1 | #include <dlfcn.h> |
2 | #include <stdio.h> |
3 | |
4 | int |
5 | main (void) |
6 | { |
7 | void *g = dlopen (file: "unload3mod1.so" , RTLD_GLOBAL | RTLD_NOW); |
8 | void *h = dlopen (file: "unload3mod2.so" , RTLD_GLOBAL | RTLD_NOW); |
9 | if (g == NULL || h == NULL) |
10 | { |
11 | printf (format: "dlopen unload3mod{1,2}.so failed: %p %p\n" , g, h); |
12 | return 1; |
13 | } |
14 | dlclose (handle: h); |
15 | dlclose (handle: g); |
16 | |
17 | g = dlopen (file: "unload3mod3.so" , RTLD_GLOBAL | RTLD_NOW); |
18 | h = dlopen (file: "unload3mod4.so" , RTLD_GLOBAL | RTLD_NOW); |
19 | if (g == NULL || h == NULL) |
20 | { |
21 | printf (format: "dlopen unload3mod{3,4}.so failed: %p %p\n" , g, h); |
22 | return 1; |
23 | } |
24 | |
25 | int (*fn) (int); |
26 | fn = dlsym (handle: h, name: "bar" ); |
27 | if (fn == NULL) |
28 | { |
29 | puts (s: "dlsym failed" ); |
30 | return 1; |
31 | } |
32 | |
33 | int val = fn (16); |
34 | if (val != 24) |
35 | { |
36 | printf (format: "bar returned %d != 24\n" , val); |
37 | return 1; |
38 | } |
39 | |
40 | return 0; |
41 | } |
42 | |