1// RUN: rm -rf %t-dir
2// RUN: mkdir %t-dir
3
4// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -shared -o %t-dir/libignore_lib4.so
5// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
6// RUN: echo "called_from_lib:libignore_lib4.so" > %t-dir/executable.supp
7// RUN: %env_tsan_opts=suppressions='%t-dir/executable.supp' %run %t-dir/executable 2>&1 | FileCheck %s
8
9// powerpc64 big endian bots failed with "FileCheck error: '-' is empty" due
10// to a segmentation fault.
11// UNSUPPORTED: target=powerpc64-unknown-linux-gnu{{.*}}
12// aarch64 bots failed with "called_from_lib suppression 'libignore_lib4.so'
13// is matched against 2 libraries".
14// UNSUPPORTED: target=aarch64{{.*}}
15
16// Test longjmp in ignored lib.
17// It used to crash since we jumped out of ScopedInterceptor scope.
18
19#include "test.h"
20#include <setjmp.h>
21#include <string.h>
22#include <errno.h>
23#include <libgen.h>
24#include <string>
25
26#ifdef LIB
27
28extern "C" void myfunc() {
29 for (int i = 0; i < (1 << 20); i++) {
30 jmp_buf env;
31 if (!setjmp(env))
32 longjmp(env, 1);
33 }
34}
35
36#else
37
38int main(int argc, char **argv) {
39 std::string lib = std::string(dirname(argv[0])) + "/libignore_lib4.so";
40 void *h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);
41 void (*func)() = (void(*)())dlsym(handle: h, name: "myfunc");
42 func();
43 fprintf(stderr, format: "DONE\n");
44 return 0;
45}
46
47#endif
48
49// CHECK: DONE
50

source code of compiler-rt/test/tsan/ignore_lib4.cpp