|
@@ -968,18 +968,6 @@ void AddressSanitizer::instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
|
|
|
UseCalls, Exp);
|
|
|
}
|
|
|
|
|
|
-// 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.
|
|
|
-static Function *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 *InsertBefore,
|
|
|
Value *Addr, bool IsWrite,
|
|
|
size_t AccessSizeIndex,
|
|
@@ -1228,17 +1216,17 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) {
|
|
|
void AddressSanitizerModule::initializeCallbacks(Module &M) {
|
|
|
IRBuilder<> IRB(*C);
|
|
|
// Declare our poisoning and unpoisoning functions.
|
|
|
- AsanPoisonGlobals = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanPoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanPoisonGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr));
|
|
|
AsanPoisonGlobals->setLinkage(Function::ExternalLinkage);
|
|
|
- AsanUnpoisonGlobals = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanUnpoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanUnpoisonGlobalsName, IRB.getVoidTy(), nullptr));
|
|
|
AsanUnpoisonGlobals->setLinkage(Function::ExternalLinkage);
|
|
|
// Declare functions that register/unregister globals.
|
|
|
- AsanRegisterGlobals = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanRegisterGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
|
|
|
AsanRegisterGlobals->setLinkage(Function::ExternalLinkage);
|
|
|
- AsanUnregisterGlobals = checkInterfaceFunction(
|
|
|
+ AsanUnregisterGlobals = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanUnregisterGlobalsName, IRB.getVoidTy(),
|
|
|
IntptrTy, IntptrTy, nullptr));
|
|
|
AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage);
|
|
@@ -1408,44 +1396,44 @@ void AddressSanitizer::initializeCallbacks(Module &M) {
|
|
|
const std::string ExpStr = Exp ? "exp_" : "";
|
|
|
const Type *ExpType = Exp ? Type::getInt32Ty(*C) : nullptr;
|
|
|
AsanErrorCallbackSized[AccessIsWrite][Exp] =
|
|
|
- checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanReportErrorTemplate + ExpStr + TypeStr + "_n",
|
|
|
IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr));
|
|
|
AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] =
|
|
|
- checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N",
|
|
|
IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr));
|
|
|
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
|
|
|
AccessSizeIndex++) {
|
|
|
const std::string Suffix = TypeStr + itostr(1 << AccessSizeIndex);
|
|
|
AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] =
|
|
|
- checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanReportErrorTemplate + ExpStr + Suffix, IRB.getVoidTy(),
|
|
|
IntptrTy, ExpType, nullptr));
|
|
|
AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] =
|
|
|
- checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
ClMemoryAccessCallbackPrefix + ExpStr + Suffix, IRB.getVoidTy(),
|
|
|
IntptrTy, ExpType, nullptr));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- AsanMemmove = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanMemmove = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
ClMemoryAccessCallbackPrefix + "memmove", IRB.getInt8PtrTy(),
|
|
|
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr));
|
|
|
- AsanMemcpy = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanMemcpy = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
ClMemoryAccessCallbackPrefix + "memcpy", IRB.getInt8PtrTy(),
|
|
|
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr));
|
|
|
- AsanMemset = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanMemset = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
ClMemoryAccessCallbackPrefix + "memset", IRB.getInt8PtrTy(),
|
|
|
IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy, nullptr));
|
|
|
|
|
|
- AsanHandleNoReturnFunc = checkInterfaceFunction(
|
|
|
+ AsanHandleNoReturnFunc = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy(), nullptr));
|
|
|
|
|
|
- AsanPtrCmpFunction = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanPtrCmpFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanPtrCmp, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
|
|
|
- AsanPtrSubFunction = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
+ AsanPtrSubFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
|
|
kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
|
|
|
// We insert an empty inline asm after __asan_report* to avoid callback merge.
|
|
|
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
|
@@ -1470,7 +1458,7 @@ bool AddressSanitizer::doInitialization(Module &M) {
|
|
|
BasicBlock *AsanCtorBB = BasicBlock::Create(*C, "", AsanCtorFunction);
|
|
|
// call __asan_init in the module ctor.
|
|
|
IRBuilder<> IRB(ReturnInst::Create(*C, AsanCtorBB));
|
|
|
- AsanInitFunction = checkInterfaceFunction(
|
|
|
+ AsanInitFunction = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanInitName, IRB.getVoidTy(), nullptr));
|
|
|
AsanInitFunction->setLinkage(Function::ExternalLinkage);
|
|
|
IRB.CreateCall(AsanInitFunction);
|
|
@@ -1622,16 +1610,17 @@ void FunctionStackPoisoner::initializeCallbacks(Module &M) {
|
|
|
IRBuilder<> IRB(*C);
|
|
|
for (int i = 0; i <= kMaxAsanStackMallocSizeClass; i++) {
|
|
|
std::string Suffix = itostr(i);
|
|
|
- AsanStackMallocFunc[i] = checkInterfaceFunction(M.getOrInsertFunction(
|
|
|
- kAsanStackMallocNameTemplate + Suffix, IntptrTy, IntptrTy, nullptr));
|
|
|
- AsanStackFreeFunc[i] = checkInterfaceFunction(
|
|
|
+ AsanStackMallocFunc[i] = checkSanitizerInterfaceFunction(
|
|
|
+ M.getOrInsertFunction(kAsanStackMallocNameTemplate + Suffix, IntptrTy,
|
|
|
+ IntptrTy, nullptr));
|
|
|
+ AsanStackFreeFunc[i] = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanStackFreeNameTemplate + Suffix,
|
|
|
IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
|
|
|
}
|
|
|
- AsanPoisonStackMemoryFunc = checkInterfaceFunction(
|
|
|
+ AsanPoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanPoisonStackMemoryName, IRB.getVoidTy(),
|
|
|
IntptrTy, IntptrTy, nullptr));
|
|
|
- AsanUnpoisonStackMemoryFunc = checkInterfaceFunction(
|
|
|
+ AsanUnpoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
|
|
|
M.getOrInsertFunction(kAsanUnpoisonStackMemoryName, IRB.getVoidTy(),
|
|
|
IntptrTy, IntptrTy, nullptr));
|
|
|
}
|