1; RUN: opt < %s -passes=asan -S | FileCheck %s 2; RUN: opt < %s -passes=asan -asan-mapping-scale=5 -S | FileCheck %s 3target 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" 4target triple = "x86_64-unknown-linux-gnu" 5@xxx = internal global i32 0, align 4, sanitize_address_dyninit ; With dynamic initializer. 6@XXX = global i32 0, align 4, sanitize_address_dyninit ; 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 10define i32 @initializer() uwtable { 11entry: 12 ret i32 42 13} 14 15define internal void @__cxx_global_var_init() section ".text.startup" { 16entry: 17 %call = call i32 @initializer() 18 store i32 %call, ptr @xxx, align 4 19 ret void 20} 21 22@llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__late_ctor, ptr null }, { i32, ptr, ptr } { i32 0, ptr @__early_ctor, ptr null }] 23 24define internal void @__late_ctor() sanitize_address section ".text.startup" { 25entry: 26 call void @__cxx_global_var_init() 27 ret void 28} 29 30; Clang indicated that @xxx was dynamically initailized. 31; __asan_{before,after}_dynamic_init should be called from __late_ctor 32 33; CHECK-LABEL: define internal void @__late_ctor 34; CHECK-NOT: ret 35; CHECK: call void @__asan_before_dynamic_init 36; CHECK: call void @__cxx_global_var_init 37; CHECK: call void @__asan_after_dynamic_init 38; CHECK: ret 39 40; CTOR with priority 0 should not be instrumented. 41define internal void @__early_ctor() sanitize_address section ".text.startup" { 42entry: 43 call void @__cxx_global_var_init() 44 ret void 45} 46; CHECK-LABEL: define internal void @__early_ctor 47; CHECK-NOT: __asan 48; CHECK: ret 49 50; Check that xxx is instrumented. 51define void @touch_xxx() sanitize_address { 52 store i32 0, ptr @xxx, align 4 53 ret void 54; CHECK-LABEL: touch_xxx 55; CHECK: call void @__asan_report_store4 56; CHECK: ret void 57} 58 59; Check that XXX is instrumented. 60define void @touch_XXX() sanitize_address { 61 store i32 0, ptr @XXX, align 4 62 ret void 63; CHECK: define void @touch_XXX 64; CHECK: call void @__asan_report_store4 65; CHECK: ret void 66} 67 68 69; Check that yyy is NOT instrumented (as it does not have dynamic initializer). 70define void @touch_yyy() sanitize_address { 71 store i32 0, ptr @yyy, align 4 72 ret void 73; CHECK: define void @touch_yyy 74; CHECK-NOT: call void @__asan_report_store4 75; CHECK: ret void 76} 77 78; Check that YYY is NOT instrumented (as it does not have dynamic initializer). 79define void @touch_YYY() sanitize_address { 80 store i32 0, ptr @YYY, align 4 81 ret void 82; CHECK: define void @touch_YYY 83; CHECK-NOT: call void @__asan_report_store4 84; CHECK: ret void 85} 86