diff options
author | Kostya Serebryany <kcc@google.com> | 2011-12-09 22:09:32 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2011-12-09 22:09:32 +0000 |
commit | 3563f8cd410cb96784e52e20771fb8cf71daa86f (patch) | |
tree | 72436503e96a63141536bf8232784c3ec4e16c49 /llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | |
parent | 6192b6570df477eb74ff4be326e42f6ca2dd471c (diff) | |
download | bcm5719-llvm-3563f8cd410cb96784e52e20771fb8cf71daa86f.tar.gz bcm5719-llvm-3563f8cd410cb96784e52e20771fb8cf71daa86f.zip |
[asan] call __asan_init from .preinit_array. This simplifies __asan_init vs malloc chicken-and-egg situation on Android and probably on other flavours of Linux. Patch by eugenis@google.com.
llvm-svn: 146284
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 83be31eada6..fdea1b59466 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -163,6 +163,8 @@ struct AddressSanitizer : public ModulePass { private: + void appendToPreinitArray(Module &M, Function *F); + uint64_t getAllocaSizeInBytes(AllocaInst *AI) { Type *Ty = AI->getAllocatedType(); uint64_t SizeInBytes = TD->getTypeStoreSizeInBits(Ty) / 8; @@ -563,6 +565,18 @@ bool AddressSanitizer::insertGlobalRedzones(Module &M) { return true; } +// .preinit_array is something that hapens before all other inits. +// On systems where .preinit_array is honored, we will call __asan_init early. +// On other systems this will make no effect. +void AddressSanitizer::appendToPreinitArray(Module &M, Function *F) { + IRBuilder<> IRB(M.getContext()); + GlobalVariable *Var = + new GlobalVariable(M, PointerType::getUnqual(F->getFunctionType()), + false, GlobalValue::PrivateLinkage, + F, "__asan_preinit_private"); + Var->setSection(".preinit_array"); +} + // virtual bool AddressSanitizer::runOnModule(Module &M) { // Initialize the private fields. No one has accessed them before. @@ -633,6 +647,7 @@ bool AddressSanitizer::runOnModule(Module &M) { } appendToGlobalCtors(M, AsanCtorFunction, 1 /*high priority*/); + appendToPreinitArray(M, AsanInitFunction); return Res; } |