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