1 | #include <dlfcn.h> |
2 | #include <mcheck.h> |
3 | #include <stdio.h> |
4 | #include <stdlib.h> |
5 | |
6 | int |
7 | main (void) |
8 | { |
9 | void *h[2]; |
10 | int fail; |
11 | int (*fp) (void); |
12 | |
13 | mtrace (); |
14 | |
15 | h[0] = dlopen (file: "ltglobmod1.so" , RTLD_LAZY); |
16 | if (h[0] == NULL) |
17 | { |
18 | printf (format: "%s: cannot open %s: %s\n" , |
19 | __FUNCTION__, "ltglobmod1.so" , dlerror ()); |
20 | exit (EXIT_FAILURE); |
21 | } |
22 | h[1] = dlopen (file: "ltglobmod2.so" , RTLD_LAZY); |
23 | if (h[1] == NULL) |
24 | { |
25 | printf (format: "%s: cannot open %s: %s\n" , |
26 | __FUNCTION__, "ltglobmod2.so" , dlerror ()); |
27 | exit (EXIT_FAILURE); |
28 | } |
29 | |
30 | puts (s: "loaded \"ltglobmod1.so\" without RTLD_GLOBAL" ); |
31 | |
32 | fp = dlsym (handle: h[1], name: "foo" ); |
33 | if (fp == NULL) |
34 | { |
35 | printf (format: "cannot get address of `foo': %s\n" , dlerror ()); |
36 | exit (EXIT_FAILURE); |
37 | } |
38 | |
39 | fail = fp (); |
40 | |
41 | puts (s: "back in main" ); |
42 | |
43 | dlclose (handle: h[1]); |
44 | dlclose (handle: h[0]); |
45 | |
46 | return fail; |
47 | } |
48 | |