This is an archive of the discontinued LLVM Phabricator instance.

[asan] Make ASan compatible with linker dead stripping on Linux.
AbandonedPublic

Authored by eugenis on Jan 9 2017, 4:05 PM.

Details

Reviewers
pcc
rnk
Summary

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 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. We
use the new SHT_ASSOCIATED section flag to link the global and its
descriptor together for linker GC.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 83727.Jan 9 2017, 4:05 PM
eugenis retitled this revision from to [asan] Make ASan compatible with linker dead stripping on Linux..
eugenis updated this object.
eugenis added reviewers: pcc, rnk.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
pcc edited edge metadata.Jan 10 2017, 8:26 PM

The InstrumentGlobals function is now basically four functions in one at this point. I'm wondering whether this code could be made more readable if we split each target object format into its own function.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1830

@rnk Can you remind me why this is not an issue for COFF?

test/Instrumentation/AddressSanitizer/global_metadata.ll
23

Don't you want to check the content of this global? And what about the global metadata for @.str?

rnk edited edge metadata.Jan 11 2017, 1:17 PM
In D28498#642272, @pcc wrote:

The InstrumentGlobals function is now basically four functions in one at this point. I'm wondering whether this code could be made more readable if we split each target object format into its own function.

I think I agree. We can extract any common code into helpers.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1830

In COFF, comdats are not really groups with a string. It's more like, you have N separate comdat sections, one is the "leader", everyone points at the leader by referring to its symbol, and the leader may have static linkage. Basically, because the comdat key is a real symbol with linkage from an object file and not some globally unique string, this isn't a problem.

Also, I thought the point of the LLD change was so that we wouldn't have to do this? I thought the plan was to change our object emission to create a section group without a comdat key.

1836

!ELFUniqueModuleId.empty() maybe?

eugenis updated this revision to Diff 84049.Jan 11 2017, 4:18 PM
eugenis edited edge metadata.

Split implementation in one function per target binary format / global instrumentation kind.

Since the fate of this change is yet unclear, I've moved the valuable refactoring to https://reviews.llvm.org/D28589.

eugenis updated this revision to Diff 84753.Jan 17 2017, 2:55 PM

use SHT_ASSOCIATED

pcc added inline comments.Jan 17 2017, 3:00 PM
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
228

Should this be testing a new flag on GlobalObject, rather than the section name?

Also, do we need to teach globaldce about this?

mehdi_amini added inline comments.Jan 17 2017, 3:14 PM
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
228

MachO version is using llvm.compiler.used to avoid having to teach GlobalDCE and other part of LLVM about a special section semantics.

eugenis added inline comments.Jan 17 2017, 3:24 PM
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
228

Yeah, we could that, at a minimum.

But this code is definitely wrong: we don't want the new flag to be added on .S -> .o transform, unless explicitly given in the assembly.

eugenis updated this revision to Diff 85213.Jan 20 2017, 4:20 PM
eugenis edited the summary of this revision. (Show Details)
eugenis marked an inline comment as done.Jan 20 2017, 4:25 PM
eugenis added inline comments.
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
228

I'm not sure why I said that. This code has nothing to do with .S -> .o path.

llvm.compiler.used added.

I'm not convinced we need a whole IR thing (the global flag) for this tiny feature. Maybe e wait until there is more than one user?

eugenis updated this revision to Diff 85222.Jan 20 2017, 5:26 PM

Added a new metadata, !associated, to mark asan globals.

pcc added inline comments.Jan 20 2017, 5:46 PM
test/Instrumentation/AddressSanitizer/global_metadata.ll
23

Looks like this hasn't been addressed.

eugenis updated this revision to Diff 85227.Jan 20 2017, 6:08 PM

+ globaldce support for !associated

eugenis marked an inline comment as done.Jan 20 2017, 6:09 PM

Moved the new metadata implementation to https://reviews.llvm.org/D29104