[llvm] r281503 - [compiler-rt] Avoid instrumenting sanitizer functions
Etienne Bergeron via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 10:18:37 PDT 2016
Author: etienneb
Date: Wed Sep 14 12:18:37 2016
New Revision: 281503
URL: http://llvm.org/viewvc/llvm-project?rev=281503&view=rev
Log:
[compiler-rt] Avoid instrumenting sanitizer functions
Summary:
Function __asan_default_options is called by __asan_init before the
shadow memory got initialized. Instrumenting that function may lead
to flaky execution.
As the __asan_default_options is provided by users, we cannot expect
them to add the appropriate function atttributes to avoid
instrumentation.
Reviewers: kcc, rnk
Subscribers: dberris, chrisha, llvm-commits
Differential Revision: https://reviews.llvm.org/D24566
Added:
llvm/trunk/test/Instrumentation/AddressSanitizer/do-not-instrument-sanitizers.ll
Modified:
llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=281503&r1=281502&r2=281503&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Wed Sep 14 12:18:37 2016
@@ -1882,17 +1882,21 @@ void AddressSanitizer::markEscapedLocalA
bool AddressSanitizer::runOnFunction(Function &F) {
if (&F == AsanCtorFunction) return false;
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
- DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
- initializeCallbacks(*F.getParent());
-
- DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
+ if (F.getName().find("__asan_") != std::string::npos) return false;
// If needed, insert __asan_init before checking for SanitizeAddress attr.
+ // This function needs to be called even if the function body is not
+ // instrumented.
maybeInsertAsanInitAtFunctionEntry(F);
-
+
+ // Leave if the function doesn't need instrumentation.
if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return false;
- if (!ClDebugFunc.empty() && ClDebugFunc != F.getName()) return false;
+ DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
+
+ initializeCallbacks(*F.getParent());
+ DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
FunctionStateRAII CleanupObj(this);
Added: llvm/trunk/test/Instrumentation/AddressSanitizer/do-not-instrument-sanitizers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/do-not-instrument-sanitizers.ll?rev=281503&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/do-not-instrument-sanitizers.ll (added)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/do-not-instrument-sanitizers.ll Wed Sep 14 12:18:37 2016
@@ -0,0 +1,24 @@
+; This test checks that we are not instrumenting sanitizer code.
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define void @__asan_default_options(i32* %a) sanitize_address {
+entry:
+ %tmp1 = load i32, i32* %a, align 4
+ %tmp2 = add i32 %tmp1, 1
+ store i32 %tmp2, i32* %a, align 4
+ ret void
+}
+
+; CHECK-NOT: call void @__asan_report_load
+
+; Function Attrs: nounwind uwtable
+define i32 @main() #0 {
+entry:
+ ret i32 0
+}
+
+; CHECK: declare void @__asan_init()
\ No newline at end of file
More information about the llvm-commits
mailing list