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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 &NewGlobals, RzRight, RelocOffsetArray(0))); | 125 &NewGlobals, RzRight, RelocOffsetArray(0))); |
| 126 RzSizes->addInitializer(VariableDeclaration::DataInitializer::create( | 126 RzSizes->addInitializer(VariableDeclaration::DataInitializer::create( |
| 127 &NewGlobals, sizeToByteVec(RzLeftSize))); | 127 &NewGlobals, sizeToByteVec(RzLeftSize))); |
| 128 RzSizes->addInitializer(VariableDeclaration::DataInitializer::create( | 128 RzSizes->addInitializer(VariableDeclaration::DataInitializer::create( |
| 129 &NewGlobals, sizeToByteVec(RzRightSize))); | 129 &NewGlobals, sizeToByteVec(RzRightSize))); |
| 130 | 130 |
| 131 NewGlobals.push_back(RzLeft); | 131 NewGlobals.push_back(RzLeft); |
| 132 NewGlobals.push_back(Global); | 132 NewGlobals.push_back(Global); |
| 133 NewGlobals.push_back(RzRight); | 133 NewGlobals.push_back(RzRight); |
| 134 RzGlobalsNum += 2; | 134 RzGlobalsNum += 2; |
| 135 | |
| 136 GlobalSizes.insert({Global->getName(), Global->getNumBytes()}); | |
| 135 } | 137 } |
| 136 | 138 |
| 137 // Replace old list of globals, without messing up arena allocators | 139 // Replace old list of globals, without messing up arena allocators |
| 138 Globals.clear(); | 140 Globals.clear(); |
| 139 Globals.merge(&NewGlobals); | 141 Globals.merge(&NewGlobals); |
| 140 DidProcessGlobals = true; | 142 DidProcessGlobals = true; |
| 141 | 143 |
| 142 // Log the new set of globals | 144 // Log the new set of globals |
| 143 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { | 145 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { |
| 144 OstreamLocker _(Ctx); | 146 OstreamLocker _(Ctx); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 typeWidthInBytes(Instr->getData()->getType()), Func); | 292 typeWidthInBytes(Instr->getData()->getType()), Func); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void ASanInstrumentation::instrumentAccess(LoweringContext &Context, | 295 void ASanInstrumentation::instrumentAccess(LoweringContext &Context, |
| 294 Operand *Op, SizeT Size, | 296 Operand *Op, SizeT Size, |
| 295 Constant *CheckFunc) { | 297 Constant *CheckFunc) { |
| 296 VarSizeMap::iterator LocalSize = ICE_TLS_GET_FIELD(LocalVars)->find(Op); | 298 VarSizeMap::iterator LocalSize = ICE_TLS_GET_FIELD(LocalVars)->find(Op); |
| 297 if (LocalSize != ICE_TLS_GET_FIELD(LocalVars)->end() && | 299 if (LocalSize != ICE_TLS_GET_FIELD(LocalVars)->end() && |
| 298 LocalSize->second >= Size) | 300 LocalSize->second >= Size) |
| 299 return; | 301 return; |
| 302 if (isOkGlobalAccess(Op, Size)) | |
| 303 return; | |
| 300 constexpr SizeT NumArgs = 2; | 304 constexpr SizeT NumArgs = 2; |
| 301 constexpr Variable *Void = nullptr; | 305 constexpr Variable *Void = nullptr; |
| 302 constexpr bool NoTailCall = false; | 306 constexpr bool NoTailCall = false; |
| 303 auto *Call = InstCall::create(Context.getNode()->getCfg(), NumArgs, Void, | 307 auto *Call = InstCall::create(Context.getNode()->getCfg(), NumArgs, Void, |
| 304 CheckFunc, NoTailCall); | 308 CheckFunc, NoTailCall); |
| 305 Call->addArg(Op); | 309 Call->addArg(Op); |
| 306 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, Size)); | 310 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, Size)); |
| 307 // play games to insert the call before the access instruction | 311 // play games to insert the call before the access instruction |
| 308 InstList::iterator Next = Context.getNext(); | 312 InstList::iterator Next = Context.getNext(); |
| 309 Context.setInsertPoint(Context.getCur()); | 313 Context.setInsertPoint(Context.getCur()); |
| 310 Context.insert(Call); | 314 Context.insert(Call); |
| 311 Context.setNext(Next); | 315 Context.setNext(Next); |
| 312 } | 316 } |
| 313 | 317 |
| 318 bool ASanInstrumentation::isOkGlobalAccess(Operand *Op, SizeT Size) { | |
| 319 ConstantRelocatable *Reloc = llvm::dyn_cast<ConstantRelocatable>(Op); | |
|
Jim Stichnoth
2016/07/27 13:19:34
auto *Reloc
tlively
2016/07/27 18:32:36
Done.
| |
| 320 if (Reloc == nullptr) | |
| 321 return false; | |
| 322 RelocOffsetT Offset = Reloc->getOffset(); | |
| 323 GlobalSizeMap::iterator GlobalSize = GlobalSizes.find(Reloc->getName()); | |
| 324 return GlobalSize != GlobalSizes.end() && GlobalSize->second - Offset >= Size; | |
| 325 } | |
| 326 | |
| 314 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) { | 327 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) { |
| 315 Cfg *Func = Context.getNode()->getCfg(); | 328 Cfg *Func = Context.getNode()->getCfg(); |
| 316 InstList::iterator Next = Context.getNext(); | 329 InstList::iterator Next = Context.getNext(); |
| 317 Context.setInsertPoint(Context.getCur()); | 330 Context.setInsertPoint(Context.getCur()); |
| 318 for (InstCall *RzUnpoison : *ICE_TLS_GET_FIELD(LocalDtors)) { | 331 for (InstCall *RzUnpoison : *ICE_TLS_GET_FIELD(LocalDtors)) { |
| 319 SizeT NumArgs = RzUnpoison->getNumArgs(); | 332 SizeT NumArgs = RzUnpoison->getNumArgs(); |
| 320 Variable *Dest = RzUnpoison->getDest(); | 333 Variable *Dest = RzUnpoison->getDest(); |
| 321 Operand *CallTarget = RzUnpoison->getCallTarget(); | 334 Operand *CallTarget = RzUnpoison->getCallTarget(); |
| 322 bool HasTailCall = RzUnpoison->isTailcall(); | 335 bool HasTailCall = RzUnpoison->isTailcall(); |
| 323 bool IsTargetHelperCall = RzUnpoison->isTargetHelperCall(); | 336 bool IsTargetHelperCall = RzUnpoison->isTargetHelperCall(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 347 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); | 360 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); |
| 348 } | 361 } |
| 349 | 362 |
| 350 // TODO(tlively): make this more efficient with swap idiom | 363 // TODO(tlively): make this more efficient with swap idiom |
| 351 void ASanInstrumentation::finishFunc(Cfg *) { | 364 void ASanInstrumentation::finishFunc(Cfg *) { |
| 352 ICE_TLS_GET_FIELD(LocalVars)->clear(); | 365 ICE_TLS_GET_FIELD(LocalVars)->clear(); |
| 353 ICE_TLS_GET_FIELD(LocalDtors)->clear(); | 366 ICE_TLS_GET_FIELD(LocalDtors)->clear(); |
| 354 } | 367 } |
| 355 | 368 |
| 356 } // end of namespace Ice | 369 } // end of namespace Ice |
| OLD | NEW |