mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
[msan] Initialize callbacks in runOnFunction as opposed to doInitialization.
This mirrors the change in ASan & TSan done in r168864. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169378 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -129,13 +129,15 @@ namespace {
|
|||||||
/// uninitialized reads.
|
/// uninitialized reads.
|
||||||
class MemorySanitizer : public FunctionPass {
|
class MemorySanitizer : public FunctionPass {
|
||||||
public:
|
public:
|
||||||
MemorySanitizer() : FunctionPass(ID), TD(0) { }
|
MemorySanitizer() : FunctionPass(ID), TD(0), WarningFn(0) { }
|
||||||
const char *getPassName() const { return "MemorySanitizer"; }
|
const char *getPassName() const { return "MemorySanitizer"; }
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
static char ID; // Pass identification, replacement for typeid.
|
static char ID; // Pass identification, replacement for typeid.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initializeCallbacks(Module &M);
|
||||||
|
|
||||||
DataLayout *TD;
|
DataLayout *TD;
|
||||||
LLVMContext *C;
|
LLVMContext *C;
|
||||||
Type *IntptrTy;
|
Type *IntptrTy;
|
||||||
@ -209,44 +211,14 @@ static GlobalVariable *createPrivateNonConstGlobalForString(Module &M,
|
|||||||
GlobalValue::PrivateLinkage, StrConst, "");
|
GlobalValue::PrivateLinkage, StrConst, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Module-level initialization.
|
|
||||||
///
|
/// \brief Insert extern declaration of runtime-provided functions and globals.
|
||||||
/// Obtains pointers to the required runtime library functions, and
|
void MemorySanitizer::initializeCallbacks(Module &M) {
|
||||||
/// inserts a call to __msan_init to the module's constructor list.
|
// Only do this once.
|
||||||
bool MemorySanitizer::doInitialization(Module &M) {
|
if (WarningFn)
|
||||||
TD = getAnalysisIfAvailable<DataLayout>();
|
return;
|
||||||
if (!TD)
|
|
||||||
return false;
|
|
||||||
BL.reset(new BlackList(ClBlackListFile));
|
|
||||||
C = &(M.getContext());
|
|
||||||
unsigned PtrSize = TD->getPointerSizeInBits(/* AddressSpace */0);
|
|
||||||
switch (PtrSize) {
|
|
||||||
case 64:
|
|
||||||
ShadowMask = kShadowMask64;
|
|
||||||
OriginOffset = kOriginOffset64;
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
ShadowMask = kShadowMask32;
|
|
||||||
OriginOffset = kOriginOffset32;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
report_fatal_error("unsupported pointer size");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
IRBuilder<> IRB(*C);
|
IRBuilder<> IRB(*C);
|
||||||
IntptrTy = IRB.getIntPtrTy(TD);
|
|
||||||
OriginTy = IRB.getInt32Ty();
|
|
||||||
|
|
||||||
ColdCallWeights = MDBuilder(*C).createBranchWeights(1, 1000);
|
|
||||||
|
|
||||||
// Insert a call to __msan_init/__msan_track_origins into the module's CTORs.
|
|
||||||
appendToGlobalCtors(M, cast<Function>(M.getOrInsertFunction(
|
|
||||||
"__msan_init", IRB.getVoidTy(), NULL)), 0);
|
|
||||||
|
|
||||||
new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
|
|
||||||
IRB.getInt32(ClTrackOrigins), "__msan_track_origins");
|
|
||||||
|
|
||||||
// Create the callback.
|
// Create the callback.
|
||||||
// FIXME: this function should have "Cold" calling conv,
|
// FIXME: this function should have "Cold" calling conv,
|
||||||
// which is not yet implemented.
|
// which is not yet implemented.
|
||||||
@ -305,6 +277,45 @@ bool MemorySanitizer::doInitialization(Module &M) {
|
|||||||
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
||||||
StringRef(""), StringRef(""),
|
StringRef(""), StringRef(""),
|
||||||
/*hasSideEffects=*/true);
|
/*hasSideEffects=*/true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Module-level initialization.
|
||||||
|
///
|
||||||
|
/// inserts a call to __msan_init to the module's constructor list.
|
||||||
|
bool MemorySanitizer::doInitialization(Module &M) {
|
||||||
|
TD = getAnalysisIfAvailable<DataLayout>();
|
||||||
|
if (!TD)
|
||||||
|
return false;
|
||||||
|
BL.reset(new BlackList(ClBlackListFile));
|
||||||
|
C = &(M.getContext());
|
||||||
|
unsigned PtrSize = TD->getPointerSizeInBits(/* AddressSpace */0);
|
||||||
|
switch (PtrSize) {
|
||||||
|
case 64:
|
||||||
|
ShadowMask = kShadowMask64;
|
||||||
|
OriginOffset = kOriginOffset64;
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
ShadowMask = kShadowMask32;
|
||||||
|
OriginOffset = kOriginOffset32;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
report_fatal_error("unsupported pointer size");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
IRBuilder<> IRB(*C);
|
||||||
|
IntptrTy = IRB.getIntPtrTy(TD);
|
||||||
|
OriginTy = IRB.getInt32Ty();
|
||||||
|
|
||||||
|
ColdCallWeights = MDBuilder(*C).createBranchWeights(1, 1000);
|
||||||
|
|
||||||
|
// Insert a call to __msan_init/__msan_track_origins into the module's CTORs.
|
||||||
|
appendToGlobalCtors(M, cast<Function>(M.getOrInsertFunction(
|
||||||
|
"__msan_init", IRB.getVoidTy(), NULL)), 0);
|
||||||
|
|
||||||
|
new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
|
||||||
|
IRB.getInt32(ClTrackOrigins), "__msan_track_origins");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,6 +422,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||||||
|
|
||||||
/// \brief Add MemorySanitizer instrumentation to a function.
|
/// \brief Add MemorySanitizer instrumentation to a function.
|
||||||
bool runOnFunction() {
|
bool runOnFunction() {
|
||||||
|
MS.initializeCallbacks(*F.getParent());
|
||||||
if (!MS.TD) return false;
|
if (!MS.TD) return false;
|
||||||
// Iterate all BBs in depth-first order and create shadow instructions
|
// Iterate all BBs in depth-first order and create shadow instructions
|
||||||
// for all instructions (where applicable).
|
// for all instructions (where applicable).
|
||||||
|
Reference in New Issue
Block a user