From baf8ee195aef40afc10a5101ec80ff8e1792d2c4 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Thu, 22 Feb 2024 14:50:59 +0100 Subject: [PATCH] Fix Bugzilla 24401 - OSX: Linker error: GOT load reloc does not point to a movq instruction --- compiler/src/dmd/backend/machobj.d | 10 ++++------ compiler/test/runnable/issue24401.d | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 compiler/test/runnable/issue24401.d diff --git a/compiler/src/dmd/backend/machobj.d b/compiler/src/dmd/backend/machobj.d index eb80c1b58c..f5718fa8f2 100644 --- a/compiler/src/dmd/backend/machobj.d +++ b/compiler/src/dmd/backend/machobj.d @@ -942,6 +942,8 @@ void MachObj_term(const(char)* objfilename) } // Put out relocation data + // See mach-o/reloc.h for some examples of what should be generated and when: + // https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/EXTERNAL_HEADERS/mach-o/x86_64/reloc.h mach_numbersyms(); for (int seg = 1; seg < SegData.length; seg++) { @@ -1053,12 +1055,8 @@ void MachObj_term(const(char)* objfilename) rel.r_type = X86_64_RELOC_SIGNED; else if ((s.Sfl == FLfunc || s.Sfl == FLextern || s.Sclass == SC.global || s.Sclass == SC.comdat || s.Sclass == SC.comdef) && r.rtype == RELaddr) - { - rel.r_type = X86_64_RELOC_GOT_LOAD; - if (seg == eh_frame_seg || - seg == except_table_seg) - rel.r_type = X86_64_RELOC_GOT; - } + rel.r_type = X86_64_RELOC_GOT; + rel.r_address = cast(int)r.offset; rel.r_symbolnum = s.Sxtrnnum; rel.r_pcrel = 1; diff --git a/compiler/test/runnable/issue24401.d b/compiler/test/runnable/issue24401.d new file mode 100644 index 0000000000..109d543a0b --- /dev/null +++ b/compiler/test/runnable/issue24401.d @@ -0,0 +1,6 @@ +// PERMUTE_ARGS: +// https://issues.dlang.org/show_bug.cgi?id=24401 +int main() +{ + return (() @trusted => 0)(); +}