llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-macho

Author: Kyungwoo Lee (kyulee-com)

<details>
<summary>Changes</summary>

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.

---

&lt;sub&gt;Stack created with &lt;a 
href="https://github.com/github/gh-stack"&gt;GitHub Stacks CLI&lt;/a&gt; • 
&lt;a href="https://gh.io/stacks-feedback"&gt;Give Feedback 
💬&lt;/a&gt;&lt;/sub&gt;

---
Full diff: https://github.com/llvm/llvm-project/pull/219743.diff


2 Files Affected:

- (modified) lld/MachO/Driver.cpp (+2-1) 
- (added) lld/test/MachO/arm64-objc-stubs-autolink.s (+35) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/219743
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to