Otherwise we get undefined symbol errors depending on the order of
arguments on the command line.
Depends on D78270.
Differential D79114
[lld-macho] Dylib symbols should always replace undefined symbols int3 on Apr 29 2020, 12:10 PM. Authored by
Details Otherwise we get undefined symbol errors depending on the order of Depends on D78270.
Diff Detail
Event Timeline
Comment Actions Not this diff, but it appears ld64 always prefers symbols from object files over symbols from dylibs. For example: $ cat f1.c int f() { return 1; } $ cat f2.c: int f() { return 2; } $ cat main.c int f(void); int main() { return f(); } $ clang -fPIC -dynamiclib -o libf1.dylib f1.c $ clang -c f2.c $ clang -c main.c $ ld libf1.dylib main.o f2.o -lSystem $ ./a.out; echo $? 2 $ ld main.o libf1.dylib f2.o -lSystem $ ./a.out; echo $? 2 # sanity check $ ld main.o libf1.dylib -lSystem I believe we should already be implementing this behavior, courtesy of a Defined replacing any other symbol, but it's worth adding a test.
Comment Actions This behavior is reasonable to me but where can we find authoritative symbol resolution rules? (You may be aware of https://lld.llvm.org/NewLLD.html "Efficient archive file handling". The ELF port has different resolution rules regarding archives.)
Comment Actions
I guess the authoritative source is whatever ld64 is doing. I took a brief look at their SymbolTable.cpp but it seems rather complex, handling many kinds of symbols. The test behavior in this diff does emulate the observed behavior of ld64 though. Thanks for the pointer to the ELF resolution rule design, will keep that in mind as we expand support for symbol kinds. Comment Actions LGTM. I added some commentary on ld64's behavior in https://reviews.llvm.org/D78342#inline-728182. |
Consider inlining short Inputs/* file: