mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-30 05:29:47 +00:00
Fix issue 67 by checking that the interface functions weren't redefined in the compiled source file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2d5fdf81dc
commit
55cabae685
@ -163,6 +163,7 @@ struct AddressSanitizer : public ModulePass {
|
|||||||
return getAlignedSize(SizeInBytes);
|
return getAlignedSize(SizeInBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Function *checkInterfaceFunction(Constant *FuncOrBitcast);
|
||||||
void PoisonStack(const ArrayRef<AllocaInst*> &AllocaVec, IRBuilder<> IRB,
|
void PoisonStack(const ArrayRef<AllocaInst*> &AllocaVec, IRBuilder<> IRB,
|
||||||
Value *ShadowBase, bool DoPoison);
|
Value *ShadowBase, bool DoPoison);
|
||||||
bool LooksLikeCodeInBug11395(Instruction *I);
|
bool LooksLikeCodeInBug11395(Instruction *I);
|
||||||
@ -317,6 +318,17 @@ void AddressSanitizer::instrumentMop(Instruction *I) {
|
|||||||
instrumentAddress(I, IRB, Addr, TypeSize, IsWrite);
|
instrumentAddress(I, IRB, Addr, TypeSize, IsWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate the result of Module::getOrInsertFunction called for an interface
|
||||||
|
// function of AddressSanitizer. If the instrumented module defines a function
|
||||||
|
// with the same name, their prototypes must match, otherwise
|
||||||
|
// getOrInsertFunction returns a bitcast.
|
||||||
|
Function *AddressSanitizer::checkInterfaceFunction(Constant *FuncOrBitcast) {
|
||||||
|
if (isa<Function>(FuncOrBitcast)) return cast<Function>(FuncOrBitcast);
|
||||||
|
FuncOrBitcast->dump();
|
||||||
|
report_fatal_error("trying to redefine an AddressSanitizer "
|
||||||
|
"interface function");
|
||||||
|
}
|
||||||
|
|
||||||
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.
|
// IsWrite and TypeSize are encoded in the function name.
|
||||||
@ -501,7 +513,7 @@ bool AddressSanitizer::insertGlobalRedzones(Module &M) {
|
|||||||
M, ArrayOfGlobalStructTy, false, GlobalVariable::PrivateLinkage,
|
M, ArrayOfGlobalStructTy, false, GlobalVariable::PrivateLinkage,
|
||||||
ConstantArray::get(ArrayOfGlobalStructTy, Initializers), "");
|
ConstantArray::get(ArrayOfGlobalStructTy, Initializers), "");
|
||||||
|
|
||||||
Function *AsanRegisterGlobals = cast<Function>(M.getOrInsertFunction(
|
Function *AsanRegisterGlobals = checkInterfaceFunction(M.getOrInsertFunction(
|
||||||
kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, NULL));
|
kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, NULL));
|
||||||
AsanRegisterGlobals->setLinkage(Function::ExternalLinkage);
|
AsanRegisterGlobals->setLinkage(Function::ExternalLinkage);
|
||||||
|
|
||||||
@ -516,8 +528,10 @@ bool AddressSanitizer::insertGlobalRedzones(Module &M) {
|
|||||||
GlobalValue::InternalLinkage, kAsanModuleDtorName, &M);
|
GlobalValue::InternalLinkage, kAsanModuleDtorName, &M);
|
||||||
BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
|
BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
|
||||||
IRBuilder<> IRB_Dtor(ReturnInst::Create(*C, AsanDtorBB));
|
IRBuilder<> IRB_Dtor(ReturnInst::Create(*C, AsanDtorBB));
|
||||||
Function *AsanUnregisterGlobals = cast<Function>(M.getOrInsertFunction(
|
Function *AsanUnregisterGlobals =
|
||||||
kAsanUnregisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, NULL));
|
checkInterfaceFunction(M.getOrInsertFunction(
|
||||||
|
kAsanUnregisterGlobalsName,
|
||||||
|
IRB.getVoidTy(), IntptrTy, IntptrTy, NULL));
|
||||||
AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage);
|
AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage);
|
||||||
|
|
||||||
IRB_Dtor.CreateCall2(AsanUnregisterGlobals,
|
IRB_Dtor.CreateCall2(AsanUnregisterGlobals,
|
||||||
@ -551,7 +565,7 @@ bool AddressSanitizer::runOnModule(Module &M) {
|
|||||||
|
|
||||||
// call __asan_init in the module ctor.
|
// call __asan_init in the module ctor.
|
||||||
IRBuilder<> IRB(CtorInsertBefore);
|
IRBuilder<> IRB(CtorInsertBefore);
|
||||||
AsanInitFunction = cast<Function>(
|
AsanInitFunction = checkInterfaceFunction(
|
||||||
M.getOrInsertFunction(kAsanInitName, IRB.getVoidTy(), NULL));
|
M.getOrInsertFunction(kAsanInitName, IRB.getVoidTy(), NULL));
|
||||||
AsanInitFunction->setLinkage(Function::ExternalLinkage);
|
AsanInitFunction->setLinkage(Function::ExternalLinkage);
|
||||||
IRB.CreateCall(AsanInitFunction);
|
IRB.CreateCall(AsanInitFunction);
|
||||||
|
Loading…
Reference in New Issue
Block a user