By default, darwin requires a definition for weak interface functions at
link time. Adding the '-U' link flag with each weak function allows these
weak interface functions to be used without definitions, which mirrors
behavior on linux and windows.
Details
Diff Detail
- Build Status
Buildable 2682 Build 2682: arc lint + arc unit
Event Timeline
-undefined dynamic_lookup
This means the linker won't warn/error out on any undefined symbol. Sounds very dangerous to me and it's likely to cause a lot of development headaches.
Can we solve this in a different way? E.g. a macro that would expand to a empty function body on Darwin?
Its actually not that dangerous, given that ELF by default does this for any dynamic linking. However, it is possible to be more granular and specify the symbols which are okay to be undefined using the -U <name> option to the linker. It is slightly nicer than the blanket approach, but at a higher maintainence cost (any time the sanitizers change the hooks, it would need to be updated. But, that doesnt seem too bad.
Looks better, but I'd rather see the list of weak symbols in each subdirectory (asan/, ubsan/, etc.), because each sanitizer has its own list. It looks wrong to list sanitizer-specific symbols in a global CMake file. Can this also be stored in a separate file and not directly in CMake (with a dependency on that file)?
Can we also make the Linux linker use this list? I only looked briefly at man ld, but it seems that --dynamic-list may achieve the same?
Overall, I support this change, but I want to avoid situations where a weak symbol is forgotten to be added to the list, and the Linux build will work fine, but Darwin will be broken.
Ish. Most linkers can read the arguments from a file. The GNU linker uses @file syntax as does link (Windows). ld64 can read a set of files to link via -file_list but not all the arguments AFAIK.
COFF does not allow any undefined symbols anyways, and this patch addresses MachO. On ELFish targets, -z defs will prevent undefined symbols even in DSOs, but I don't think that applies to STB_WEAK symbols.
FWIW, I think that getting the same behavior across the two is a bit beyond the scope of this change.
As far as I can tell, @compnerd is correct with respect to STB_WEAK symbols on Linux. I'll upload a refactored change targeting Darwin with the weak symbols pushed down into the sanitizer-specific directories.
LGTM with a nit.
Note that D28359 was trying to solve a similar problem with weak linking on Windows, so maybe there are more changes coming, but this patch doesn't need to be blocked on that.
cmake/Modules/SanitizerUtils.cmake | ||
---|---|---|
53 | nit: add a comment saying that this is specific to Darwin/Mach-O | |
lib/sanitizer_common/sanitizer_internal_defs.h | ||
35 | What about FreeBSD? Just curious. |
lib/sanitizer_common/sanitizer_internal_defs.h | ||
---|---|---|
35 | I believe that FreeBSD uses ELF, so it should be able to support weak linkage. However, if its untested ... |
I realized during testing that the symbols must also be added to some test cases directly. Re-uploaded with those changes, to give the opportunity for review before submitting.
There are still a few typos where LINK_FLAGS (with the underscore) is used.
Besides that, the patch looks good.
nit: add a comment saying that this is specific to Darwin/Mach-O