]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/unload2.c
Update.
[thirdparty/glibc.git] / elf / unload2.c
1 #include <dlfcn.h>
2 #include <elf.h>
3 #include <errno.h>
4 #include <error.h>
5 #include <link.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #define OUT \
10 for (map = _r_debug.r_map; map != NULL; map = map->l_next) \
11 if (map->l_type == lt_loaded) \
12 printf ("name = \"%s\", opencount = %d\n", \
13 map->l_name, (int) map->l_opencount); \
14 fflush (stdout)
15
16 int
17 main (void)
18 {
19 void *h[3];
20 struct link_map *map;
21 void (*fp) (void);
22
23 h[0] = dlopen ("unload2mod.so", RTLD_LAZY);
24 h[1] = dlopen ("unload2mod.so", RTLD_LAZY);
25 if (h[0] == NULL || h[1] == NULL)
26 error (EXIT_FAILURE, errno, "cannot load \"unload2mod.so\"");
27 h[2] = dlopen ("unload2dep.so", RTLD_LAZY);
28 if (h[2] == NULL)
29 error (EXIT_FAILURE, errno, "cannot load \"unload2dep.so\"");
30
31 puts ("\nAfter loading everything:");
32 OUT;
33
34 dlclose (h[0]);
35
36 puts ("\nAfter unloading \"unload2mod.so\" once:");
37 OUT;
38
39 dlclose (h[1]);
40
41 puts ("\nAfter unloading \"unload2mod.so\" twice:");
42 OUT;
43
44 fp = dlsym (h[2], "foo");
45 puts ("\nnow calling `foo'");
46 fflush (stdout);
47 fp ();
48 puts ("managed to call `foo'");
49 fflush (stdout);
50
51 dlclose (h[2]);
52
53 puts ("\nAfter unloading \"unload2dep.so\":");
54 OUT;
55
56 return 0;
57 }