[LLD][Mach-O] Multi-document TBDs link against host dylibs instead of sibling documents
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
`ld64.lld` appears to prioritize resolving an install-name against files in the sysroot on disk, even when they are defined by embedded sibling documents in an explicitly provided `.tbd` file. This causes it to incorrectly link against the host sysroot dylibs (in contrast to `ld` behavior).
To repro:
```console
$ curl -sLO https://raw.githubusercontent.com/ziglang/zig/master/lib/libc/darwin/libSystem.tbd
$ echo 'int main(void){return 0;}' | clang -x c -c -mmacosx-version-min=11.0 - -o t.o
$ ld64.lld -arch arm64 -platform_version macos 11.0 11.0 -o out t.o libSystem.tbd
ld64.lld: warning: /usr/lib/system/libsystem_kernel.dylib has version 26.4.0, which is newer than target minimum of 11.0
ld64.lld: warning: /usr/lib/system/libsystem_platform.dylib has version 26.4.0, which is newer than target minimum of 11.0
ld64.lld: warning: /usr/lib/system/libsystem_pthread.dylib has version 26.4.0, which is newer than target minimum of 11.0
$ /usr/bin/ld -arch arm64 -platform_version macos 11.0 11.0 -o out t.o libSystem.tbd
$ ./out
$ echo $?
0
```
This FIXME seems relevant: https://github.com/llvm/llvm-project/blob/b2ae992193e3c157b306f1067a5a30cadae9b7b0/lld/MachO/InputFiles.cpp#L1661
Contributor guide
Research direction
Start with lld/MachO/InputFiles.cpp at the FIXME referenced in the issue, then reproduce the commands using the embedded sibling documents in libSystem.tbd and compare ld64.lld with ld. Done means install-names from sibling TBD documents resolve there instead of to host sysroot dylibs, without the reported newer-version warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100