diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 401459a054394..7ac3f51cec103 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -90,6 +90,10 @@ static std::optional 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 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 0000000000000..e6f5ff7e52e32 --- /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