Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 59a4a47

Browse files
committed
[asan] extend the blacklist functionality to handle global-init. Patch by Reid Watson
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163199 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4e4e6c0 commit 59a4a47

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ bool AddressSanitizer::ShouldInstrumentGlobal(GlobalVariable *G) {
544544
Type *Ty = cast<PointerType>(G->getType())->getElementType();
545545
DEBUG(dbgs() << "GLOBAL: " << *G);
546546

547+
if (BL->isIn(*G)) return false;
547548
if (!Ty->isSized()) return false;
548549
if (!G->hasInitializer()) return false;
549550
// Touch only those globals that will not be defined in other modules.
@@ -643,6 +644,8 @@ bool AddressSanitizer::insertGlobalRedzones(Module &M) {
643644
Type *RightRedZoneTy = ArrayType::get(IRB.getInt8Ty(), RightRedzoneSize);
644645
// Determine whether this global should be poisoned in initialization.
645646
bool GlobalHasDynamicInitializer = HasDynamicInitializer(G);
647+
// Don't check initialization order if this global is blacklisted.
648+
GlobalHasDynamicInitializer &= ! BL->isInInit(*G);
646649

647650
StructType *NewTy = StructType::get(Ty, RightRedZoneTy, NULL);
648651
Constant *NewInitializer = ConstantStruct::get(

lib/Transforms/Instrumentation/BlackList.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ bool BlackList::isIn(const Module &M) {
8989
return inSection("src", M.getModuleIdentifier());
9090
}
9191

92+
bool BlackList::isInInit(const GlobalVariable &G) {
93+
return isIn(*G.getParent()) || inSection("global-init", G.getName());
94+
}
95+
9296
bool BlackList::inSection(const StringRef Section,
9397
const StringRef Query) {
9498
Regex *FunctionRegex = Entries[Section];

lib/Transforms/Instrumentation/BlackList.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
// variables. Each line contains a prefix, followed by a wild card expression.
1515
// ---
1616
// fun:*_ZN4base6subtle*
17-
// global:*global_with_initialization_problems*
17+
// global:*global_with_bad_access_or_initialization*
18+
// global-init:*global_with_initialization_issues*
1819
// src:file_with_tricky_code.cc
1920
// ---
2021
// Note that the wild card is in fact an llvm::Regex, but * is automatically
@@ -43,6 +44,8 @@ class BlackList {
4344
bool isIn(const GlobalVariable &G);
4445
// Returns whether this module is blacklisted by filename.
4546
bool isIn(const Module &M);
47+
// Returns whether a global should be excluded from initialization checking.
48+
bool isInInit(const GlobalVariable &G);
4649
private:
4750
StringMap<Regex*> Entries;
4851

0 commit comments

Comments
 (0)