brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 21a56bd Raw
56 lines · plain
1RUN: rm -rf %t && split-file %s %t && cd %t2RUN: %clang foo.c -c --coverage3RUN: %clang foo2.c -c --coverage4RUN: %clang -shared foo.o -o shr.o --coverage5RUN: ar -X32_64 r libfoo.a shr.o6RUN: %clang -shared foo2.o -o shr.o --coverage7RUN: ar -X32_64 r libfoo2.a shr.o8 9RUN: %clang common.c -c --coverage10 11RUN: %clang test1.c common.o  --coverage12RUN: ./a.out13 14//--- foo.c15void foo() {}16 17//--- foo2.c18void foo2() {}19 20//--- common.c21#include <dlfcn.h>22#include <stdio.h>23#include <stdlib.h>24typedef void (*FN_PTR)();25int open_close_libs() {26  void *handle, *handle2;27  FN_PTR foo, foo2;28 29#define OPEN_AND_RUN(HANDLE, SUF)                                            \30  HANDLE = dlopen("./lib" #SUF ".a(shr.o)",RTLD_NOW|RTLD_MEMBER);            \31  SUF = (void (*)())dlsym(HANDLE, #SUF);                                     \32  if (SUF == NULL) {                                                         \33    fprintf(stderr, "unable to lookup symbol '%s': %s\n", #SUF, dlerror());  \34    return EXIT_FAILURE;                                                     \35  }                                                                          \36  SUF();37 38#define CLOSE_AND_CHECK(HANDLE, SUF)                                         \39  dlclose(HANDLE);                                                           \40  system("ls " #SUF ".gc*");41 42  OPEN_AND_RUN(handle, foo)43  CLOSE_AND_CHECK(handle, foo)44 45  OPEN_AND_RUN(handle2, foo2)46  OPEN_AND_RUN(handle, foo)47  CLOSE_AND_CHECK(handle2, foo2)48  CLOSE_AND_CHECK(handle, foo)49  return EXIT_SUCCESS;50}51//--- test1.c52int open_close_libs();53int main() {54  open_close_libs();55}56