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