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

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2145063003: Updates in preparation of wrapper script (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: minor fix to test 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 | « runtime/szrt_asan.c ('k') | tests_lit/asan_tests/func_ptr.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 13 matching lines...) Expand all
24 24
25 #include <sstream> 25 #include <sstream>
26 #include <unordered_map> 26 #include <unordered_map>
27 #include <unordered_set> 27 #include <unordered_set>
28 #include <vector> 28 #include <vector>
29 29
30 namespace Ice { 30 namespace Ice {
31 31
32 namespace { 32 namespace {
33 33
34 constexpr const char *ASanPrefix = "__asan";
34 constexpr SizeT RzSize = 32; 35 constexpr SizeT RzSize = 32;
35 constexpr const char *RzPrefix = "__$rz"; 36 constexpr const char *RzPrefix = "__$rz";
36 constexpr const char *RzArrayName = "__$rz_array"; 37 constexpr const char *RzArrayName = "__$rz_array";
37 constexpr const char *RzSizesName = "__$rz_sizes"; 38 constexpr const char *RzSizesName = "__$rz_sizes";
38 const llvm::NaClBitcodeRecord::RecordVector RzContents = 39 const llvm::NaClBitcodeRecord::RecordVector RzContents =
39 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R'); 40 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R');
40 41
41 // In order to instrument the code correctly, the .pexe must not have had its 42 // In order to instrument the code correctly, the .pexe must not have had its
42 // symbols stripped. 43 // symbols stripped.
43 using string_map = std::unordered_map<std::string, std::string>; 44 using string_map = std::unordered_map<std::string, std::string>;
44 using string_set = std::unordered_set<std::string>; 45 using string_set = std::unordered_set<std::string>;
45 // TODO(tlively): Handle all allocation functions 46 // TODO(tlively): Handle all allocation functions
46 const string_map FuncSubstitutions = {{"malloc", "__asan_malloc"}, 47 const string_map FuncSubstitutions = {{"malloc", "__asan_malloc"},
47 {"free", "__asan_free"}}; 48 {"free", "__asan_free"},
49 {"calloc", "__asan_calloc"},
50 {"__asan_dummy_calloc", "__asan_calloc"}};
48 const string_set FuncBlackList = {"_Balloc"}; 51 const string_set FuncBlackList = {"_Balloc"};
49 52
50 llvm::NaClBitcodeRecord::RecordVector sizeToByteVec(SizeT Size) { 53 llvm::NaClBitcodeRecord::RecordVector sizeToByteVec(SizeT Size) {
51 llvm::NaClBitcodeRecord::RecordVector SizeContents; 54 llvm::NaClBitcodeRecord::RecordVector SizeContents;
52 for (unsigned i = 0; i < sizeof(Size); ++i) { 55 for (unsigned i = 0; i < sizeof(Size); ++i) {
53 SizeContents.emplace_back(Size % (1 << CHAR_BIT)); 56 SizeContents.emplace_back(Size % (1 << CHAR_BIT));
54 Size >>= CHAR_BIT; 57 Size >>= CHAR_BIT;
55 } 58 }
56 return SizeContents; 59 return SizeContents;
57 } 60 }
58 61
59 } // end of anonymous namespace 62 } // end of anonymous namespace
60 63
61 ICE_TLS_DEFINE_FIELD(std::vector<InstCall *> *, ASanInstrumentation, 64 ICE_TLS_DEFINE_FIELD(std::vector<InstCall *> *, ASanInstrumentation,
62 LocalDtors); 65 LocalDtors);
63 66
64 bool ASanInstrumentation::isInstrumentable(Cfg *Func) { 67 bool ASanInstrumentation::isInstrumentable(Cfg *Func) {
65 std::string FuncName = Func->getFunctionName().toStringOrEmpty(); 68 std::string FuncName = Func->getFunctionName().toStringOrEmpty();
66 return FuncName == "" || FuncBlackList.count(FuncName) == 0; 69 return FuncName == "" ||
70 (FuncBlackList.count(FuncName) == 0 && FuncName.find(ASanPrefix) != 0);
67 } 71 }
68 72
69 // Create redzones around all global variables, ensuring that the initializer 73 // Create redzones around all global variables, ensuring that the initializer
70 // types of the redzones and their associated globals match so that they are 74 // types of the redzones and their associated globals match so that they are
71 // laid out together in memory. 75 // laid out together in memory.
72 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { 76 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) {
73 if (DidProcessGlobals) 77 if (DidProcessGlobals)
74 return; 78 return;
75 VariableDeclarationList NewGlobals; 79 VariableDeclarationList NewGlobals;
76 // Global holding pointers to all redzones 80 // Global holding pointers to all redzones
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName))); 343 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName)));
340 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); 344 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName)));
341 } 345 }
342 346
343 // TODO(tlively): make this more efficient with swap idiom 347 // TODO(tlively): make this more efficient with swap idiom
344 void ASanInstrumentation::finishFunc(Cfg *) { 348 void ASanInstrumentation::finishFunc(Cfg *) {
345 ICE_TLS_GET_FIELD(LocalDtors)->clear(); 349 ICE_TLS_GET_FIELD(LocalDtors)->clear();
346 } 350 }
347 351
348 } // end of namespace Ice 352 } // end of namespace Ice
OLDNEW
« no previous file with comments | « runtime/szrt_asan.c ('k') | tests_lit/asan_tests/func_ptr.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698