mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-21 03:53:04 +02:00
Add proper support for -fsanitize-blacklist= flag for TSan and MSan. LLVM part.
llvm-svn: 171183
This commit is contained in:
parent
c8ec143f05
commit
3a437b2e64
@ -44,10 +44,11 @@ ModulePass *createAddressSanitizerModulePass(
|
|||||||
bool CheckInitOrder = false, StringRef BlacklistFile = StringRef());
|
bool CheckInitOrder = false, StringRef BlacklistFile = StringRef());
|
||||||
|
|
||||||
// Insert MemorySanitizer instrumentation (detection of uninitialized reads)
|
// Insert MemorySanitizer instrumentation (detection of uninitialized reads)
|
||||||
FunctionPass *createMemorySanitizerPass(bool TrackOrigins = false);
|
FunctionPass *createMemorySanitizerPass(bool TrackOrigins = false,
|
||||||
|
StringRef BlacklistFile = StringRef());
|
||||||
|
|
||||||
// Insert ThreadSanitizer (race detection) instrumentation
|
// Insert ThreadSanitizer (race detection) instrumentation
|
||||||
FunctionPass *createThreadSanitizerPass();
|
FunctionPass *createThreadSanitizerPass(StringRef BlacklistFile = StringRef());
|
||||||
|
|
||||||
|
|
||||||
// BoundsChecking - This pass instruments the code to perform run-time bounds
|
// BoundsChecking - This pass instruments the code to perform run-time bounds
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
/// value associated with them. If these bytes contain uninitialized data
|
/// value associated with them. If these bytes contain uninitialized data
|
||||||
/// coming from 2 different allocations, the last store wins. Because of this,
|
/// coming from 2 different allocations, the last store wins. Because of this,
|
||||||
/// MemorySanitizer reports can show unrelated origins, but this is unlikely in
|
/// MemorySanitizer reports can show unrelated origins, but this is unlikely in
|
||||||
/// practice.
|
/// practice.
|
||||||
///
|
///
|
||||||
/// Origins are meaningless for fully initialized values, so MemorySanitizer
|
/// Origins are meaningless for fully initialized values, so MemorySanitizer
|
||||||
/// avoids storing origin to memory when a fully initialized value is stored.
|
/// avoids storing origin to memory when a fully initialized value is stored.
|
||||||
@ -104,7 +104,7 @@ static const unsigned kMinOriginAlignment = 4;
|
|||||||
static const unsigned kShadowTLSAlignment = 8;
|
static const unsigned kShadowTLSAlignment = 8;
|
||||||
|
|
||||||
/// \brief Track origins of uninitialized values.
|
/// \brief Track origins of uninitialized values.
|
||||||
///
|
///
|
||||||
/// Adds a section to MemorySanitizer report that points to the allocation
|
/// Adds a section to MemorySanitizer report that points to the allocation
|
||||||
/// (stack or heap) the uninitialized bits came from originally.
|
/// (stack or heap) the uninitialized bits came from originally.
|
||||||
static cl::opt<bool> ClTrackOrigins("msan-track-origins",
|
static cl::opt<bool> ClTrackOrigins("msan-track-origins",
|
||||||
@ -145,7 +145,7 @@ static cl::opt<bool> ClDumpStrictInstructions("msan-dump-strict-instructions",
|
|||||||
cl::desc("print out instructions with default strict semantics"),
|
cl::desc("print out instructions with default strict semantics"),
|
||||||
cl::Hidden, cl::init(false));
|
cl::Hidden, cl::init(false));
|
||||||
|
|
||||||
static cl::opt<std::string> ClBlackListFile("msan-blacklist",
|
static cl::opt<std::string> ClBlacklistFile("msan-blacklist",
|
||||||
cl::desc("File containing the list of functions where MemorySanitizer "
|
cl::desc("File containing the list of functions where MemorySanitizer "
|
||||||
"should not report bugs"), cl::Hidden);
|
"should not report bugs"), cl::Hidden);
|
||||||
|
|
||||||
@ -158,11 +158,14 @@ namespace {
|
|||||||
/// uninitialized reads.
|
/// uninitialized reads.
|
||||||
class MemorySanitizer : public FunctionPass {
|
class MemorySanitizer : public FunctionPass {
|
||||||
public:
|
public:
|
||||||
MemorySanitizer(bool TrackOrigins = false)
|
MemorySanitizer(bool TrackOrigins = false,
|
||||||
|
StringRef BlacklistFile = StringRef())
|
||||||
: FunctionPass(ID),
|
: FunctionPass(ID),
|
||||||
TrackOrigins(TrackOrigins || ClTrackOrigins),
|
TrackOrigins(TrackOrigins || ClTrackOrigins),
|
||||||
TD(0),
|
TD(0),
|
||||||
WarningFn(0) { }
|
WarningFn(0),
|
||||||
|
BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile
|
||||||
|
: BlacklistFile) { }
|
||||||
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);
|
||||||
@ -218,6 +221,8 @@ class MemorySanitizer : public FunctionPass {
|
|||||||
MDNode *ColdCallWeights;
|
MDNode *ColdCallWeights;
|
||||||
/// \brief Branch weights for origin store.
|
/// \brief Branch weights for origin store.
|
||||||
MDNode *OriginStoreWeights;
|
MDNode *OriginStoreWeights;
|
||||||
|
/// \bried Path to blacklist file.
|
||||||
|
SmallString<64> BlacklistFile;
|
||||||
/// \brief The blacklist.
|
/// \brief The blacklist.
|
||||||
OwningPtr<BlackList> BL;
|
OwningPtr<BlackList> BL;
|
||||||
/// \brief An empty volatile inline asm that prevents callback merge.
|
/// \brief An empty volatile inline asm that prevents callback merge.
|
||||||
@ -233,8 +238,9 @@ INITIALIZE_PASS(MemorySanitizer, "msan",
|
|||||||
"MemorySanitizer: detects uninitialized reads.",
|
"MemorySanitizer: detects uninitialized reads.",
|
||||||
false, false)
|
false, false)
|
||||||
|
|
||||||
FunctionPass *llvm::createMemorySanitizerPass(bool TrackOrigins) {
|
FunctionPass *llvm::createMemorySanitizerPass(bool TrackOrigins,
|
||||||
return new MemorySanitizer(TrackOrigins);
|
StringRef BlacklistFile) {
|
||||||
|
return new MemorySanitizer(TrackOrigins, BlacklistFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Create a non-const global initialized with the given string.
|
/// \brief Create a non-const global initialized with the given string.
|
||||||
@ -324,7 +330,7 @@ bool MemorySanitizer::doInitialization(Module &M) {
|
|||||||
TD = getAnalysisIfAvailable<DataLayout>();
|
TD = getAnalysisIfAvailable<DataLayout>();
|
||||||
if (!TD)
|
if (!TD)
|
||||||
return false;
|
return false;
|
||||||
BL.reset(new BlackList(ClBlackListFile));
|
BL.reset(new BlackList(BlacklistFile));
|
||||||
C = &(M.getContext());
|
C = &(M.getContext());
|
||||||
unsigned PtrSize = TD->getPointerSizeInBits(/* AddressSpace */0);
|
unsigned PtrSize = TD->getPointerSizeInBits(/* AddressSpace */0);
|
||||||
switch (PtrSize) {
|
switch (PtrSize) {
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static cl::opt<std::string> ClBlackListFile("tsan-blacklist",
|
static cl::opt<std::string> ClBlacklistFile("tsan-blacklist",
|
||||||
cl::desc("Blacklist file"), cl::Hidden);
|
cl::desc("Blacklist file"), cl::Hidden);
|
||||||
static cl::opt<bool> ClInstrumentMemoryAccesses(
|
static cl::opt<bool> ClInstrumentMemoryAccesses(
|
||||||
"tsan-instrument-memory-accesses", cl::init(true),
|
"tsan-instrument-memory-accesses", cl::init(true),
|
||||||
@ -71,7 +71,11 @@ namespace {
|
|||||||
|
|
||||||
/// ThreadSanitizer: instrument the code in module to find races.
|
/// ThreadSanitizer: instrument the code in module to find races.
|
||||||
struct ThreadSanitizer : public FunctionPass {
|
struct ThreadSanitizer : public FunctionPass {
|
||||||
ThreadSanitizer();
|
ThreadSanitizer(StringRef BlacklistFile = StringRef())
|
||||||
|
: FunctionPass(ID),
|
||||||
|
TD(0),
|
||||||
|
BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile
|
||||||
|
: BlacklistFile) { }
|
||||||
const char *getPassName() const;
|
const char *getPassName() const;
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
@ -87,6 +91,7 @@ struct ThreadSanitizer : public FunctionPass {
|
|||||||
int getMemoryAccessFuncIndex(Value *Addr);
|
int getMemoryAccessFuncIndex(Value *Addr);
|
||||||
|
|
||||||
DataLayout *TD;
|
DataLayout *TD;
|
||||||
|
SmallString<64> BlacklistFile;
|
||||||
OwningPtr<BlackList> BL;
|
OwningPtr<BlackList> BL;
|
||||||
IntegerType *OrdTy;
|
IntegerType *OrdTy;
|
||||||
// Callbacks to run-time library are computed in doInitialization.
|
// Callbacks to run-time library are computed in doInitialization.
|
||||||
@ -115,13 +120,8 @@ const char *ThreadSanitizer::getPassName() const {
|
|||||||
return "ThreadSanitizer";
|
return "ThreadSanitizer";
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadSanitizer::ThreadSanitizer()
|
FunctionPass *llvm::createThreadSanitizerPass(StringRef BlacklistFile) {
|
||||||
: FunctionPass(ID),
|
return new ThreadSanitizer(BlacklistFile);
|
||||||
TD(NULL) {
|
|
||||||
}
|
|
||||||
|
|
||||||
FunctionPass *llvm::createThreadSanitizerPass() {
|
|
||||||
return new ThreadSanitizer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Function *checkInterfaceFunction(Constant *FuncOrBitcast) {
|
static Function *checkInterfaceFunction(Constant *FuncOrBitcast) {
|
||||||
@ -206,7 +206,7 @@ bool ThreadSanitizer::doInitialization(Module &M) {
|
|||||||
TD = getAnalysisIfAvailable<DataLayout>();
|
TD = getAnalysisIfAvailable<DataLayout>();
|
||||||
if (!TD)
|
if (!TD)
|
||||||
return false;
|
return false;
|
||||||
BL.reset(new BlackList(ClBlackListFile));
|
BL.reset(new BlackList(BlacklistFile));
|
||||||
|
|
||||||
// Always insert a call to __tsan_init into the module's CTORs.
|
// Always insert a call to __tsan_init into the module's CTORs.
|
||||||
IRBuilder<> IRB(M.getContext());
|
IRBuilder<> IRB(M.getContext());
|
||||||
|
Loading…
Reference in New Issue
Block a user