[asan] don't instrument linker-initialized globals even with external linkage in -asan-initialization-order mode

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168367 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany 2012-11-20 13:11:32 +00:00
parent ca23d43084
commit 407790604b
2 changed files with 26 additions and 6 deletions

View File

@ -364,11 +364,9 @@ void AddressSanitizer::instrumentMop(Instruction *I) {
if (!ClInitializers) if (!ClInitializers)
return; return;
// If a global variable does not have dynamic initialization we don't // If a global variable does not have dynamic initialization we don't
// have to instrument it. However, if a global has external linkage, we // have to instrument it. However, if a global does not have initailizer
// assume it has dynamic initialization, as it may have an initializer // at all, we assume it has dynamic initializer (in other TU).
// in a different TU. if (G->hasInitializer() && !DynamicallyInitializedGlobals.Contains(G))
if (G->getLinkage() != GlobalVariable::ExternalLinkage &&
!DynamicallyInitializedGlobals.Contains(G))
return; return;
} }
} }

View File

@ -2,11 +2,14 @@
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu" target triple = "x86_64-unknown-linux-gnu"
@xxx = internal global i32 0, align 4 ; With dynamic initializer. @xxx = internal global i32 0, align 4 ; With dynamic initializer.
@XXX = global i32 0, align 4 ; With dynamic initializer.
@yyy = internal global i32 0, align 4 ; W/o dynamic initializer. @yyy = internal global i32 0, align 4 ; W/o dynamic initializer.
@YYY = global i32 0, align 4 ; W/o dynamic initializer.
; Clang will emit the following metadata identifying @xxx as dynamically ; Clang will emit the following metadata identifying @xxx as dynamically
; initialized. ; initialized.
!0 = metadata !{i32* @xxx} !0 = metadata !{i32* @xxx}
!llvm.asan.dynamically_initialized_globals = !{!0} !1 = metadata !{i32* @XXX}
!llvm.asan.dynamically_initialized_globals = !{!0, !1}
define i32 @initializer() uwtable { define i32 @initializer() uwtable {
entry: entry:
@ -45,6 +48,16 @@ define void @touch_xxx() address_safety {
; CHECK: ret void ; CHECK: ret void
} }
; Check that XXX is instrumented.
define void @touch_XXX() address_safety {
store i32 0, i32 *@XXX, align 4
ret void
; CHECK: define void @touch_XXX
; CHECK: call void @__asan_report_store4
; CHECK: ret void
}
; Check that yyy is NOT instrumented (as it does not have dynamic initializer). ; Check that yyy is NOT instrumented (as it does not have dynamic initializer).
define void @touch_yyy() address_safety { define void @touch_yyy() address_safety {
store i32 0, i32 *@yyy, align 4 store i32 0, i32 *@yyy, align 4
@ -53,3 +66,12 @@ define void @touch_yyy() address_safety {
; CHECK-NOT: call void @__asan_report_store4 ; CHECK-NOT: call void @__asan_report_store4
; CHECK: ret void ; CHECK: ret void
} }
; Check that YYY is NOT instrumented (as it does not have dynamic initializer).
define void @touch_YYY() address_safety {
store i32 0, i32 *@YYY, align 4
ret void
; CHECK: define void @touch_YYY
; CHECK-NOT: call void @__asan_report_store4
; CHECK: ret void
}