1
2#include <stdio.h>
3#include <stdlib.h>
4
5#ifdef DLOPEN_FUNC_DIR
6#include <dlfcn.h>
7#else
8void func(int K);
9void func2(int K);
10#endif
11
12int 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(K: 1);
43 func2(K: 0);
44
45 return EXIT_SUCCESS;
46}
47
48

source code of compiler-rt/test/profile/Inputs/instrprof-dlopen-main.c