https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/219743
>From a113ed3ede9c87befba3caa8abc11c6497109bb4 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee <[email protected]> Date: Sat, 29 Aug 2026 17:05:11 -0700 Subject: [PATCH] [lld][MachO] Fix ObjC stubs from autolinked archives Move ObjC stub preparation after LC_LINKER_OPTION processing so archive members loaded via autolink can contribute _objc_msgSend$ selector stubs before selector references are built. Previously those stubs missed __objc_methname setup; assert builds could fail in makeSelRef, and release builds could form an invalid selector reference. --- lld/MachO/Driver.cpp | 3 +- lld/test/MachO/arm64-objc-stubs-autolink.s | 35 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lld/test/MachO/arm64-objc-stubs-autolink.s diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 2864c6d28fa49..632c48120c8cf 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -2441,7 +2441,6 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS, createSyntheticSections(); createSyntheticSymbols(); - addSynthenticMethnames(); createAliases(); // If we are in "explicit exports" mode, hide everything that isn't @@ -2459,6 +2458,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS, if (config->thinLTOIndexOnly || config->emitLLVM) return errorCount() == 0; + addSynthenticMethnames(); + // LTO may emit a non-hidden (extern) object file symbol even if the // corresponding bitcode symbol is hidden. In particular, this happens for // cross-module references to hidden symbols under ThinLTO. Thus, if we diff --git a/lld/test/MachO/arm64-objc-stubs-autolink.s b/lld/test/MachO/arm64-objc-stubs-autolink.s new file mode 100644 index 0000000000000..d177eb8e7961d --- /dev/null +++ b/lld/test/MachO/arm64-objc-stubs-autolink.s @@ -0,0 +1,35 @@ +# REQUIRES: aarch64 + +# RUN: rm -rf %t && split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/main.s \ +# RUN: -o %t/main.o +# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/dep.s \ +# RUN: -o %t/dep.o +# RUN: llvm-ar rcs %t/libdep.a %t/dep.o +# RUN: %lld -arch arm64 -lSystem -o %t/out %t/main.o -L%t \ +# RUN: -objc_stubs_fast -U _objc_msgSend +# RUN: llvm-objdump --no-show-raw-insn --section=__TEXT,__objc_stubs \ +# RUN: --macho %t/out | FileCheck %s + +# CHECK: Contents of (__TEXT,__objc_stubs) section +# CHECK-NEXT: _objc_msgSend$plain: +# CHECK-NEXT: adrp x1, +# CHECK-NEXT: ldr x1, {{.*}} ; Objc selector ref: plain +# CHECK-NEXT: adrp x16, +# CHECK-NEXT: ldr x16, {{.*}} ; literal pool symbol address: _objc_msgSend +# CHECK-NEXT: br x16 + +#--- main.s +.linker_option "-ldep" +.text +.globl _main +_main: + bl _dep + ret + +#--- dep.s +.text +.globl _dep +_dep: + bl _objc_msgSend$plain + ret _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
