1; Test that global metadata is placed in a separate section on Mach-O platforms, 2; allowing dead stripping to be performed, and that the appropriate runtime 3; routines are invoked. 4 5; RUN: opt < %s -passes=asan -asan-use-private-alias=0 -asan-globals-live-support=1 -S | FileCheck %s --check-prefixes=CHECK,NOALIAS 6; RUN: opt < %s -passes=asan -asan-use-private-alias=1 -asan-globals-live-support=1 -S | FileCheck %s --check-prefixes=CHECK,ALIAS 7 8target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 9target triple = "x86_64-apple-macosx10.11.0" 10 11@global = global [1 x i32] zeroinitializer, align 4 12 13!llvm.asan.globals = !{!0} 14 15!0 = !{ptr @global, !1, !"global", i1 false, i1 false} 16!1 = !{!"test-globals.c", i32 1, i32 5} 17 18 19; Find the metadata for @global: 20; NOALIAS: [[METADATA:@.+]] = internal global {{.*}} @global {{.*}} section "__DATA,__asan_globals,regular" 21; ALIAS: [[METADATA:@.+]] = internal global {{.*}} @0 {{.*}} section "__DATA,__asan_globals,regular" 22 23; Find the liveness binder for @global and its metadata: 24; NOALIAS: @__asan_binder_global = internal global {{.*}} @global {{.*}} [[METADATA]] {{.*}} section "__DATA,__asan_liveness,regular,live_support" 25; ALIAS: @__asan_binder_global = internal global {{.*}} @0 {{.*}} [[METADATA]] {{.*}} section "__DATA,__asan_liveness,regular,live_support" 26 27; The binder has to be inserted to llvm.compiler.used to avoid being stripped 28; during LTO. 29; CHECK: @llvm.compiler.used = appending global [2 x ptr] [ptr @global, ptr @__asan_binder_global], section "llvm.metadata" 30 31; Test that there is the flag global variable: 32; CHECK: @___asan_globals_registered = common hidden global i64 0 33 34; ALIAS: @0 = private alias {{.*}} @global 35 36; Test that __asan_register_image_globals is invoked from the constructor: 37; CHECK-LABEL: define internal void @asan.module_ctor 38; CHECK-NOT: ret 39; CHECK: call void @__asan_register_image_globals(i64 ptrtoint (ptr @___asan_globals_registered to i64)) 40; CHECK: ret 41 42; Test that __asan_unregister_image_globals is invoked from the destructor: 43; CHECK-LABEL: define internal void @asan.module_dtor 44; CHECK-NOT: ret 45; CHECK: call void @__asan_unregister_image_globals(i64 ptrtoint (ptr @___asan_globals_registered to i64)) 46; CHECK: ret 47