[PATCH] D28498: [asan] Make ASan compatible with linker dead stripping on Linux.
Evgeniy Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 9 16:05:58 PST 2017
eugenis created this revision.
eugenis added reviewers: pcc, rnk.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.
Herald added a subscriber: mehdi_amini.
See this issue for more context:
https://github.com/google/sanitizers/issues/260
Instead of putting all global variable descriptions in one large chunk, we emit one descriptor global for each original global. This is more linker-gc friendly, as now individual globals can be discarded along with their descriptors when unused.
The implementation is basically a cross between the COFF change in r287576 and the MachO change in r264645. The same as COFF, we use comdat (section groups in ELF) to link the global and it's descriptor together. Unlike COFF, ASan runtime does not have any per-DSO code on ELF targets, so the address of the descriptor section is obtained in the module constructor and passed to the global registration function as an argument. Similarly to MachO, we use a per-DSO registration flag.
This depends on the linker treating ELF section groups as "associative" comdats (see IMAGE_COMDAT_SELECT_ASSOCIATIVE). This is true for BFD, but not for Gold. An implementation for LLD can be found at https://reviews.llvm.org/D28481.
A non-supporting linker could in theory lose the descriptions. Luckily, both gold and lld work correctly:
- gold treats section symbols as GC roots
- lld treats any section whose name is a valid C identifier as a GC root
As a result, the behavior with gold and lld is unchanged, other than some space in object files is being wasted on all the new sections.
Repository:
rL LLVM
https://reviews.llvm.org/D28498
Files:
include/llvm/Transforms/Utils/ModuleUtils.h
lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
lib/Transforms/Instrumentation/AddressSanitizer.cpp
lib/Transforms/Utils/ModuleUtils.cpp
test/Instrumentation/AddressSanitizer/global_metadata.ll
test/Instrumentation/AddressSanitizer/instrument_global.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28498.83727.patch
Type: text/x-patch
Size: 14770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170110/056e4804/attachment.bin>
More information about the llvm-commits
mailing list