Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2183683003: Subzero: Removed unnecessary global access checks (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Small fixes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | tests_lit/asan_tests/instrumentload.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // TODO(tlively): Trace back load and store addresses to find their real offsets
319 bool ASanInstrumentation::isOkGlobalAccess(Operand *Op, SizeT Size) {
320 auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Op);
321 if (Reloc == nullptr)
322 return false;
323 RelocOffsetT Offset = Reloc->getOffset();
324 GlobalSizeMap::iterator GlobalSize = GlobalSizes.find(Reloc->getName());
325 return GlobalSize != GlobalSizes.end() && GlobalSize->second - Offset >= Size;
326 }
327
314 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) { 328 void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) {
315 Cfg *Func = Context.getNode()->getCfg(); 329 Cfg *Func = Context.getNode()->getCfg();
316 InstList::iterator Next = Context.getNext(); 330 InstList::iterator Next = Context.getNext();
317 Context.setInsertPoint(Context.getCur()); 331 Context.setInsertPoint(Context.getCur());
318 for (InstCall *RzUnpoison : *ICE_TLS_GET_FIELD(LocalDtors)) { 332 for (InstCall *RzUnpoison : *ICE_TLS_GET_FIELD(LocalDtors)) {
319 SizeT NumArgs = RzUnpoison->getNumArgs(); 333 SizeT NumArgs = RzUnpoison->getNumArgs();
320 Variable *Dest = RzUnpoison->getDest(); 334 Variable *Dest = RzUnpoison->getDest();
321 Operand *CallTarget = RzUnpoison->getCallTarget(); 335 Operand *CallTarget = RzUnpoison->getCallTarget();
322 bool HasTailCall = RzUnpoison->isTailcall(); 336 bool HasTailCall = RzUnpoison->isTailcall();
323 bool IsTargetHelperCall = RzUnpoison->isTargetHelperCall(); 337 bool IsTargetHelperCall = RzUnpoison->isTargetHelperCall();
(...skipping 23 matching lines...) Expand all
347 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); 361 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName)));
348 } 362 }
349 363
350 // TODO(tlively): make this more efficient with swap idiom 364 // TODO(tlively): make this more efficient with swap idiom
351 void ASanInstrumentation::finishFunc(Cfg *) { 365 void ASanInstrumentation::finishFunc(Cfg *) {
352 ICE_TLS_GET_FIELD(LocalVars)->clear(); 366 ICE_TLS_GET_FIELD(LocalVars)->clear();
353 ICE_TLS_GET_FIELD(LocalDtors)->clear(); 367 ICE_TLS_GET_FIELD(LocalDtors)->clear();
354 } 368 }
355 369
356 } // end of namespace Ice 370 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | tests_lit/asan_tests/instrumentload.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698