1 RUN: rm -rf %t && split-file %s %t && cd %t
2 RUN: %clang foo.c -c --coverage
3 RUN: %clang foo2.c -c --coverage
4 RUN: %clang -shared foo.o -o shr.o --coverage
5 RUN: ar -X32_64 r libfoo.a shr.o
6 RUN: %clang -shared foo2.o -o shr.o --coverage
7 RUN: ar -X32_64 r libfoo2.a shr.o
9 RUN: %clang common.c -c --coverage
11 RUN: %clang test1.c common.o --coverage
24 typedef void (*FN_PTR)();
25 int open_close_libs() {
26 void *handle, *handle2;
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); \
33 fprintf(stderr, "unable to lookup symbol '%s': %s\n", #SUF, dlerror()); \
34 return EXIT_FAILURE; \
38 #define CLOSE_AND_CHECK(HANDLE, SUF) \
40 system("ls " #SUF ".gc*");
42 OPEN_AND_RUN(handle, foo)
43 CLOSE_AND_CHECK(handle, foo)
45 OPEN_AND_RUN(handle2, foo2)
46 OPEN_AND_RUN(handle, foo)
47 CLOSE_AND_CHECK(handle2, foo2)
48 CLOSE_AND_CHECK(handle, foo)
52 int open_close_libs();