forked from OSchip/llvm-project
Fix ASan init function detection after clang r208128.
llvm-svn: 208141
This commit is contained in:
parent
3b3bdb5169
commit
ba8a99cf77
|
|
@ -846,8 +846,29 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
|
||||||
|
|
||||||
void AddressSanitizerModule::createInitializerPoisonCalls(
|
void AddressSanitizerModule::createInitializerPoisonCalls(
|
||||||
Module &M, GlobalValue *ModuleName) {
|
Module &M, GlobalValue *ModuleName) {
|
||||||
// We do all of our poisoning and unpoisoning within _GLOBAL__I_a.
|
// We do all of our poisoning and unpoisoning within a global constructor.
|
||||||
Function *GlobalInit = M.getFunction("_GLOBAL__I_a");
|
// 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
|
// If that function is not present, this TU contains no globals, or they have
|
||||||
// all been optimized away
|
// all been optimized away
|
||||||
if (!GlobalInit)
|
if (!GlobalInit)
|
||||||
|
|
@ -862,7 +883,7 @@ void AddressSanitizerModule::createInitializerPoisonCalls(
|
||||||
|
|
||||||
// Add calls to unpoison all globals before each return instruction.
|
// Add calls to unpoison all globals before each return instruction.
|
||||||
for (Function::iterator I = GlobalInit->begin(), E = GlobalInit->end();
|
for (Function::iterator I = GlobalInit->begin(), E = GlobalInit->end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) {
|
if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) {
|
||||||
CallInst::Create(AsanUnpoisonGlobals, "", RI);
|
CallInst::Create(AsanUnpoisonGlobals, "", RI);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue