Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceASanInstrumentation.cpp - ASan ------------*- C++ -*-===// | 1 //===- subzero/src/IceASanInstrumentation.cpp - ASan ------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 InstCall::create(Context.getNode()->getCfg(), Instr->getNumArgs(), | 356 InstCall::create(Context.getNode()->getCfg(), Instr->getNumArgs(), |
| 357 Instr->getDest(), NewFunc, Instr->isTailcall()); | 357 Instr->getDest(), NewFunc, Instr->isTailcall()); |
| 358 for (SizeT I = 0, Args = Instr->getNumArgs(); I < Args; ++I) | 358 for (SizeT I = 0, Args = Instr->getNumArgs(); I < Args; ++I) |
| 359 NewCall->addArg(Instr->getArg(I)); | 359 NewCall->addArg(Instr->getArg(I)); |
| 360 Context.insert(NewCall); | 360 Context.insert(NewCall); |
| 361 Instr->setDeleted(); | 361 Instr->setDeleted(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void ASanInstrumentation::instrumentLoad(LoweringContext &Context, | 364 void ASanInstrumentation::instrumentLoad(LoweringContext &Context, |
| 365 InstLoad *Instr) { | 365 InstLoad *Instr) { |
| 366 Operand *Src = Instr->getSourceAddress(); | |
| 367 auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Src); | |
| 368 if (Reloc != nullptr) { | |
|
Jim Stichnoth
2016/08/16 21:36:46
if (auto *Reloc = llvm::dyn_cast<ConstantRelocatab
tlively
2016/08/16 21:55:38
Done.
| |
| 369 std::string SrcName = Reloc->getName().toStringOrEmpty(); | |
| 370 assert(!SrcName.empty()); | |
| 371 StringMap::const_iterator SrcSub = FuncSubstitutions.find(SrcName); | |
| 372 if (SrcSub != FuncSubstitutions.end()) { | |
| 373 auto *NewSrc = ConstantRelocatable::create( | |
| 374 Ctx, Reloc->getType(), | |
| 375 RelocatableTuple(Reloc->getOffset(), RelocOffsetArray(0), | |
| 376 Ctx->getGlobalString(SrcSub->second), | |
| 377 Reloc->getEmitString())); | |
| 378 auto *NewLoad = InstLoad::create(Context.getNode()->getCfg(), | |
| 379 Instr->getDest(), NewSrc); | |
| 380 Instr->setDeleted(); | |
| 381 Context.insert(NewLoad); | |
| 382 instrumentLoad(Context, NewLoad); | |
|
Karl
2016/08/16 21:38:43
Do you need to recurse here? It looks like you jus
tlively
2016/08/16 21:55:38
Done.
| |
| 383 return; | |
| 384 } | |
| 385 } | |
| 366 Constant *Func = | 386 Constant *Func = |
| 367 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_load")); | 387 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_load")); |
| 368 instrumentAccess(Context, Instr->getSourceAddress(), | 388 instrumentAccess(Context, Instr->getSourceAddress(), |
| 369 typeWidthInBytes(Instr->getDest()->getType()), Func); | 389 typeWidthInBytes(Instr->getDest()->getType()), Func); |
| 370 } | 390 } |
| 371 | 391 |
| 372 void ASanInstrumentation::instrumentStore(LoweringContext &Context, | 392 void ASanInstrumentation::instrumentStore(LoweringContext &Context, |
| 373 InstStore *Instr) { | 393 InstStore *Instr) { |
| 374 Constant *Func = | 394 Constant *Func = |
| 375 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_store")); | 395 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_store")); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 CheckFunc, NoTailCall); | 430 CheckFunc, NoTailCall); |
| 411 Call->addArg(Op); | 431 Call->addArg(Op); |
| 412 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, Size)); | 432 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, Size)); |
| 413 // play games to insert the call before the access instruction | 433 // play games to insert the call before the access instruction |
| 414 InstList::iterator Next = Context.getNext(); | 434 InstList::iterator Next = Context.getNext(); |
| 415 Context.setInsertPoint(Context.getCur()); | 435 Context.setInsertPoint(Context.getCur()); |
| 416 Context.insert(Call); | 436 Context.insert(Call); |
| 417 Context.setNext(Next); | 437 Context.setNext(Next); |
| 418 } | 438 } |
| 419 | 439 |
| 420 // TODO(tlively): Trace back load and store addresses to find their real offsets | 440 // TODO(tlively): Trace back load and store addresses to find their real |
|
Jim Stichnoth
2016/08/16 21:36:46
Why did this line change?
tlively
2016/08/16 21:55:38
Done.
| |
| 441 // offsets | |
| 421 bool ASanInstrumentation::isOkGlobalAccess(Operand *Op, SizeT Size) { | 442 bool ASanInstrumentation::isOkGlobalAccess(Operand *Op, SizeT Size) { |
| 422 auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Op); | 443 auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Op); |
| 423 if (Reloc == nullptr) | 444 if (Reloc == nullptr) |
| 424 return false; | 445 return false; |
| 425 RelocOffsetT Offset = Reloc->getOffset(); | 446 RelocOffsetT Offset = Reloc->getOffset(); |
| 426 GlobalSizeMap::iterator GlobalSize = GlobalSizes.find(Reloc->getName()); | 447 GlobalSizeMap::iterator GlobalSize = GlobalSizes.find(Reloc->getName()); |
| 427 return GlobalSize != GlobalSizes.end() && GlobalSize->second - Offset >= Size; | 448 return GlobalSize != GlobalSizes.end() && GlobalSize->second - Offset >= Size; |
| 428 } | 449 } |
| 429 | 450 |
| 430 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) { | 451 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 454 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); | 475 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); |
| 455 } | 476 } |
| 456 | 477 |
| 457 // TODO(tlively): make this more efficient with swap idiom | 478 // TODO(tlively): make this more efficient with swap idiom |
| 458 void ASanInstrumentation::finishFunc(Cfg *) { | 479 void ASanInstrumentation::finishFunc(Cfg *) { |
| 459 ICE_TLS_GET_FIELD(LocalVars)->clear(); | 480 ICE_TLS_GET_FIELD(LocalVars)->clear(); |
| 460 ICE_TLS_GET_FIELD(LocalDtors)->clear(); | 481 ICE_TLS_GET_FIELD(LocalDtors)->clear(); |
| 461 } | 482 } |
| 462 | 483 |
| 463 } // end of namespace Ice | 484 } // end of namespace Ice |
| OLD | NEW |