summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-05-06 23:17:26 +0000
committerNico Weber <nicolasweber@gmx.de>2014-05-06 23:17:26 +0000
commit9e9ec9b69ce132b72eb557e914f7f05241fb192f (patch)
treea3a0541935516dd1c5500d7ebe82a066290935ec /lib/Transforms/Instrumentation
parent26668d093e4668a28f377c521c280454dc1b35ab (diff)
downloadllvm-9e9ec9b69ce132b72eb557e914f7f05241fb192f.tar.gz
llvm-9e9ec9b69ce132b72eb557e914f7f05241fb192f.tar.bz2
llvm-9e9ec9b69ce132b72eb557e914f7f05241fb192f.tar.xz
Fix ASan init function detection after clang r208128.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208141 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/AddressSanitizer.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index aa723616d0..ea0ace037d 100644
--- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -846,8 +846,29 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
void AddressSanitizerModule::createInitializerPoisonCalls(
Module &M, GlobalValue *ModuleName) {
- // We do all of our poisoning and unpoisoning within _GLOBAL__I_a.
- Function *GlobalInit = M.getFunction("_GLOBAL__I_a");
+ // We do all of our poisoning and unpoisoning within a global constructor.
+ // These are called _GLOBAL__(sub_)?I_.*.
+ // TODO: Consider looking through the functions in
+ // M.getGlobalVariable("llvm.global_ctors") instead of using this stringly
+ // typed approach.
+ Function *GlobalInit = nullptr;
+ for (auto &F : M.getFunctionList()) {
+ StringRef FName = F.getName();
+
+ const char kGlobalPrefix[] = "_GLOBAL__";
+ if (!FName.startswith(kGlobalPrefix))
+ continue;
+ FName = FName.substr(strlen(kGlobalPrefix));
+
+ const char kOptionalSub[] = "sub_";
+ if (FName.startswith(kOptionalSub))
+ FName = FName.substr(strlen(kOptionalSub));
+
+ if (FName.startswith("I_")) {
+ GlobalInit = &F;
+ break;
+ }
+ }
// If that function is not present, this TU contains no globals, or they have
// all been optimized away
if (!GlobalInit)
@@ -862,7 +883,7 @@ void AddressSanitizerModule::createInitializerPoisonCalls(
// Add calls to unpoison all globals before each return instruction.
for (Function::iterator I = GlobalInit->begin(), E = GlobalInit->end();
- I != E; ++I) {
+ I != E; ++I) {
if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) {
CallInst::Create(AsanUnpoisonGlobals, "", RI);
}