1 | #include <dlfcn.h> |
2 | #include <errno.h> |
3 | #include <error.h> |
4 | #include <mcheck.h> |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | |
8 | int |
9 | main (void) |
10 | { |
11 | int (*foo) (void); |
12 | void *h; |
13 | int ret; |
14 | |
15 | mtrace (); |
16 | |
17 | h = dlopen (file: "constload2.so" , RTLD_LAZY | RTLD_GLOBAL); |
18 | if (h == NULL) |
19 | error (EXIT_FAILURE, errno, format: "cannot load module \"constload2.so\"" ); |
20 | foo = dlsym (handle: h, name: "foo" ); |
21 | ret = foo (); |
22 | /* Note that the following dlclose() call cannot unload the objects. |
23 | Due to the introduced relocation dependency constload2.so depends |
24 | on constload3.so and the dependencies of constload2.so on constload3.so |
25 | is not visible to ld.so since it's done using dlopen(). */ |
26 | if (dlclose (handle: h) != 0) |
27 | { |
28 | puts (s: "failed to close" ); |
29 | exit (EXIT_FAILURE); |
30 | } |
31 | return ret; |
32 | } |
33 | |