]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/profile/Inputs/instrprof-dlopen-main.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / profile / Inputs / instrprof-dlopen-main.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #ifdef DLOPEN_FUNC_DIR
6 #include <dlfcn.h>
7 #else
8 void func(int K);
9 void func2(int K);
10 #endif
11
12 int main(int argc, char *argv[]) {
13 #ifdef DLOPEN_FUNC_DIR
14   dlerror();
15   void *f1_handle = dlopen(DLOPEN_FUNC_DIR"/func.shared", DLOPEN_FLAGS);
16   if (f1_handle == NULL) {
17     fprintf(stderr, "unable to open '" DLOPEN_FUNC_DIR "/func.shared': %s\n",
18             dlerror());
19     return EXIT_FAILURE;
20   }
21
22   void (*func)(int) = (void (*)(int))dlsym(f1_handle, "func");
23   if (func == NULL) {
24     fprintf(stderr, "unable to lookup symbol 'func': %s\n", dlerror());
25     return EXIT_FAILURE;
26   }
27
28   void *f2_handle = dlopen(DLOPEN_FUNC_DIR"/func2.shared", DLOPEN_FLAGS);
29   if (f2_handle == NULL) {
30     fprintf(stderr, "unable to open '" DLOPEN_FUNC_DIR "/func2.shared': %s\n",
31             dlerror());
32     return EXIT_FAILURE;
33   }
34
35   void (*func2)(int) = (void (*)(int))dlsym(f2_handle, "func2");
36   if (func2 == NULL) {
37     fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
38     return EXIT_FAILURE;
39   }
40 #endif
41
42   func(1);
43   func2(0);
44
45   return EXIT_SUCCESS;
46 }
47