1 ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
2 ; RUN: opt < %s -asan -asan-module -asan-mapping-scale=5 -S | FileCheck %s
3 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"
4 target triple = "x86_64-unknown-linux-gnu"
5 @xxx = internal global i32 0, align 4 ; With dynamic initializer.
6 @XXX = global i32 0, align 4 ; With dynamic initializer.
7 @yyy = internal global i32 0, align 4 ; W/o dynamic initializer.
8 @YYY = global i32 0, align 4 ; W/o dynamic initializer.
9 ; Clang will emit the following metadata identifying @xxx as dynamically
11 !0 = !{i32* @xxx, null, null, i1 true, i1 false}
12 !1 = !{i32* @XXX, null, null, i1 true, i1 false}
13 !2 = !{i32* @yyy, null, null, i1 false, i1 false}
14 !3 = !{i32* @YYY, null, null, i1 false, i1 false}
15 !llvm.asan.globals = !{!0, !1, !2, !3}
17 define i32 @initializer() uwtable {
22 define internal void @__cxx_global_var_init() section ".text.startup" {
24 %call = call i32 @initializer()
25 store i32 %call, i32* @xxx, align 4
29 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__late_ctor, i8* null }, { i32, void ()*, i8* } { i32 0, void ()* @__early_ctor, i8* null }]
31 define internal void @__late_ctor() sanitize_address section ".text.startup" {
33 call void @__cxx_global_var_init()
37 ; Clang indicated that @xxx was dynamically initailized.
38 ; __asan_{before,after}_dynamic_init should be called from __late_ctor
40 ; CHECK-LABEL: define internal void @__late_ctor
42 ; CHECK: call void @__asan_before_dynamic_init
43 ; CHECK: call void @__cxx_global_var_init
44 ; CHECK: call void @__asan_after_dynamic_init
47 ; CTOR with priority 0 should not be instrumented.
48 define internal void @__early_ctor() sanitize_address section ".text.startup" {
50 call void @__cxx_global_var_init()
53 ; CHECK-LABEL: define internal void @__early_ctor
57 ; Check that xxx is instrumented.
58 define void @touch_xxx() sanitize_address {
59 store i32 0, i32 *@xxx, align 4
61 ; CHECK-LABEL: touch_xxx
62 ; CHECK: call void @__asan_report_store4
66 ; Check that XXX is instrumented.
67 define void @touch_XXX() sanitize_address {
68 store i32 0, i32 *@XXX, align 4
70 ; CHECK: define void @touch_XXX
71 ; CHECK: call void @__asan_report_store4
76 ; Check that yyy is NOT instrumented (as it does not have dynamic initializer).
77 define void @touch_yyy() sanitize_address {
78 store i32 0, i32 *@yyy, align 4
80 ; CHECK: define void @touch_yyy
81 ; CHECK-NOT: call void @__asan_report_store4
85 ; Check that YYY is NOT instrumented (as it does not have dynamic initializer).
86 define void @touch_YYY() sanitize_address {
87 store i32 0, i32 *@YYY, align 4
89 ; CHECK: define void @touch_YYY
90 ; CHECK-NOT: call void @__asan_report_store4