lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <dlfcn.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | extern int bar (void); |
| 6 | extern int foo (void); |
| 7 | |
| 8 | int |
| 9 | foo (void) |
| 10 | { |
| 11 | void *h; |
| 12 | int res; |
| 13 | |
| 14 | /* Load ltglobalmod1 in the global namespace. */ |
| 15 | h = dlopen ("ltglobmod1.so", RTLD_GLOBAL | RTLD_LAZY); |
| 16 | if (h == NULL) |
| 17 | { |
| 18 | printf ("%s: cannot open %s: %s", |
| 19 | __FUNCTION__, "ltglobmod1.so", dlerror ()); |
| 20 | exit (EXIT_FAILURE); |
| 21 | } |
| 22 | |
| 23 | /* Call bar. This is undefined in the DSO. */ |
| 24 | puts ("about to call `bar'"); |
| 25 | fflush (stdout); |
| 26 | res = bar (); |
| 27 | |
| 28 | printf ("bar returned %d\n", res); |
| 29 | |
| 30 | dlclose (h); |
| 31 | |
| 32 | return res != 42; |
| 33 | } |