Fix powerpc abilist sort order
[glibc.git] / elf / unload2.c
blobeef2bfd42688f1572658c89918e8c62b46d12d81
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>
9 #define MAPS ((struct link_map *) _r_debug.r_map)
11 #define OUT \
12 for (map = MAPS; map != NULL; map = map->l_next) \
13 if (map->l_type == lt_loaded) \
14 printf ("name = \"%s\", direct_opencount = %d\n", \
15 map->l_name, (int) map->l_direct_opencount); \
16 fflush (stdout)
18 int
19 main (void)
21 void *h[3];
22 struct link_map *map;
23 void (*fp) (void);
25 h[0] = dlopen ("unload2mod.so", RTLD_LAZY);
26 h[1] = dlopen ("unload2mod.so", RTLD_LAZY);
27 if (h[0] == NULL || h[1] == NULL)
28 error (EXIT_FAILURE, errno, "cannot load \"unload2mod.so\"");
29 h[2] = dlopen ("unload2dep.so", RTLD_LAZY);
30 if (h[2] == NULL)
31 error (EXIT_FAILURE, errno, "cannot load \"unload2dep.so\"");
33 puts ("\nAfter loading everything:");
34 OUT;
36 dlclose (h[0]);
38 puts ("\nAfter unloading \"unload2mod.so\" once:");
39 OUT;
41 dlclose (h[1]);
43 puts ("\nAfter unloading \"unload2mod.so\" twice:");
44 OUT;
46 fp = dlsym (h[2], "foo");
47 puts ("\nnow calling `foo'");
48 fflush (stdout);
49 fp ();
50 puts ("managed to call `foo'");
51 fflush (stdout);
53 dlclose (h[2]);
55 puts ("\nAfter unloading \"unload2dep.so\":");
56 OUT;
58 return 0;