lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> |
| 2 | #include <mcheck.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | |
| 7 | int |
| 8 | main (void) |
| 9 | { |
| 10 | void *p1; |
| 11 | void *p2; |
| 12 | int (*fp) (void); |
| 13 | int result; |
| 14 | |
| 15 | mtrace (); |
| 16 | |
| 17 | p1 = dlopen ("dblloadmod1.so", RTLD_LAZY); |
| 18 | if (p1 == NULL) |
| 19 | { |
| 20 | printf ("cannot load dblloadmod1.so: %s\n", dlerror ()); |
| 21 | exit (EXIT_FAILURE); |
| 22 | } |
| 23 | |
| 24 | p2 = dlopen ("dblloadmod2.so", RTLD_LAZY); |
| 25 | if (p2 == NULL) |
| 26 | { |
| 27 | printf ("cannot load dblloadmod2.so: %s\n", dlerror ()); |
| 28 | exit (EXIT_FAILURE); |
| 29 | } |
| 30 | |
| 31 | if (dlclose (p1) != 0) |
| 32 | { |
| 33 | printf ("error while closing dblloadmod1.so: %s\n", dlerror ()); |
| 34 | exit (EXIT_FAILURE); |
| 35 | } |
| 36 | |
| 37 | fp = dlsym (p2, "xyzzy"); |
| 38 | if (fp == NULL) |
| 39 | { |
| 40 | printf ("cannot get function \"xyzzy\": %s\n", dlerror ()); |
| 41 | exit (EXIT_FAILURE); |
| 42 | } |
| 43 | |
| 44 | result = fp (); |
| 45 | |
| 46 | if (dlclose (p2) != 0) |
| 47 | { |
| 48 | printf ("error while closing dblloadmod2.so: %s\n", dlerror ()); |
| 49 | exit (EXIT_FAILURE); |
| 50 | } |
| 51 | |
| 52 | return result; |
| 53 | } |