This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizers] Make sanitizer allocator linker-initialize compliant.
ClosedPublic

Authored by alekseyshl on Jun 13 2018, 12:29 PM.

Details

Summary

These four SpinMutex ctors was the only code executed in the ctor for
the static __asan::Allocator instance (same for the other sanitizers
allocators), which is supposed to be fully linker-initialized.

Also, when the global ctor for this allocator instance is executed,
this instance might already be initialized by __asan_init called from
.preinit_array.

Issue: https://github.com/google/sanitizers/issues/194

Event Timeline

alekseyshl created this revision.Jun 13 2018, 12:29 PM
Herald added subscribers: Restricted Project, delcypher, kubamracek. · View Herald TranscriptJun 13 2018, 12:29 PM

Interesting I was looking at that recently!
If you could add the one in scudo_allocator_secondary.h as well in this patch it would be great. Otherwise I can do a separate one.

Please ignore the last comment I'll do a separate patch, Scudo doesn't belong in this one.

cryptoad accepted this revision.Jun 13 2018, 12:48 PM
This revision is now accepted and ready to land.Jun 13 2018, 12:48 PM
This revision was automatically updated to reflect the committed changes.
filcab added a subscriber: filcab.Jun 25 2018, 9:28 AM

Clang still warns:

/Users/filcab/dev/llvm/compiler-rt/lib/asan/asan_allocator.cc:793:18: warning: declaration requires a global constructor [-Wglobal-constructors]
static Allocator instance(LINKER_INITIALIZED);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Clang still warns:

/Users/filcab/dev/llvm/compiler-rt/lib/asan/asan_allocator.cc:793:18: warning: declaration requires a global constructor [-Wglobal-constructors]
static Allocator instance(LINKER_INITIALIZED);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Ah, that's the Asan allocator, which might be bringing something else on. It's probably not about this patch. Sorry for the noise.

Clang still warns:

/Users/filcab/dev/llvm/compiler-rt/lib/asan/asan_allocator.cc:793:18: warning: declaration requires a global constructor [-Wglobal-constructors]
static Allocator instance(LINKER_INITIALIZED);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Ah, that's the Asan allocator, which might be bringing something else on. It's probably not about this patch. Sorry for the noise.

Yep, clang warns about all of those LINKER_INITIALIZED instances, although no code ends up in the binary. Well, maybe this warning is worth investigating and improving...