mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-28 22:20:43 +00:00
[asan] remove the code for --asan-merge-callbacks as it appears to be a bad idea. (partly related to Bug 13225)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161757 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8932fe4d2b
commit
11c2a47af8
@ -86,9 +86,6 @@ static cl::opt<bool> ClInstrumentWrites("asan-instrument-writes",
|
||||
static cl::opt<bool> ClInstrumentAtomics("asan-instrument-atomics",
|
||||
cl::desc("instrument atomic instructions (rmw, cmpxchg)"),
|
||||
cl::Hidden, cl::init(true));
|
||||
static cl::opt<bool> ClMergeCallbacks("asan-merge-callbacks",
|
||||
cl::desc("merge __asan_report_ callbacks to create fewer BBs"),
|
||||
cl::Hidden, cl::init(false));
|
||||
// This flag limits the number of instructions to be instrumented
|
||||
// in any given BB. Normally, this should be set to unlimited (INT_MAX),
|
||||
// but due to http://llvm.org/bugs/show_bug.cgi?id=12652 we temporary
|
||||
@ -145,24 +142,11 @@ static cl::opt<int> ClDebugMax("asan-debug-max", cl::desc("Debug man inst"),
|
||||
|
||||
namespace {
|
||||
|
||||
/// When the crash callbacks are merged, they receive some amount of arguments
|
||||
/// that are merged in a PHI node. This struct represents arguments from one
|
||||
/// call site.
|
||||
struct CrashArg {
|
||||
Value *Arg1;
|
||||
Value *Arg2;
|
||||
};
|
||||
|
||||
/// An object of this type is created while instrumenting every function.
|
||||
struct AsanFunctionContext {
|
||||
AsanFunctionContext(Function &Function) : F(Function), CrashBlock() { }
|
||||
AsanFunctionContext(Function &Function) : F(Function) { }
|
||||
|
||||
Function &F;
|
||||
// These are initially zero. If we require at least one call to
|
||||
// __asan_report_{read,write}{1,2,4,8,16}, an appropriate BB is created.
|
||||
BasicBlock *CrashBlock[2][kNumberOfAccessSizes];
|
||||
typedef SmallVector<CrashArg, 8> CrashArgsVec;
|
||||
CrashArgsVec CrashArgs[2][kNumberOfAccessSizes];
|
||||
};
|
||||
|
||||
/// AddressSanitizer: instrument the code in module to find memory bugs.
|
||||
@ -457,34 +441,12 @@ void AddressSanitizer::instrumentAddress(AsanFunctionContext &AFC,
|
||||
|
||||
Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal);
|
||||
|
||||
BasicBlock *CrashBlock = 0;
|
||||
if (ClMergeCallbacks) {
|
||||
size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
|
||||
BasicBlock **Cached = &AFC.CrashBlock[IsWrite][AccessSizeIndex];
|
||||
if (!*Cached) {
|
||||
std::string BBName("crash_bb-");
|
||||
BBName += (IsWrite ? "w-" : "r-") + itostr(1 << AccessSizeIndex);
|
||||
BasicBlock *BB = BasicBlock::Create(*C, BBName, &AFC.F);
|
||||
new UnreachableInst(*C, BB);
|
||||
*Cached = BB;
|
||||
}
|
||||
CrashBlock = *Cached;
|
||||
// We need to pass the PC as the second parameter to __asan_report_*.
|
||||
// There are few problems:
|
||||
// - Some architectures (e.g. x86_32) don't have a cheap way to get the PC.
|
||||
// - LLVM doesn't have the appropriate intrinsic.
|
||||
// For now, put a random number into the PC, just to allow experiments.
|
||||
Value *PC = ConstantInt::get(IntptrTy, rand());
|
||||
CrashArg Arg = {AddrLong, PC};
|
||||
AFC.CrashArgs[IsWrite][AccessSizeIndex].push_back(Arg);
|
||||
} else {
|
||||
CrashBlock = BasicBlock::Create(*C, "crash_bb", &AFC.F);
|
||||
new UnreachableInst(*C, CrashBlock);
|
||||
size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
|
||||
Instruction *Crash =
|
||||
generateCrashCode(CrashBlock, AddrLong, 0, IsWrite, AccessSizeIndex);
|
||||
Crash->setDebugLoc(OrigIns->getDebugLoc());
|
||||
}
|
||||
BasicBlock *CrashBlock = BasicBlock::Create(*C, "crash_bb", &AFC.F);
|
||||
new UnreachableInst(*C, CrashBlock);
|
||||
size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
|
||||
Instruction *Crash =
|
||||
generateCrashCode(CrashBlock, AddrLong, 0, IsWrite, AccessSizeIndex);
|
||||
Crash->setDebugLoc(OrigIns->getDebugLoc());
|
||||
|
||||
size_t Granularity = 1 << MappingScale;
|
||||
if (TypeSize < 8 * Granularity) {
|
||||
@ -694,12 +656,7 @@ bool AddressSanitizer::runOnModule(Module &M) {
|
||||
std::string FunctionName = std::string(kAsanReportErrorTemplate) +
|
||||
(AccessIsWrite ? "store" : "load") + itostr(1 << AccessSizeIndex);
|
||||
// If we are merging crash callbacks, they have two parameters.
|
||||
if (ClMergeCallbacks)
|
||||
AsanErrorCallback[AccessIsWrite][AccessSizeIndex] = cast<Function>(
|
||||
M.getOrInsertFunction(FunctionName, IRB.getVoidTy(), IntptrTy,
|
||||
IntptrTy, NULL));
|
||||
else
|
||||
AsanErrorCallback[AccessIsWrite][AccessSizeIndex] = cast<Function>(
|
||||
AsanErrorCallback[AccessIsWrite][AccessSizeIndex] = cast<Function>(
|
||||
M.getOrInsertFunction(FunctionName, IRB.getVoidTy(), IntptrTy, NULL));
|
||||
}
|
||||
}
|
||||
@ -845,33 +802,6 @@ bool AddressSanitizer::handleFunction(Module &M, Function &F) {
|
||||
NumInstrumented++;
|
||||
}
|
||||
|
||||
// Create PHI nodes and crash callbacks if we are merging crash callbacks.
|
||||
if (NumInstrumented) {
|
||||
for (size_t IsWrite = 0; IsWrite <= 1; IsWrite++) {
|
||||
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
|
||||
AccessSizeIndex++) {
|
||||
BasicBlock *BB = AFC.CrashBlock[IsWrite][AccessSizeIndex];
|
||||
if (!BB) continue;
|
||||
assert(ClMergeCallbacks);
|
||||
AsanFunctionContext::CrashArgsVec &Args =
|
||||
AFC.CrashArgs[IsWrite][AccessSizeIndex];
|
||||
IRBuilder<> IRB(BB->getFirstNonPHI());
|
||||
size_t n = Args.size();
|
||||
PHINode *PN1 = IRB.CreatePHI(IntptrTy, n);
|
||||
PHINode *PN2 = IRB.CreatePHI(IntptrTy, n);
|
||||
// We need to match crash parameters and the predecessors.
|
||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
||||
PI != PE; ++PI) {
|
||||
n--;
|
||||
PN1->addIncoming(Args[n].Arg1, *PI);
|
||||
PN2->addIncoming(Args[n].Arg2, *PI);
|
||||
}
|
||||
assert(n == 0);
|
||||
generateCrashCode(BB, PN1, PN2, IsWrite, AccessSizeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG(dbgs() << F);
|
||||
|
||||
bool ChangedStack = poisonStackInFunction(M, F);
|
||||
|
Loading…
Reference in New Issue
Block a user