Chromium Code Reviews

Unified Diff: src/IceASanInstrumentation.cpp

Issue 2183683003: Subzero: Removed unnecessary global access checks (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: src/IceASanInstrumentation.cpp
diff --git a/src/IceASanInstrumentation.cpp b/src/IceASanInstrumentation.cpp
index b53de0d4063186e5e58d8e8f58269a200bf5027a..a812fc2b8b59d0e0da9de6bf06ee9beac7d9fbb1 100644
--- a/src/IceASanInstrumentation.cpp
+++ b/src/IceASanInstrumentation.cpp
@@ -132,6 +132,8 @@ void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) {
NewGlobals.push_back(Global);
NewGlobals.push_back(RzRight);
RzGlobalsNum += 2;
+
+ GlobalSizes.insert({Global->getName(), Global->getNumBytes()});
}
// Replace old list of globals, without messing up arena allocators
@@ -297,6 +299,8 @@ void ASanInstrumentation::instrumentAccess(LoweringContext &Context,
if (LocalSize != ICE_TLS_GET_FIELD(LocalVars)->end() &&
LocalSize->second >= Size)
return;
+ if (isOkGlobalAccess(Op, Size))
+ return;
constexpr SizeT NumArgs = 2;
constexpr Variable *Void = nullptr;
constexpr bool NoTailCall = false;
@@ -311,6 +315,15 @@ void ASanInstrumentation::instrumentAccess(LoweringContext &Context,
Context.setNext(Next);
}
+bool ASanInstrumentation::isOkGlobalAccess(Operand *Op, SizeT Size) {
+ ConstantRelocatable *Reloc = llvm::dyn_cast<ConstantRelocatable>(Op);
Jim Stichnoth 2016/07/27 13:19:34 auto *Reloc
tlively 2016/07/27 18:32:36 Done.
+ if (Reloc == nullptr)
+ return false;
+ RelocOffsetT Offset = Reloc->getOffset();
+ GlobalSizeMap::iterator GlobalSize = GlobalSizes.find(Reloc->getName());
+ return GlobalSize != GlobalSizes.end() && GlobalSize->second - Offset >= Size;
+}
+
void ASanInstrumentation::instrumentRet(LoweringContext &Context, InstRet *) {
Cfg *Func = Context.getNode()->getCfg();
InstList::iterator Next = Context.getNext();

Powered by Google App Engine