mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-21 03:32:21 +00:00
[asan] initialize asan error callbacks in runOnModule instead of doing that on-demand
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160269 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d93ea88cde
commit
9db5b5ffa9
@ -180,7 +180,6 @@ struct AddressSanitizer : public ModulePass {
|
|||||||
Value *ShadowBase, bool DoPoison);
|
Value *ShadowBase, bool DoPoison);
|
||||||
bool LooksLikeCodeInBug11395(Instruction *I);
|
bool LooksLikeCodeInBug11395(Instruction *I);
|
||||||
|
|
||||||
Module *CurrentModule;
|
|
||||||
LLVMContext *C;
|
LLVMContext *C;
|
||||||
TargetData *TD;
|
TargetData *TD;
|
||||||
uint64_t MappingOffset;
|
uint64_t MappingOffset;
|
||||||
@ -193,6 +192,10 @@ struct AddressSanitizer : public ModulePass {
|
|||||||
Function *AsanInitFunction;
|
Function *AsanInitFunction;
|
||||||
Instruction *CtorInsertBefore;
|
Instruction *CtorInsertBefore;
|
||||||
OwningPtr<FunctionBlackList> BL;
|
OwningPtr<FunctionBlackList> BL;
|
||||||
|
// Accesses sizes are powers of two: 1, 2, 4, 8, 16.
|
||||||
|
static const size_t kNumberOfAccessSizes = 5;
|
||||||
|
// This array is indexed by AccessIsWrite and log2(AccessSize).
|
||||||
|
Function *AsanErrorCallback[2][kNumberOfAccessSizes];
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -361,12 +364,10 @@ Function *AddressSanitizer::checkInterfaceFunction(Constant *FuncOrBitcast) {
|
|||||||
|
|
||||||
Instruction *AddressSanitizer::generateCrashCode(
|
Instruction *AddressSanitizer::generateCrashCode(
|
||||||
IRBuilder<> &IRB, Value *Addr, bool IsWrite, uint32_t TypeSize) {
|
IRBuilder<> &IRB, Value *Addr, bool IsWrite, uint32_t TypeSize) {
|
||||||
// IsWrite and TypeSize are encoded in the function name.
|
size_t AccessSizeIndex = CountTrailingZeros_32(TypeSize / 8);
|
||||||
std::string FunctionName = std::string(kAsanReportErrorTemplate) +
|
assert(AccessSizeIndex < kNumberOfAccessSizes);
|
||||||
(IsWrite ? "store" : "load") + itostr(TypeSize / 8);
|
CallInst *Call = IRB.CreateCall(AsanErrorCallback[IsWrite][AccessSizeIndex],
|
||||||
Value *ReportWarningFunc = CurrentModule->getOrInsertFunction(
|
Addr);
|
||||||
FunctionName, IRB.getVoidTy(), IntptrTy, NULL);
|
|
||||||
CallInst *Call = IRB.CreateCall(ReportWarningFunc, Addr);
|
|
||||||
Call->setDoesNotReturn();
|
Call->setDoesNotReturn();
|
||||||
return Call;
|
return Call;
|
||||||
}
|
}
|
||||||
@ -581,7 +582,6 @@ bool AddressSanitizer::runOnModule(Module &M) {
|
|||||||
return false;
|
return false;
|
||||||
BL.reset(new FunctionBlackList(ClBlackListFile));
|
BL.reset(new FunctionBlackList(ClBlackListFile));
|
||||||
|
|
||||||
CurrentModule = &M;
|
|
||||||
C = &(M.getContext());
|
C = &(M.getContext());
|
||||||
LongSize = TD->getPointerSizeInBits();
|
LongSize = TD->getPointerSizeInBits();
|
||||||
IntptrTy = Type::getIntNTy(*C, LongSize);
|
IntptrTy = Type::getIntNTy(*C, LongSize);
|
||||||
@ -600,6 +600,18 @@ bool AddressSanitizer::runOnModule(Module &M) {
|
|||||||
AsanInitFunction->setLinkage(Function::ExternalLinkage);
|
AsanInitFunction->setLinkage(Function::ExternalLinkage);
|
||||||
IRB.CreateCall(AsanInitFunction);
|
IRB.CreateCall(AsanInitFunction);
|
||||||
|
|
||||||
|
// Create __asan_report* callbacks.
|
||||||
|
for (size_t AccessIsWrite = 0; AccessIsWrite <= 1; AccessIsWrite++) {
|
||||||
|
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
|
||||||
|
AccessSizeIndex++) {
|
||||||
|
// IsWrite and TypeSize are encoded in the function name.
|
||||||
|
std::string FunctionName = std::string(kAsanReportErrorTemplate) +
|
||||||
|
(AccessIsWrite ? "store" : "load") + itostr(1 << AccessSizeIndex);
|
||||||
|
AsanErrorCallback[AccessIsWrite][AccessSizeIndex] = cast<Function>(
|
||||||
|
M.getOrInsertFunction(FunctionName, IRB.getVoidTy(), IntptrTy, NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Triple targetTriple(M.getTargetTriple());
|
llvm::Triple targetTriple(M.getTargetTriple());
|
||||||
bool isAndroid = targetTriple.getEnvironment() == llvm::Triple::ANDROIDEABI;
|
bool isAndroid = targetTriple.getEnvironment() == llvm::Triple::ANDROIDEABI;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user