1 | // RUN: %clang_tsan -O1 %s -DBUILD_LIB=1 -fno-sanitize=thread -shared -fPIC -o %dynamiclib %ld_flags_rpath_so |
2 | // RUN: %clang_tsan -O1 %s -o %t %ld_flags_rpath_exe |
3 | // RUN: %run %t | FileCheck %s |
4 | |
5 | // Test that initialization/finalization hooks are called, even when they are |
6 | // not defined in the main executable, but by another another library that |
7 | // doesn't directly link against the TSan runtime. |
8 | |
9 | #include <stdio.h> |
10 | |
11 | #if BUILD_LIB |
12 | |
13 | extern "C" void __tsan_on_initialize() { |
14 | printf("__tsan_on_initialize()\n" ); |
15 | } |
16 | |
17 | extern "C" int __tsan_on_finalize(int failed) { |
18 | printf("__tsan_on_finalize()\n" ); |
19 | return failed; |
20 | } |
21 | |
22 | #else // BUILD_LIB |
23 | |
24 | int main() { |
25 | printf(format: "main()\n" ); |
26 | return 0; |
27 | } |
28 | |
29 | #endif // BUILD_LIB |
30 | |
31 | // CHECK: __tsan_on_initialize() |
32 | // CHECK: main() |
33 | // CHECK: __tsan_on_finalize() |
34 | |