Skip to content

Commit 6552d84

Browse files
committed
[ASAN] Use nosanitize module flag.
1 parent 8a2a63b commit 6552d84

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,17 +1249,11 @@ AddressSanitizerPass::AddressSanitizerPass(
12491249
UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind),
12501250
ConstructorKind(ConstructorKind) {}
12511251

1252-
static bool hasAsanModuleCtor(Module &M) {
1253-
if (M.getFunction(kAsanModuleCtorName))
1254-
return true;
1255-
return false;
1256-
}
1257-
12581252
PreservedAnalyses AddressSanitizerPass::run(Module &M,
12591253
ModuleAnalysisManager &MAM) {
1260-
// Return early if asan.module_ctor is already present in the module.
1254+
// Return early if nosanitize module flag is present for the module.
12611255
// This implies that asan pass has already run before.
1262-
if (hasAsanModuleCtor(M))
1256+
if (M.getModuleFlag("nosanitize"))
12631257
return PreservedAnalyses::all();
12641258

12651259
ModuleAddressSanitizer ModuleSanitizer(
@@ -1278,6 +1272,8 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
12781272
Modified |= FunctionSanitizer.instrumentFunction(F, &TLI);
12791273
}
12801274
Modified |= ModuleSanitizer.instrumentModule(M);
1275+
if (Modified)
1276+
M.addModuleFlag(Module::ModFlagBehavior::Override, "nosanitize", 1);
12811277
if (!Modified)
12821278
return PreservedAnalyses::all();
12831279

llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; This test checks in the second run, function is not instrumented again.
33
; RUN: opt < %s -passes=asan,asan -S | FileCheck %s
44

@@ -8,13 +8,12 @@ target triple = "x86_64-unknown-linux-gnu"
88
; Function with sanitize_address is instrumented.
99
; Function Attrs: nounwind uwtable
1010
;.
11-
; CHECK: @llvm.used = appending global [1 x ptr] [ptr @asan.module_ctor], section "llvm.metadata"
1211
; CHECK: @___asan_globals_registered = common hidden global i64 0
1312
; CHECK: @__start_asan_globals = extern_weak hidden global i64
1413
; CHECK: @__stop_asan_globals = extern_weak hidden global i64
15-
; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @asan.module_ctor, ptr @asan.module_ctor }]
1614
;.
1715
define void @instr_sa(ptr %a) sanitize_address {
16+
; CHECK: Function Attrs: sanitize_address
1817
; CHECK-LABEL: define void @instr_sa(
1918
; CHECK-SAME: ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
2019
; CHECK-NEXT: [[ENTRY:.*:]]
@@ -24,15 +23,15 @@ define void @instr_sa(ptr %a) sanitize_address {
2423
; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
2524
; CHECK-NEXT: [[TMP4:%.*]] = load i8, ptr [[TMP3]], align 1
2625
; CHECK-NEXT: [[TMP5:%.*]] = icmp ne i8 [[TMP4]], 0
27-
; CHECK-NEXT: br i1 [[TMP5]], label %[[BB6:.*]], label %[[BB12:.*]], !prof [[PROF0:![0-9]+]]
26+
; CHECK-NEXT: br i1 [[TMP5]], label %[[BB6:.*]], label %[[BB12:.*]], !prof [[PROF1:![0-9]+]]
2827
; CHECK: [[BB6]]:
2928
; CHECK-NEXT: [[TMP7:%.*]] = and i64 [[TMP0]], 7
3029
; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[TMP7]], 3
3130
; CHECK-NEXT: [[TMP9:%.*]] = trunc i64 [[TMP8]] to i8
3231
; CHECK-NEXT: [[TMP10:%.*]] = icmp sge i8 [[TMP9]], [[TMP4]]
3332
; CHECK-NEXT: br i1 [[TMP10]], label %[[BB11:.*]], label %[[BB12]]
3433
; CHECK: [[BB11]]:
35-
; CHECK-NEXT: call void @__asan_report_load4(i64 [[TMP0]]) #[[ATTR3:[0-9]+]]
34+
; CHECK-NEXT: call void @__asan_report_load4(i64 [[TMP0]]) #[[ATTR2:[0-9]+]]
3635
; CHECK-NEXT: unreachable
3736
; CHECK: [[BB12]]:
3837
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
@@ -49,8 +48,8 @@ entry:
4948
;.
5049
; CHECK: attributes #[[ATTR0]] = { sanitize_address }
5150
; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
52-
; CHECK: attributes #[[ATTR2:[0-9]+]] = { nounwind }
53-
; CHECK: attributes #[[ATTR3]] = { nomerge }
51+
; CHECK: attributes #[[ATTR2]] = { nomerge }
5452
;.
55-
; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 1048575}
53+
; CHECK: [[META0:![0-9]+]] = !{i32 4, !"nosanitize", i32 1}
54+
; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 1048575}
5655
;.

llvm/test/Instrumentation/AddressSanitizer/missing_dbg.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ entry:
3434
!4 = !DISubroutineType(types: !5)
3535
!5 = !{}
3636

37-
; CHECK: [[DBG]] = !DILocation(line: 0, scope: !3)
37+
; CHECK: [[DBG]] = !DILocation(line: 0, scope: !4)

0 commit comments

Comments
 (0)