brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 72f1118 Raw
89 lines · c
1/// atexit(3) not supported in dlopen(3)ed+dlclose(3)d DSO2// XFAIL: target={{.*netbsd.*}}3// XFAIL: target={{.*haiku.*}}4 5// RUN: mkdir -p %t.d && cd %t.d6 7// RUN: echo 'void func1(int k) {}' > func1.c8// RUN: echo 'void func2(int k) {}' > func2.c9// RUN: echo 'void func3(int k) {}' > func3.c10// RUN: %clang --coverage -fPIC -shared func1.c -o func1.so -dumpdir ./11// RUN: %clang --coverage -fPIC -shared func2.c -o func2.so -dumpdir ./12// RUN: %clang --coverage -fPIC -shared func3.c -o func3.so -dumpdir ./13// RUN: %clang --coverage -fPIC -rpath %t.d %s -o %t -dumpdir ./14 15/// Test with two dlopened libraries.16// RUN: rm -f gcov-dlopen.gcda func1.gcda func2.gcda17// RUN: %run %t18// RUN: llvm-cov gcov -t gcov-dlopen.gcda | FileCheck %s19// RUN: llvm-cov gcov -t func1.gcda | FileCheck %s --check-prefix=FUNC120// RUN: llvm-cov gcov -t func2.gcda | FileCheck %s --check-prefix=FUNC221 22// FUNC1:     1:    1:void func1(int k) {}23// FUNC2:     1:    1:void func2(int k) {}24 25/// Test with three dlopened libraries.26// RUN: %clang -DUSE_LIB3 --coverage -fPIC -rpath %t.d %s -o %t -dumpdir ./27// RUN: rm -f gcov-dlopen.gcda func1.gcda func2.gcda func3.gcda28// RUN: %run %t29// RUN: llvm-cov gcov -t gcov-dlopen.gcda | FileCheck %s --check-prefix=LIB330// RUN: llvm-cov gcov -t func1.gcda | FileCheck %s --check-prefix=FUNC131// RUN: llvm-cov gcov -t func2.gcda | FileCheck %s --check-prefix=FUNC232// RUN: llvm-cov gcov -t func3.gcda | FileCheck %s --check-prefix=FUNC333 34// FUNC3:     1:    1:void func3(int k) {}35 36#include <dlfcn.h>37#include <stdio.h>38#include <stdlib.h>39 40int main(int argc, char *argv[]) {41  void *f1_handle = dlopen("func1.so", RTLD_LAZY | RTLD_GLOBAL);42  if (f1_handle == NULL)43    return fprintf(stderr, "unable to open 'func1.so': %s\n", dlerror());44  void (*func1)(void) = (void (*)(void))dlsym(f1_handle, "func1");45  if (func1 == NULL)46    return fprintf(stderr, "unable to lookup symbol 'func1': %s\n", dlerror());47 48  void *f2_handle = dlopen("func2.so", RTLD_LAZY | RTLD_GLOBAL);49  if (f2_handle == NULL)50    return fprintf(stderr, "unable to open 'func2.so': %s\n", dlerror());51  void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");52  if (func2 == NULL)53    return fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());54  func2();55 56#ifdef USE_LIB357// CHECK:          -: [[#@LINE+2]]:  void *f3_handle58// LIB3:           1: [[#@LINE+1]]:  void *f3_handle59  void *f3_handle = dlopen("func3.so", RTLD_LAZY | RTLD_GLOBAL);60  if (f3_handle == NULL)61    return fprintf(stderr, "unable to open 'func3.so': %s\n", dlerror());62  void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");63  if (func3 == NULL)64    return fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());65  func3();66#endif67 68  void (*gcov_reset1)() = (void (*)())dlsym(f1_handle, "__gcov_reset");69  if (gcov_reset1 == NULL)70    return fprintf(stderr, "unable to find __gcov_reset in func1.so': %s\n", dlerror());71  void (*gcov_reset2)() = (void (*)())dlsym(f2_handle, "__gcov_reset");72  if (gcov_reset2 == NULL)73    return fprintf(stderr, "unable to find __gcov_reset in func2.so': %s\n", dlerror());74  if (gcov_reset1 == gcov_reset2)75    return fprintf(stderr, "same __gcov_reset found in func1.so and func2.so\n");76 77  /// Test that __gcov_dump is in the dynamic symbol table.78  void (*gcov_dump1)() = (void (*)())dlsym(f1_handle, "__gcov_dump");79  if (gcov_dump1 == NULL)80    return fprintf(stderr, "unable to find __gcov_dump in func1.so': %s\n", dlerror());81 82  if (dlclose(f2_handle) != 0)83    return fprintf(stderr, "unable to close 'func2.so': %s\n", dlerror());84 85  func1();86 87  return 0;88}89