]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/tsan/Linux/check_preinit.cc
1 // RUN: %clang_tsan -fno-sanitize=thread -shared -fPIC -O1 -DBUILD_SO=1 %s -o \
3 // RUN: %clang_tsan -O1 %s %t.so -o %t && %run %t 2>&1 | FileCheck %s
4 // RUN: llvm-objdump -t %t | FileCheck %s --check-prefix=CHECK-DUMP
5 // CHECK-DUMP: {{[.]preinit_array.*__local_tsan_preinit}}
7 // SANITIZER_CAN_USE_PREINIT_ARRAY is undefined on android.
8 // UNSUPPORTED: android
10 // Test checks if __tsan_init is called from .preinit_array.
11 // Without initialization from .preinit_array, __tsan_init will be called from
12 // constructors of the binary which are called after constructors of shared
19 // "volatile" is needed to avoid compiler optimize-out constructors.
20 volatile int counter
= 0;
21 volatile int lib_constructor_call
= 0;
22 volatile int tsan_init_call
= 0;
24 __attribute__ ((constructor
))
25 void LibConstructor() {
26 lib_constructor_call
= ++counter
;
32 extern int lib_constructor_call
;
33 extern int tsan_init_call
;
35 volatile int bin_constructor_call
= 0;
37 __attribute__ ((constructor
))
38 void BinConstructor() {
39 bin_constructor_call
= ++counter
;
45 tsan_init_call
= ++counter
;
52 // CHECK: LIB_CONSTRUCTOR 2
53 // CHECK: BIN_CONSTRUCTOR 3
54 printf("TSAN_INIT %d\n", tsan_init_call
);
55 printf("LIB_CONSTRUCTOR %d\n", lib_constructor_call
);
56 printf("BIN_CONSTRUCTOR %d\n", bin_constructor_call
);