[lld] 46a9135 - [lld-macho] Find objects in library search path (#78628)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 20 13:53:59 PST 2024


Author: OldWorldOrdr
Date: 2024-01-20T13:53:55-08:00
New Revision: 46a9135d61f729da90b88d3d34a3905c91d194d7

URL: https://github.com/llvm/llvm-project/commit/46a9135d61f729da90b88d3d34a3905c91d194d7
DIFF: https://github.com/llvm/llvm-project/commit/46a9135d61f729da90b88d3d34a3905c91d194d7.diff

LOG: [lld-macho] Find objects in library search path (#78628)

Find object files in library search path just like Apple's linker, this
makes building with some older MacOS SDKs easier since clang runs with
`-lcrt1.10.6.o`

Added: 
    lld/test/MachO/link-csu-object.s

Modified: 
    lld/MachO/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 401459a054394ec..7ac3f51cec103f6 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -90,6 +90,10 @@ static std::optional<StringRef> findLibrary(StringRef name) {
     return entry->second;
 
   auto doFind = [&] {
+    // Special case for Csu support files required for Mac OS X 10.7 and older
+    // (crt1.o)
+    if (name.ends_with(".o"))
+      return findPathCombination(name, config->librarySearchPaths, {""});
     if (config->searchDylibsFirst) {
       if (std::optional<StringRef> path =
               findPathCombination("lib" + name, config->librarySearchPaths,

diff  --git a/lld/test/MachO/link-csu-object.s b/lld/test/MachO/link-csu-object.s
new file mode 100644
index 000000000000000..e6f5ff7e52e3250
--- /dev/null
+++ b/lld/test/MachO/link-csu-object.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: mkdir -p %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s -o %t/hello.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
+# RUN: %lld -L %t %t/main.o %t/hello.o -o %t/a.out
+# RUN: llvm-nm %t/a.out | FileCheck %s
+
+# CHECK: _main
+# CHECK: _print_hello
+
+.globl _main
+_main:
+    call _print_hello
+    ret


        


More information about the llvm-commits mailing list