mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-24 22:24:54 +00:00
Implement createSanitizerCtor
, common helper function for all sanitizers
Summary: This helper function creates a ctor function, which calls sanitizer's init function with given arguments. This constructor is then expected to be added to module's ctors. The patch helps unifying how sanitizer constructor functions are created, and how init functions are called across all sanitizers. Reviewers: kcc, samsonov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8777 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -104,3 +104,24 @@ Function *llvm::checkSanitizerInterfaceFunction(Constant *FuncOrBitcast) {
|
||||
Stream << "Sanitizer interface function redefined: " << *FuncOrBitcast;
|
||||
report_fatal_error(Err);
|
||||
}
|
||||
|
||||
std::pair<Function *, Function *> llvm::createSanitizerCtorAndInitFunctions(
|
||||
Module &M, StringRef CtorName, StringRef InitName,
|
||||
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs) {
|
||||
assert(!InitName.empty() && "Expected init function name");
|
||||
assert(InitArgTypes.size() == InitArgTypes.size() &&
|
||||
"Sanitizer's init function expects different number of arguments");
|
||||
Function *Ctor = Function::Create(
|
||||
FunctionType::get(Type::getVoidTy(M.getContext()), false),
|
||||
GlobalValue::InternalLinkage, CtorName, &M);
|
||||
BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
|
||||
IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB));
|
||||
Function *InitFunction =
|
||||
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
|
||||
InitName, FunctionType::get(IRB.getVoidTy(), InitArgTypes, false),
|
||||
AttributeSet()));
|
||||
InitFunction->setLinkage(Function::ExternalLinkage);
|
||||
IRB.CreateCall(InitFunction, InitArgs);
|
||||
return std::make_pair(Ctor, InitFunction);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user