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

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2128383002: Blacklisted instrumenting _Balloc. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 5 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') | src/IceInstrumentation.h » ('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
11 /// \brief Implements the AddressSanitizer instrumentation class. 11 /// \brief Implements the AddressSanitizer instrumentation class.
12 /// 12 ///
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "IceASanInstrumentation.h" 15 #include "IceASanInstrumentation.h"
16 16
17 #include "IceBuildDefs.h" 17 #include "IceBuildDefs.h"
18 #include "IceCfg.h" 18 #include "IceCfg.h"
19 #include "IceCfgNode.h" 19 #include "IceCfgNode.h"
20 #include "IceGlobalInits.h" 20 #include "IceGlobalInits.h"
21 #include "IceInst.h" 21 #include "IceInst.h"
22 #include "IceTargetLowering.h" 22 #include "IceTargetLowering.h"
23 #include "IceTypes.h" 23 #include "IceTypes.h"
24 24
25 #include <sstream> 25 #include <sstream>
26 #include <unordered_map> 26 #include <unordered_map>
27 #include <unordered_set>
27 #include <vector> 28 #include <vector>
28 29
29 namespace Ice { 30 namespace Ice {
30 31
31 namespace { 32 namespace {
32 33
33 constexpr SizeT RzSize = 32; 34 constexpr SizeT RzSize = 32;
34 constexpr const char *RzPrefix = "__$rz"; 35 constexpr const char *RzPrefix = "__$rz";
35 constexpr const char *RzArrayName = "__$rz_array"; 36 constexpr const char *RzArrayName = "__$rz_array";
36 constexpr const char *RzSizesName = "__$rz_sizes"; 37 constexpr const char *RzSizesName = "__$rz_sizes";
37 const llvm::NaClBitcodeRecord::RecordVector RzContents = 38 const llvm::NaClBitcodeRecord::RecordVector RzContents =
38 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R'); 39 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R');
39 40
40 // TODO(tlively): Handle all allocation functions
41 // In order to instrument the code correctly, the .pexe must not have had its 41 // In order to instrument the code correctly, the .pexe must not have had its
42 // symbols stripped. 42 // symbols stripped.
43 using string_map = std::unordered_map<std::string, std::string>; 43 using string_map = std::unordered_map<std::string, std::string>;
44 using string_set = std::unordered_set<std::string>;
45 // TODO(tlively): Handle all allocation functions
44 const string_map FuncSubstitutions = {{"malloc", "__asan_malloc"}, 46 const string_map FuncSubstitutions = {{"malloc", "__asan_malloc"},
45 {"free", "__asan_free"}}; 47 {"free", "__asan_free"}};
48 const string_set FuncBlackList = {"_Balloc"};
46 49
47 llvm::NaClBitcodeRecord::RecordVector sizeToByteVec(SizeT Size) { 50 llvm::NaClBitcodeRecord::RecordVector sizeToByteVec(SizeT Size) {
48 llvm::NaClBitcodeRecord::RecordVector SizeContents; 51 llvm::NaClBitcodeRecord::RecordVector SizeContents;
49 for (unsigned i = 0; i < sizeof(Size); ++i) { 52 for (unsigned i = 0; i < sizeof(Size); ++i) {
50 SizeContents.emplace_back(Size % (1 << CHAR_BIT)); 53 SizeContents.emplace_back(Size % (1 << CHAR_BIT));
51 Size >>= CHAR_BIT; 54 Size >>= CHAR_BIT;
52 } 55 }
53 return SizeContents; 56 return SizeContents;
54 } 57 }
55 58
56 } // end of anonymous namespace 59 } // end of anonymous namespace
57 60
58 ICE_TLS_DEFINE_FIELD(std::vector<InstCall *> *, ASanInstrumentation, 61 ICE_TLS_DEFINE_FIELD(std::vector<InstCall *> *, ASanInstrumentation,
59 LocalDtors); 62 LocalDtors);
60 63
64 bool ASanInstrumentation::isInstrumentable(Cfg *Func) {
65 std::string FuncName = Func->getFunctionName().toStringOrEmpty();
66 return FuncName == "" || FuncBlackList.find(FuncName) == FuncBlackList.end();
Karl 2016/07/07 21:20:49 Actually, a simpler test is: || FuncBlackList
tlively 2016/07/08 16:56:21 Done.
67 }
68
61 // Create redzones around all global variables, ensuring that the initializer 69 // Create redzones around all global variables, ensuring that the initializer
62 // types of the redzones and their associated globals match so that they are 70 // types of the redzones and their associated globals match so that they are
63 // laid out together in memory. 71 // laid out together in memory.
64 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { 72 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) {
65 if (DidProcessGlobals) 73 if (DidProcessGlobals)
66 return; 74 return;
67 VariableDeclarationList NewGlobals; 75 VariableDeclarationList NewGlobals;
68 // Global holding pointers to all redzones 76 // Global holding pointers to all redzones
69 auto *RzArray = VariableDeclaration::create(&NewGlobals); 77 auto *RzArray = VariableDeclaration::create(&NewGlobals);
70 // Global holding sizes of all redzones 78 // Global holding sizes of all redzones
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 while (!DidProcessGlobals) 334 while (!DidProcessGlobals)
327 GlobalsDoneCV.wait(GlobalsLock); 335 GlobalsDoneCV.wait(GlobalsLock);
328 GlobalsLock.release(); 336 GlobalsLock.release();
329 } 337 }
330 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum)); 338 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum));
331 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName))); 339 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName)));
332 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); 340 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName)));
333 } 341 }
334 342
335 // TODO(tlively): make this more efficient with swap idiom 343 // TODO(tlively): make this more efficient with swap idiom
336 void ASanInstrumentation::finishFunc(Cfg *Func) { 344 void ASanInstrumentation::finishFunc(Cfg *) {
337 (void)Func;
338 ICE_TLS_GET_FIELD(LocalDtors)->clear(); 345 ICE_TLS_GET_FIELD(LocalDtors)->clear();
339 } 346 }
340 347
341 } // end of namespace Ice 348 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | src/IceInstrumentation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698