summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2011-12-09 22:09:32 +0000
committerKostya Serebryany <kcc@google.com>2011-12-09 22:09:32 +0000
commit25a8b809a074941e52cf357674b4382437aabb08 (patch)
tree30b4b2a50b25b020990e89291d6f823dfac1a3d2 /lib/Transforms/Instrumentation
parent840bf7eda7c81059a0aae9abd51262147c60d814 (diff)
downloadllvm-25a8b809a074941e52cf357674b4382437aabb08.tar.gz
llvm-25a8b809a074941e52cf357674b4382437aabb08.tar.bz2
llvm-25a8b809a074941e52cf357674b4382437aabb08.tar.xz
[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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/AddressSanitizer.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 83be31eada..fdea1b5946 100644
--- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/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;
}