Skip to content

Commit 46a9135

Browse files
authored
[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`
1 parent 07b5829 commit 46a9135

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lld/MachO/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ static std::optional<StringRef> findLibrary(StringRef name) {
9090
return entry->second;
9191

9292
auto doFind = [&] {
93+
// Special case for Csu support files required for Mac OS X 10.7 and older
94+
// (crt1.o)
95+
if (name.ends_with(".o"))
96+
return findPathCombination(name, config->librarySearchPaths, {""});
9397
if (config->searchDylibsFirst) {
9498
if (std::optional<StringRef> path =
9599
findPathCombination("lib" + name, config->librarySearchPaths,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# REQUIRES: x86
2+
# RUN: mkdir -p %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s -o %t/hello.o
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
5+
# RUN: %lld -L %t %t/main.o %t/hello.o -o %t/a.out
6+
# RUN: llvm-nm %t/a.out | FileCheck %s
7+
8+
# CHECK: _main
9+
# CHECK: _print_hello
10+
11+
.globl _main
12+
_main:
13+
call _print_hello
14+
ret

0 commit comments

Comments
 (0)