From be5fe4c727daa1afa03a572bb5b34954ef7724ea Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 6 Jul 2022 17:22:52 +0800 Subject: [PATCH] [Mach-O] Map __DATA,__const to __DATA_CONST,__const --- macho/input-files.cc | 1 + macho/input-sections.cc | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/macho/input-files.cc b/macho/input-files.cc index d478ac782a..b9816ff186 100644 --- a/macho/input-files.cc +++ b/macho/input-files.cc @@ -607,6 +607,7 @@ bool ObjectFile::is_objc_object(Context &ctx) { if (!mach_syms[i].is_undef() && mach_syms[i].is_extern && this->syms[i]->name.starts_with("_OBJC_CLASS_$_")) return true; + return false; } diff --git a/macho/input-sections.cc b/macho/input-sections.cc index 4954376696..10ad324381 100644 --- a/macho/input-sections.cc +++ b/macho/input-sections.cc @@ -2,12 +2,21 @@ namespace mold::macho { +template +OutputSection &get_output_section(Context &ctx, const MachSection &hdr) { + std::string_view seg = hdr.get_segname(); + std::string_view sect = hdr.get_sectname(); + + if (seg == "__DATA" && sect == "__const") + seg = "__DATA_CONST"; + + return *OutputSection::get_instance(ctx, seg, sect); +} + template InputSection::InputSection(Context &ctx, ObjectFile &file, const MachSection &hdr) - : file(file), hdr(hdr), - osec(*OutputSection::get_instance(ctx, hdr.get_segname(), - hdr.get_sectname())) { + : file(file), hdr(hdr), osec(get_output_section(ctx, hdr)) { if (hdr.type != S_ZEROFILL) contents = file.mf->get_contents().substr(hdr.offset, hdr.size); }