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