[PATCH] D41222: Handle previously ASAN-instrumented IR gracefully when ASAN re-invoked
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 08:33:05 PST 2017
tejohnson updated this revision to Diff 126972.
tejohnson added a comment.
Simplify test case
https://reviews.llvm.org/D41222
Files:
lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/skip-previously-instrumented.ll
Index: test/Instrumentation/AddressSanitizer/skip-previously-instrumented.ll
===================================================================
--- /dev/null
+++ test/Instrumentation/AddressSanitizer/skip-previously-instrumented.ll
@@ -0,0 +1,15 @@
+; Test to ensure previously-instrumented IR is handled gracefully
+; (ASAN skipped and not aborted).
+; RUN: opt < %s -asan -asan-module -S -o %t.ll
+; RUN: opt < %t.ll -asan -asan-module -S -o %t2.ll
+; RUN: diff %t.ll %t2.ll
+source_filename = "hello.c"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1
+
+!llvm.asan.globals = !{!0}
+
+!0 = !{[13 x i8]* @.str, !1, !"<string literal>", i1 false, i1 false}
+!1 = !{!"hello.c", i32 5, i32 12}
Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2191,7 +2191,16 @@
return Version;
}
+static bool isAlreadyAsanInstrumented(const Module &M) {
+ // Looks for a function inserted by the second (module) pass of
+ // ASAN, to detect modules fully ASAN instrumented.
+ return M.getFunction(kAsanPoisonGlobalsName) != nullptr;
+}
+
bool AddressSanitizerModule::runOnModule(Module &M) {
+ // Skip modules which already have ASan instrumentation.
+ if (isAlreadyAsanInstrumented(M))
+ return false;
C = &(M.getContext());
int LongSize = M.getDataLayout().getPointerSizeInBits();
IntptrTy = Type::getIntNTy(*C, LongSize);
@@ -2314,6 +2323,10 @@
// virtual
bool AddressSanitizer::doInitialization(Module &M) {
+ // Skip modules which already have ASan instrumentation.
+ if (isAlreadyAsanInstrumented(M))
+ return false;
+
// Initialize the private fields. No one has accessed them before.
GlobalsMD.init(M);
@@ -2405,6 +2418,9 @@
}
bool AddressSanitizer::runOnFunction(Function &F) {
+ // Skip modules which already have ASan instrumentation.
+ if (isAlreadyAsanInstrumented(*F.getParent()))
+ return false;
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
if (F.getName().startswith("__asan_")) return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41222.126972.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171214/c69a7a9b/attachment.bin>
More information about the llvm-commits
mailing list