| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace Ice { | 22 namespace Ice { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 constexpr SizeT RzSize = 32; | 25 constexpr SizeT RzSize = 32; |
| 26 const std::string RzPrefix = "__$rz"; | 26 const std::string RzPrefix = "__$rz"; |
| 27 const llvm::NaClBitcodeRecord::RecordVector RzContents = | 27 const llvm::NaClBitcodeRecord::RecordVector RzContents = |
| 28 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R'); | 28 llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R'); |
| 29 } // end of anonymous namespace | 29 } // end of anonymous namespace |
| 30 | 30 |
| 31 // Create redzones between all global variables, ensuring that the initializer | 31 // Create redzones around all global variables, ensuring that the initializer |
| 32 // types of the redzones and their associated globals match so that they are | 32 // types of the redzones and their associated globals match so that they are |
| 33 // laid out together in memory. | 33 // laid out together in memory. |
| 34 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { | 34 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { |
| 35 if (BuildDefs::minimal() || DidInsertRedZones) | 35 if (DidInsertRedZones) |
| 36 return; | 36 return; |
| 37 | 37 |
| 38 VariableDeclarationList NewGlobals; | 38 VariableDeclarationList NewGlobals; |
| 39 // Global holding pointers to all redzones | 39 // Global holding pointers to all redzones |
| 40 auto *RzArray = VariableDeclaration::create(&NewGlobals); | 40 auto *RzArray = VariableDeclaration::create(&NewGlobals); |
| 41 // Global holding the size of RzArray | 41 // Global holding the size of RzArray |
| 42 auto *RzArraySizeVar = VariableDeclaration::create(&NewGlobals); | 42 auto *RzArraySizeVar = VariableDeclaration::create(&NewGlobals); |
| 43 SizeT RzArraySize = 0; | 43 SizeT RzArraySize = 0; |
| 44 | 44 |
| 45 RzArray->setName(Ctx, nextRzName()); | 45 RzArray->setName(Ctx, nextRzName()); |
| 46 RzArraySizeVar->setName(Ctx, nextRzName()); | 46 RzArraySizeVar->setName(Ctx, nextRzName()); |
| 47 RzArray->setIsConstant(true); | 47 RzArray->setIsConstant(true); |
| 48 RzArraySizeVar->setIsConstant(true); | 48 RzArraySizeVar->setIsConstant(true); |
| 49 NewGlobals.push_back(RzArray); | 49 NewGlobals.push_back(RzArray); |
| 50 NewGlobals.push_back(RzArraySizeVar); | 50 NewGlobals.push_back(RzArraySizeVar); |
| 51 | 51 |
| 52 for (VariableDeclaration *Global : Globals) { | 52 for (VariableDeclaration *Global : Globals) { |
| 53 VariableDeclaration *RzLeft = createRz(&NewGlobals, RzArray, RzArraySize, Gl
obal); | 53 VariableDeclaration *RzLeft = |
| 54 VariableDeclaration *RzRight = createRz(&NewGlobals, RzArray, RzArraySize, G
lobal); | 54 createRz(&NewGlobals, RzArray, RzArraySize, Global); |
| 55 VariableDeclaration *RzRight = |
| 56 createRz(&NewGlobals, RzArray, RzArraySize, Global); |
| 55 NewGlobals.push_back(RzLeft); | 57 NewGlobals.push_back(RzLeft); |
| 56 NewGlobals.push_back(Global); | 58 NewGlobals.push_back(Global); |
| 57 NewGlobals.push_back(RzRight); | 59 NewGlobals.push_back(RzRight); |
| 58 } | 60 } |
| 59 | 61 |
| 60 // update the contents of the RzArraySize global | 62 // update the contents of the RzArraySize global |
| 61 llvm::NaClBitcodeRecord::RecordVector SizeContents; | 63 llvm::NaClBitcodeRecord::RecordVector SizeContents; |
| 62 for (unsigned i = 0; i < sizeof(RzArraySize); i++) { | 64 for (unsigned i = 0; i < sizeof(RzArraySize); i++) { |
| 63 SizeContents.emplace_back(RzArraySize % (1 << CHAR_BIT)); | 65 SizeContents.emplace_back(RzArraySize % (1 << CHAR_BIT)); |
| 64 RzArraySize >>= CHAR_BIT; | 66 RzArraySize >>= CHAR_BIT; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 75 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { | 77 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { |
| 76 OstreamLocker _(Ctx); | 78 OstreamLocker _(Ctx); |
| 77 Ctx->getStrDump() << "========= Instrumented Globals =========\n"; | 79 Ctx->getStrDump() << "========= Instrumented Globals =========\n"; |
| 78 for (VariableDeclaration *Global : Globals) { | 80 for (VariableDeclaration *Global : Globals) { |
| 79 Global->dump(Ctx->getStrDump()); | 81 Global->dump(Ctx->getStrDump()); |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 84 std::string ASanInstrumentation::nextRzName() { | 86 std::string ASanInstrumentation::nextRzName() { |
| 85 if (BuildDefs::minimal()) | |
| 86 return ""; | |
| 87 std::stringstream Name; | 87 std::stringstream Name; |
| 88 Name << RzPrefix << RzNum++; | 88 Name << RzPrefix << RzNum++; |
| 89 return Name.str(); | 89 return Name.str(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 VariableDeclaration * | 92 VariableDeclaration * |
| 93 ASanInstrumentation::createRz(VariableDeclarationList *List, | 93 ASanInstrumentation::createRz(VariableDeclarationList *List, |
| 94 VariableDeclaration *RzArray, SizeT &RzArraySize, | 94 VariableDeclaration *RzArray, SizeT &RzArraySize, |
| 95 VariableDeclaration *Global) { | 95 VariableDeclaration *Global) { |
| 96 if (BuildDefs::minimal()) | |
| 97 return nullptr; | |
| 98 auto *Rz = VariableDeclaration::create(List); | 96 auto *Rz = VariableDeclaration::create(List); |
| 99 Rz->setName(Ctx, nextRzName()); | 97 Rz->setName(Ctx, nextRzName()); |
| 100 if (Global->hasNonzeroInitializer()) { | 98 if (Global->hasNonzeroInitializer()) { |
| 101 Rz->addInitializer( | 99 Rz->addInitializer( |
| 102 VariableDeclaration::DataInitializer::create(List, RzContents)); | 100 VariableDeclaration::DataInitializer::create(List, RzContents)); |
| 103 } else { | 101 } else { |
| 104 Rz->addInitializer( | 102 Rz->addInitializer( |
| 105 VariableDeclaration::ZeroInitializer::create(List, RzSize)); | 103 VariableDeclaration::ZeroInitializer::create(List, RzSize)); |
| 106 } | 104 } |
| 107 Rz->setIsConstant(Global->getIsConstant()); | 105 Rz->setIsConstant(Global->getIsConstant()); |
| 108 RzArray->addInitializer(VariableDeclaration::RelocInitializer::create( | 106 RzArray->addInitializer(VariableDeclaration::RelocInitializer::create( |
| 109 List, Rz, RelocOffsetArray(0))); | 107 List, Rz, RelocOffsetArray(0))); |
| 110 ++RzArraySize; | 108 ++RzArraySize; |
| 111 return Rz; | 109 return Rz; |
| 112 } | 110 } |
| 113 | 111 |
| 114 } // end of namespace Ice | 112 } // end of namespace Ice |
| OLD | NEW |