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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 bool ASanInstrumentation::isInstrumentable(Cfg *Func) { | 67 bool ASanInstrumentation::isInstrumentable(Cfg *Func) { |
68 std::string FuncName = Func->getFunctionName().toStringOrEmpty(); | 68 std::string FuncName = Func->getFunctionName().toStringOrEmpty(); |
69 return FuncName == "" || | 69 return FuncName == "" || |
70 (FuncBlackList.count(FuncName) == 0 && FuncName.find(ASanPrefix) != 0); | 70 (FuncBlackList.count(FuncName) == 0 && FuncName.find(ASanPrefix) != 0); |
71 } | 71 } |
72 | 72 |
73 // Create redzones around all global variables, ensuring that the initializer | 73 // Create redzones around all global variables, ensuring that the initializer |
74 // 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 |
75 // laid out together in memory. | 75 // laid out together in memory. |
76 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { | 76 void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) { |
77 if (DidProcessGlobals) | 77 GlobalsMutex.lock(); |
Jim Stichnoth
2016/07/19 14:04:13
Can you do this?
std::unique_lock<std::mutex> _
tlively
2016/07/19 22:27:04
Done.
| |
78 if (DidProcessGlobals) { | |
79 GlobalsMutex.unlock(); | |
78 return; | 80 return; |
81 } | |
79 VariableDeclarationList NewGlobals; | 82 VariableDeclarationList NewGlobals; |
80 // Global holding pointers to all redzones | 83 // Global holding pointers to all redzones |
81 auto *RzArray = VariableDeclaration::create(&NewGlobals); | 84 auto *RzArray = VariableDeclaration::create(&NewGlobals); |
82 // Global holding sizes of all redzones | 85 // Global holding sizes of all redzones |
83 auto *RzSizes = VariableDeclaration::create(&NewGlobals); | 86 auto *RzSizes = VariableDeclaration::create(&NewGlobals); |
84 | 87 |
85 RzArray->setName(Ctx, RzArrayName); | 88 RzArray->setName(Ctx, RzArrayName); |
86 RzSizes->setName(Ctx, RzSizesName); | 89 RzSizes->setName(Ctx, RzSizesName); |
87 RzArray->setIsConstant(true); | 90 RzArray->setIsConstant(true); |
88 RzSizes->setIsConstant(true); | 91 RzSizes->setIsConstant(true); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 NewGlobals.push_back(RzLeft); | 131 NewGlobals.push_back(RzLeft); |
129 NewGlobals.push_back(Global); | 132 NewGlobals.push_back(Global); |
130 NewGlobals.push_back(RzRight); | 133 NewGlobals.push_back(RzRight); |
131 RzGlobalsNum += 2; | 134 RzGlobalsNum += 2; |
132 } | 135 } |
133 | 136 |
134 // Replace old list of globals, without messing up arena allocators | 137 // Replace old list of globals, without messing up arena allocators |
135 Globals.clear(); | 138 Globals.clear(); |
136 Globals.merge(&NewGlobals); | 139 Globals.merge(&NewGlobals); |
137 DidProcessGlobals = true; | 140 DidProcessGlobals = true; |
138 GlobalsDoneCV.notify_all(); | 141 GlobalsMutex.unlock(); |
139 | 142 |
140 // Log the new set of globals | 143 // Log the new set of globals |
141 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { | 144 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { |
142 OstreamLocker _(Ctx); | 145 OstreamLocker _(Ctx); |
143 Ctx->getStrDump() << "========= Instrumented Globals =========\n"; | 146 Ctx->getStrDump() << "========= Instrumented Globals =========\n"; |
144 for (VariableDeclaration *Global : Globals) { | 147 for (VariableDeclaration *Global : Globals) { |
145 Global->dump(Ctx->getStrDump()); | 148 Global->dump(Ctx->getStrDump()); |
146 } | 149 } |
147 } | 150 } |
148 } | 151 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 328 |
326 void ASanInstrumentation::instrumentStart(Cfg *Func) { | 329 void ASanInstrumentation::instrumentStart(Cfg *Func) { |
327 Constant *ShadowMemInit = | 330 Constant *ShadowMemInit = |
328 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init")); | 331 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init")); |
329 constexpr SizeT NumArgs = 3; | 332 constexpr SizeT NumArgs = 3; |
330 constexpr Variable *Void = nullptr; | 333 constexpr Variable *Void = nullptr; |
331 constexpr bool NoTailCall = false; | 334 constexpr bool NoTailCall = false; |
332 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall); | 335 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall); |
333 Func->getEntryNode()->getInsts().push_front(Call); | 336 Func->getEntryNode()->getInsts().push_front(Call); |
334 | 337 |
335 // wait to get the final count of global redzones | 338 // wait for globals to be installed |
336 if (!DidProcessGlobals) { | 339 while (!Ctx->getGlobalsReceived()) { |
tlively
2016/07/19 07:59:54
This spinning could be replaced by a condition var
Jim Stichnoth
2016/07/19 14:04:13
Definitely add a TODO about properly using a condi
tlively
2016/07/19 22:27:04
Done.
| |
337 GlobalsLock.lock(); | |
338 while (!DidProcessGlobals) | |
339 GlobalsDoneCV.wait(GlobalsLock); | |
340 GlobalsLock.release(); | |
341 } | 340 } |
341 // instrument globals if not already done | |
342 instrumentGlobals(*Ctx->getGlobals()); | |
343 | |
342 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum)); | 344 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum)); |
343 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName))); | 345 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName))); |
344 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); | 346 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); |
345 } | 347 } |
346 | 348 |
347 // TODO(tlively): make this more efficient with swap idiom | 349 // TODO(tlively): make this more efficient with swap idiom |
348 void ASanInstrumentation::finishFunc(Cfg *) { | 350 void ASanInstrumentation::finishFunc(Cfg *) { |
349 ICE_TLS_GET_FIELD(LocalDtors)->clear(); | 351 ICE_TLS_GET_FIELD(LocalDtors)->clear(); |
350 } | 352 } |
351 | 353 |
352 } // end of namespace Ice | 354 } // end of namespace Ice |
OLD | NEW |