From 2fa38f8ce07466e8a80716ee575c38066dab1f80 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 5 Sep 2012 07:29:56 +0000 Subject: [PATCH] [asan] extend the blacklist functionality to handle global-init. Patch by Reid Watson llvm-svn: 163199 --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 3 +++ llvm/lib/Transforms/Instrumentation/BlackList.cpp | 4 ++++ llvm/lib/Transforms/Instrumentation/BlackList.h | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 42f21d2983a3..33047293658c 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -544,6 +544,7 @@ bool AddressSanitizer::ShouldInstrumentGlobal(GlobalVariable *G) { Type *Ty = cast(G->getType())->getElementType(); DEBUG(dbgs() << "GLOBAL: " << *G); + if (BL->isIn(*G)) return false; if (!Ty->isSized()) return false; if (!G->hasInitializer()) return false; // Touch only those globals that will not be defined in other modules. @@ -643,6 +644,8 @@ bool AddressSanitizer::insertGlobalRedzones(Module &M) { Type *RightRedZoneTy = ArrayType::get(IRB.getInt8Ty(), RightRedzoneSize); // Determine whether this global should be poisoned in initialization. bool GlobalHasDynamicInitializer = HasDynamicInitializer(G); + // Don't check initialization order if this global is blacklisted. + GlobalHasDynamicInitializer &= ! BL->isInInit(*G); StructType *NewTy = StructType::get(Ty, RightRedZoneTy, NULL); Constant *NewInitializer = ConstantStruct::get( diff --git a/llvm/lib/Transforms/Instrumentation/BlackList.cpp b/llvm/lib/Transforms/Instrumentation/BlackList.cpp index ecfe954dec19..2cb119964a3d 100644 --- a/llvm/lib/Transforms/Instrumentation/BlackList.cpp +++ b/llvm/lib/Transforms/Instrumentation/BlackList.cpp @@ -89,6 +89,10 @@ bool BlackList::isIn(const Module &M) { return inSection("src", M.getModuleIdentifier()); } +bool BlackList::isInInit(const GlobalVariable &G) { + return isIn(*G.getParent()) || inSection("global-init", G.getName()); +} + bool BlackList::inSection(const StringRef Section, const StringRef Query) { Regex *FunctionRegex = Entries[Section]; diff --git a/llvm/lib/Transforms/Instrumentation/BlackList.h b/llvm/lib/Transforms/Instrumentation/BlackList.h index e303dbcd9615..73977fc10a64 100644 --- a/llvm/lib/Transforms/Instrumentation/BlackList.h +++ b/llvm/lib/Transforms/Instrumentation/BlackList.h @@ -14,7 +14,8 @@ // variables. Each line contains a prefix, followed by a wild card expression. // --- // fun:*_ZN4base6subtle* -// global:*global_with_initialization_problems* +// global:*global_with_bad_access_or_initialization* +// global-init:*global_with_initialization_issues* // src:file_with_tricky_code.cc // --- // Note that the wild card is in fact an llvm::Regex, but * is automatically @@ -43,6 +44,8 @@ class BlackList { bool isIn(const GlobalVariable &G); // Returns whether this module is blacklisted by filename. bool isIn(const Module &M); + // Returns whether a global should be excluded from initialization checking. + bool isInInit(const GlobalVariable &G); private: StringMap Entries;