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 13 matching lines...) Expand all Loading... | |
| 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); | |
|
Karl
2016/07/13 21:17:57
run
make -F Makefile.standalone format
to fix li
tlively
2016/07/13 21:26:24
This is how the formatter likes it.
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |