Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2462473

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281503 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c348bc4 commit 2462473

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,17 +1882,21 @@ void AddressSanitizer::markEscapedLocalAllocas(Function &F) {
18821882
bool AddressSanitizer::runOnFunction(Function &F) {
18831883
if (&F == AsanCtorFunction) return false;
18841884
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
1885-
DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
1886-
initializeCallbacks(*F.getParent());
1887-
1888-
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1885+
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
1886+
if (F.getName().find("__asan_") != std::string::npos) return false;
18891887

18901888
// If needed, insert __asan_init before checking for SanitizeAddress attr.
1889+
// This function needs to be called even if the function body is not
1890+
// instrumented.
18911891
maybeInsertAsanInitAtFunctionEntry(F);
1892-
1892+
1893+
// Leave if the function doesn't need instrumentation.
18931894
if (!F.hasFnAttribute(Attribute::SanitizeAddress)) return false;
18941895

1895-
if (!ClDebugFunc.empty() && ClDebugFunc != F.getName()) return false;
1896+
DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
1897+
1898+
initializeCallbacks(*F.getParent());
1899+
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
18961900

18971901
FunctionStateRAII CleanupObj(this);
18981902

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; This test checks that we are not instrumenting sanitizer code.
2+
; RUN: opt < %s -asan -asan-module -S | FileCheck %s
3+
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-unknown-linux-gnu"
6+
7+
; Function Attrs: nounwind uwtable
8+
define void @__asan_default_options(i32* %a) sanitize_address {
9+
entry:
10+
%tmp1 = load i32, i32* %a, align 4
11+
%tmp2 = add i32 %tmp1, 1
12+
store i32 %tmp2, i32* %a, align 4
13+
ret void
14+
}
15+
16+
; CHECK-NOT: call void @__asan_report_load
17+
18+
; Function Attrs: nounwind uwtable
19+
define i32 @main() #0 {
20+
entry:
21+
ret i32 0
22+
}
23+
24+
; CHECK: declare void @__asan_init()

0 commit comments

Comments
 (0)