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

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2165493002: Subzero: Fixed deadlock with _start but no globals (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Moved an include to the proper file 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/IceGlobalContext.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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::unique_lock<std::mutex> _(GlobalsMutex);
77 if (DidProcessGlobals) 78 if (DidProcessGlobals)
78 return; 79 return;
79 VariableDeclarationList NewGlobals; 80 VariableDeclarationList NewGlobals;
80 // Global holding pointers to all redzones 81 // Global holding pointers to all redzones
81 auto *RzArray = VariableDeclaration::create(&NewGlobals); 82 auto *RzArray = VariableDeclaration::create(&NewGlobals);
82 // Global holding sizes of all redzones 83 // Global holding sizes of all redzones
83 auto *RzSizes = VariableDeclaration::create(&NewGlobals); 84 auto *RzSizes = VariableDeclaration::create(&NewGlobals);
84 85
85 RzArray->setName(Ctx, RzArrayName); 86 RzArray->setName(Ctx, RzArrayName);
86 RzSizes->setName(Ctx, RzSizesName); 87 RzSizes->setName(Ctx, RzSizesName);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 NewGlobals.push_back(RzLeft); 129 NewGlobals.push_back(RzLeft);
129 NewGlobals.push_back(Global); 130 NewGlobals.push_back(Global);
130 NewGlobals.push_back(RzRight); 131 NewGlobals.push_back(RzRight);
131 RzGlobalsNum += 2; 132 RzGlobalsNum += 2;
132 } 133 }
133 134
134 // Replace old list of globals, without messing up arena allocators 135 // Replace old list of globals, without messing up arena allocators
135 Globals.clear(); 136 Globals.clear();
136 Globals.merge(&NewGlobals); 137 Globals.merge(&NewGlobals);
137 DidProcessGlobals = true; 138 DidProcessGlobals = true;
138 GlobalsDoneCV.notify_all();
139 139
140 // Log the new set of globals 140 // Log the new set of globals
141 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) { 141 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit)) {
142 OstreamLocker _(Ctx); 142 OstreamLocker _(Ctx);
143 Ctx->getStrDump() << "========= Instrumented Globals =========\n"; 143 Ctx->getStrDump() << "========= Instrumented Globals =========\n";
144 for (VariableDeclaration *Global : Globals) { 144 for (VariableDeclaration *Global : Globals) {
145 Global->dump(Ctx->getStrDump()); 145 Global->dump(Ctx->getStrDump());
146 } 146 }
147 } 147 }
148 } 148 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 void ASanInstrumentation::instrumentStart(Cfg *Func) { 326 void ASanInstrumentation::instrumentStart(Cfg *Func) {
327 Constant *ShadowMemInit = 327 Constant *ShadowMemInit =
328 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init")); 328 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init"));
329 constexpr SizeT NumArgs = 3; 329 constexpr SizeT NumArgs = 3;
330 constexpr Variable *Void = nullptr; 330 constexpr Variable *Void = nullptr;
331 constexpr bool NoTailCall = false; 331 constexpr bool NoTailCall = false;
332 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall); 332 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall);
333 Func->getEntryNode()->getInsts().push_front(Call); 333 Func->getEntryNode()->getInsts().push_front(Call);
334 334
335 // wait to get the final count of global redzones 335 instrumentGlobals(*getGlobals());
336 if (!DidProcessGlobals) { 336
337 GlobalsLock.lock();
338 while (!DidProcessGlobals)
339 GlobalsDoneCV.wait(GlobalsLock);
340 GlobalsLock.release();
341 }
342 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum)); 337 Call->addArg(ConstantInteger32::create(Ctx, IceType_i32, RzGlobalsNum));
343 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName))); 338 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzArrayName)));
344 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName))); 339 Call->addArg(Ctx->getConstantSym(0, Ctx->getGlobalString(RzSizesName)));
345 } 340 }
346 341
347 // TODO(tlively): make this more efficient with swap idiom 342 // TODO(tlively): make this more efficient with swap idiom
348 void ASanInstrumentation::finishFunc(Cfg *) { 343 void ASanInstrumentation::finishFunc(Cfg *) {
349 ICE_TLS_GET_FIELD(LocalDtors)->clear(); 344 ICE_TLS_GET_FIELD(LocalDtors)->clear();
350 } 345 }
351 346
352 } // end of namespace Ice 347 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698