[PATCH] D20741: [LibFuzzer] Fix weak linking issues building tests under OSX.
Dan Liew via llvm-commits
llvm-commits at lists.llvm.org
Fri May 27 14:30:54 PDT 2016
delcypher added a comment.
@mehdi_amini
In http://reviews.llvm.org/D20741#442650, @mehdi_amini wrote:
> Weak linking is not supported on Darwin AFAIK. Or rather: the symbol has to be present during the static link, but don't have to be present in the dylib when loading the program.
I don't think this is quite true. Weak linking can work under Darwin it's just that you have to tell the compile time linker to behave differently.
https://glandium.org/blog/?p=2764
https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html#//apple_ref/doc/uid/20002378-106633
So far I have not been able to find an attribute that can be used to tell the Darwin linker to treat weak symbols differently (although you still need to use ``__attribute__((weak))`` or ``__attribute__((weak_import))`` to tell the compiler to mark the symbol as weak).
So far the ways of handling this I've found are
- Explicitly tell the linker about the symbols that do not to be defined at link time. This is the approach used in this patch by passing `-U _theSymbol` to the linker
- Pass `-undefined dynamic_lookup` to the linker. This is really bad because now the linker won't warn/error out on **any** undefined symbols.
The problem with both of these is a user of LibFuzzer has to do extra things with the linker to make things work.
@mehdi_amini suggestion of using dlsym might be the best way forward as in principle it wouldn't require the user to do anything special with the linker.
http://reviews.llvm.org/D20741
More information about the llvm-commits
mailing list