52 lines · cpp
1// RUN: rm -rf %t-dir2// RUN: mkdir %t-dir3 4// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib3.so5// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable6// RUN: %env_tsan_opts=suppressions='%s.supp':verbosity=1 %run %t-dir/executable 2>&1 | FileCheck %s7 8// Tests that unloading of a library matched against called_from_lib suppression9// is supported.10 11// Some aarch64 kernels do not support non executable write pages12// REQUIRES: stable-runtime13 14#ifndef LIB15 16#include <dlfcn.h>17#include <stdlib.h>18#include <stdio.h>19#include <errno.h>20#include <libgen.h>21#include <string>22 23int main(int argc, char **argv) {24 std::string lib = std::string(dirname(argv[0])) + "/libignore_lib3.so";25 void *h;26 void (*f)();27 // Try opening, closing and reopening the ignored lib.28 for (unsigned int k = 0; k < 2; k++) {29 h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);30 if (h == 0)31 exit(printf("failed to load the library (%d)\n", errno));32 f = (void (*)())dlsym(h, "libfunc");33 if (f == 0)34 exit(printf("failed to find the func (%d)\n", errno));35 f();36 dlclose(h);37 }38 fprintf(stderr, "OK\n");39}40 41#else // #ifdef LIB42 43# include "ignore_lib_lib.h"44 45#endif // #ifdef LIB46 47// CHECK: Matched called_from_lib suppression 'ignore_lib3.so'48// CHECK: library '{{.*}}ignore_lib3.so' that was matched against called_from_lib suppression 'ignore_lib3.so' is unloaded49// CHECK: Matched called_from_lib suppression 'ignore_lib3.so'50// CHECK: library '{{.*}}ignore_lib3.so' that was matched against called_from_lib suppression 'ignore_lib3.so' is unloaded51// CHECK: OK52