From 857aef32445428ae0049e496fa4c194845710383 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 23 Oct 2021 22:16:24 +0900 Subject: [PATCH] [Mach-O] wip --- macho/main.cc | 12 ++++++------ macho/mold.h | 2 +- macho/output-chunks.cc | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/macho/main.cc b/macho/main.cc index 271068a5..d6c42f59 100644 --- a/macho/main.cc +++ b/macho/main.cc @@ -87,12 +87,12 @@ static void create_synthetic_chunks(Context &ctx) { } static void fill_symtab(Context &ctx) { - ctx.symtab.add(ctx, intern(ctx, "__dyld_private"), N_SECT, false, 8, 0x0); - ctx.symtab.add(ctx, intern(ctx, "__mh_execute_header"), N_SECT, true, 1, 0x10); - ctx.symtab.add(ctx, intern(ctx, "_hello"), N_SECT, true, 1, 0x0); - ctx.symtab.add(ctx, intern(ctx, "_main"), N_SECT, true, 1, 0x0); - ctx.symtab.add(ctx, intern(ctx, "_printf"), N_UNDF, true, 0, 0x100); - ctx.symtab.add(ctx, intern(ctx, "dyld_stub_binder"), N_UNDF, true, 0, 0x100); + ctx.symtab.add(ctx, intern(ctx, "__dyld_private"), false, 8, 0x0); + ctx.symtab.add(ctx, intern(ctx, "__mh_execute_header"), true, 1, 0x10); + ctx.symtab.add(ctx, intern(ctx, "_hello"), true, 1, 0x0); + ctx.symtab.add(ctx, intern(ctx, "_main"), true, 1, 0x0); + ctx.symtab.add(ctx, intern(ctx, "_printf"), true, 0, 0x100); + ctx.symtab.add(ctx, intern(ctx, "dyld_stub_binder"), true, 0, 0x100); } static void export_symbols(Context &ctx) { diff --git a/macho/mold.h b/macho/mold.h index 2206648e..ac38bd6b 100644 --- a/macho/mold.h +++ b/macho/mold.h @@ -346,7 +346,7 @@ public: hdr.p2align = __builtin_ctz(8); } - void add(Context &ctx, Symbol *sym, i64 type, bool is_external, + void add(Context &ctx, Symbol *sym, bool is_external, i64 sect_idx, i64 lib_idx); void copy_buf(Context &ctx) override; diff --git a/macho/output-chunks.cc b/macho/output-chunks.cc index 49f2bd7a..90e8e736 100644 --- a/macho/output-chunks.cc +++ b/macho/output-chunks.cc @@ -579,8 +579,7 @@ void OutputFunctionStartsSection::copy_buf(Context &ctx) { write_vector(ctx.buf + hdr.offset, contents); } -void OutputSymtabSection::add(Context &ctx, Symbol *sym, - i64 type, bool is_external, +void OutputSymtabSection::add(Context &ctx, Symbol *sym, bool is_external, i64 sect_idx, i64 desc) { MachSym &msym = mach_syms.emplace_back(); hdr.size += sizeof(msym); @@ -588,7 +587,7 @@ void OutputSymtabSection::add(Context &ctx, Symbol *sym, memset(&msym, 0, sizeof(msym)); msym.stroff = ctx.strtab.add_string(sym->name); - msym.type = type; + msym.type = (sym->file->is_dylib ? N_UNDF : N_SECT); msym.ext = is_external; msym.sect = sect_idx; msym.desc = desc;