1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 09:57:18 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-11-14 15:05:22 +09:00
parent 18cfe1f4ca
commit 15215b1f71
3 changed files with 29 additions and 1 deletions

View File

@ -124,10 +124,12 @@ void Subsection::scan_relocations(Context &ctx) {
switch (rel.type) { switch (rel.type) {
case X86_64_RELOC_GOT_LOAD: case X86_64_RELOC_GOT_LOAD:
case X86_64_RELOC_GOT:
if (sym->file->is_dylib) if (sym->file->is_dylib)
sym->flags |= NEEDS_GOT; sym->flags |= NEEDS_GOT;
break; break;
case X86_64_RELOC_GOT:
sym->flags |= NEEDS_GOT;
break;
case X86_64_RELOC_TLV: case X86_64_RELOC_TLV:
if (sym->file->is_dylib) if (sym->file->is_dylib)
sym->flags |= NEEDS_THREAD_PTR; sym->flags |= NEEDS_THREAD_PTR;

View File

@ -569,6 +569,7 @@ public:
} }
void add(Context &ctx, Symbol *sym); void add(Context &ctx, Symbol *sym);
void copy_buf(Context &ctx) override;
std::vector<Symbol *> syms; std::vector<Symbol *> syms;
@ -595,6 +596,7 @@ public:
} }
void add(Context &ctx, Symbol *sym); void add(Context &ctx, Symbol *sym);
void copy_buf(Context &ctx) override;
std::vector<Symbol *> syms; std::vector<Symbol *> syms;

View File

@ -491,6 +491,16 @@ void OutputRebaseSection::compute_size(Context &ctx) {
ctx.lazy_symbol_ptr.hdr.addr + i * LazySymbolPtrSection::ENTRY_SIZE - ctx.lazy_symbol_ptr.hdr.addr + i * LazySymbolPtrSection::ENTRY_SIZE -
ctx.data_seg->cmd.vmaddr); ctx.data_seg->cmd.vmaddr);
for (Symbol *sym : ctx.got.syms)
if (!sym->file->is_dylib)
enc.add(ctx.data_const_seg->seg_idx,
sym->get_got_addr(ctx) - ctx.data_const_seg->cmd.vmaddr);
for (Symbol *sym : ctx.thread_ptrs.syms)
if (!sym->file->is_dylib)
enc.add(ctx.data_seg->seg_idx,
sym->get_tlv_addr(ctx) - ctx.data_seg->cmd.vmaddr);
for (std::unique_ptr<OutputSegment> &seg : ctx.segments) for (std::unique_ptr<OutputSegment> &seg : ctx.segments)
for (Chunk *chunk : seg->chunks) for (Chunk *chunk : seg->chunks)
if (chunk->is_regular) if (chunk->is_regular)
@ -1162,6 +1172,13 @@ void GotSection::add(Context &ctx, Symbol *sym) {
hdr.size = syms.size() * ENTRY_SIZE; hdr.size = syms.size() * ENTRY_SIZE;
} }
void GotSection::copy_buf(Context &ctx) {
u64 *buf = (u64 *)(ctx.buf + hdr.offset);
for (i64 i = 0; i < syms.size(); i++)
if (!syms[i]->file->is_dylib)
buf[i] = syms[i]->get_addr(ctx);
}
void LazySymbolPtrSection::copy_buf(Context &ctx) { void LazySymbolPtrSection::copy_buf(Context &ctx) {
u64 *buf = (u64 *)(ctx.buf + hdr.offset); u64 *buf = (u64 *)(ctx.buf + hdr.offset);
@ -1177,4 +1194,11 @@ void ThreadPtrsSection::add(Context &ctx, Symbol *sym) {
hdr.size = syms.size() * ENTRY_SIZE; hdr.size = syms.size() * ENTRY_SIZE;
} }
void ThreadPtrsSection::copy_buf(Context &ctx) {
u64 *buf = (u64 *)(ctx.buf + hdr.offset);
for (i64 i = 0; i < syms.size(); i++)
if (!syms[i]->file->is_dylib)
buf[i] = syms[i]->get_addr(ctx);
}
} // namespace mold::macho } // namespace mold::macho