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

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2256903003: Subzero: Replace pointers to allocation functions in stores (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Refactored common logic 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/localreplacement.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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(); 366 Operand *Src = Instr->getSourceAddress();
367 if (auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Src)) { 367 if (auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Src)) {
368 std::string SrcName = Reloc->getName().toStringOrEmpty(); 368 auto *NewLoad = InstLoad::create(Context.getNode()->getCfg(),
369 assert(!SrcName.empty()); 369 Instr->getDest(), instrumentReloc(Reloc));
370 StringMap::const_iterator SrcSub = FuncSubstitutions.find(SrcName); 370 Instr->setDeleted();
371 if (SrcSub != FuncSubstitutions.end()) { 371 Context.insert(NewLoad);
372 auto *NewSrc = ConstantRelocatable::create( 372 Instr = NewLoad;
373 Ctx, Reloc->getType(),
374 RelocatableTuple(Reloc->getOffset(), RelocOffsetArray(0),
375 Ctx->getGlobalString(SrcSub->second),
376 Reloc->getEmitString()));
377 auto *NewLoad = InstLoad::create(Context.getNode()->getCfg(),
378 Instr->getDest(), NewSrc);
379 Instr->setDeleted();
380 Context.insert(NewLoad);
381 Instr = NewLoad;
382 }
383 } 373 }
384 Constant *Func = 374 Constant *Func =
385 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_load")); 375 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_load"));
386 instrumentAccess(Context, Instr->getSourceAddress(), 376 instrumentAccess(Context, Instr->getSourceAddress(),
387 typeWidthInBytes(Instr->getDest()->getType()), Func); 377 typeWidthInBytes(Instr->getDest()->getType()), Func);
388 } 378 }
389 379
390 void ASanInstrumentation::instrumentStore(LoweringContext &Context, 380 void ASanInstrumentation::instrumentStore(LoweringContext &Context,
391 InstStore *Instr) { 381 InstStore *Instr) {
382 Operand *Data = Instr->getData();
383 if (auto *Reloc = llvm::dyn_cast<ConstantRelocatable>(Data)) {
384 auto *NewStore = InstStore::create(
385 Context.getNode()->getCfg(), instrumentReloc(Reloc), Instr->getAddr());
386 Instr->setDeleted();
387 Context.insert(NewStore);
388 Instr = NewStore;
389 }
392 Constant *Func = 390 Constant *Func =
393 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_store")); 391 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_check_store"));
394 instrumentAccess(Context, Instr->getAddr(), 392 instrumentAccess(Context, Instr->getAddr(),
395 typeWidthInBytes(Instr->getData()->getType()), Func); 393 typeWidthInBytes(Instr->getData()->getType()), Func);
396 } 394 }
397 395
396 ConstantRelocatable *
397 ASanInstrumentation::instrumentReloc(ConstantRelocatable *Reloc) {
398 std::string DataName = Reloc->getName().toString();
399 StringMap::const_iterator DataSub = FuncSubstitutions.find(DataName);
400 if (DataSub != FuncSubstitutions.end()) {
401 return ConstantRelocatable::create(
402 Ctx, Reloc->getType(),
403 RelocatableTuple(Reloc->getOffset(), RelocOffsetArray(0),
404 Ctx->getGlobalString(DataSub->second),
405 Reloc->getEmitString()));
406 }
407 return Reloc;
408 }
409
398 void ASanInstrumentation::instrumentAccess(LoweringContext &Context, 410 void ASanInstrumentation::instrumentAccess(LoweringContext &Context,
399 Operand *Op, SizeT Size, 411 Operand *Op, SizeT Size,
400 Constant *CheckFunc) { 412 Constant *CheckFunc) {
401 // Skip redundant checks within basic blocks 413 // Skip redundant checks within basic blocks
402 VarSizeMap *Checked = ICE_TLS_GET_FIELD(CheckedVars); 414 VarSizeMap *Checked = ICE_TLS_GET_FIELD(CheckedVars);
403 if (ICE_TLS_GET_FIELD(CurNode) != Context.getNode()) { 415 if (ICE_TLS_GET_FIELD(CurNode) != Context.getNode()) {
404 ICE_TLS_SET_FIELD(CurNode, Context.getNode()); 416 ICE_TLS_SET_FIELD(CurNode, Context.getNode());
405 if (Checked == NULL) { 417 if (Checked == NULL) {
406 Checked = new VarSizeMap(); 418 Checked = new VarSizeMap();
407 ICE_TLS_SET_FIELD(CheckedVars, Checked); 419 ICE_TLS_SET_FIELD(CheckedVars, Checked);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); 484 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName)));
473 } 485 }
474 486
475 // TODO(tlively): make this more efficient with swap idiom 487 // TODO(tlively): make this more efficient with swap idiom
476 void ASanInstrumentation::finishFunc(Cfg *) { 488 void ASanInstrumentation::finishFunc(Cfg *) {
477 ICE_TLS_GET_FIELD(LocalVars)->clear(); 489 ICE_TLS_GET_FIELD(LocalVars)->clear();
478 ICE_TLS_GET_FIELD(LocalDtors)->clear(); 490 ICE_TLS_GET_FIELD(LocalDtors)->clear();
479 } 491 }
480 492
481 } // end of namespace Ice 493 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | tests_lit/asan_tests/localreplacement.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698