From 9807e5408bf1d7f879216f0000c1f220beb89d93 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 23 Oct 2000 22:58:40 +0000 Subject: Update. * elf/unload.c: Generate more debugging output. * elf/neededtest.c: Make it more complicated. * elf/neededtest2.c: New file. * elf/Makefile: Add rules to build and run neededtest2. --- elf/neededtest2.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 elf/neededtest2.c (limited to 'elf/neededtest2.c') diff --git a/elf/neededtest2.c b/elf/neededtest2.c new file mode 100644 index 0000000..cf111bc --- /dev/null +++ b/elf/neededtest2.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include + +static int +check_loaded_objects (const char **loaded) +{ + struct link_map *lm; + int n; + int *found = NULL; + int errors = 0; + + for (n = 0; loaded[n]; n++) + /* NOTHING */; + + if (n) + { + found = (int *) alloca (sizeof (int) * n); + memset (found, 0, sizeof (int) * n); + } + + printf(" Name\n"); + printf(" --------------------------------------------------------\n"); + for (lm = _r_debug.r_map; lm; lm = lm->l_next) + { + if (lm->l_name && lm->l_name[0]) + printf(" %s, count = %d\n", lm->l_name, (int) lm->l_opencount); + if (lm->l_type == lt_loaded && lm->l_name) + { + int match = 0; + for (n = 0; loaded[n] != NULL; n++) + { + if (strcmp (basename (loaded[n]), basename (lm->l_name)) == 0) + { + found[n] = 1; + match = 1; + break; + } + } + + if (match == 0) + { + ++errors; + printf ("ERRORS: %s is not unloaded\n", lm->l_name); + } + } + } + + for (n = 0; loaded[n] != NULL; n++) + { + if (found[n] == 0) + { + ++errors; + printf ("ERRORS: %s is not loaded\n", loaded[n]); + } + } + + return errors; +} + +int +main (void) +{ + void *obj2; + void *obj3[2]; + const char *loaded[] = { NULL, NULL, NULL, NULL }; + int errors = 0; + + printf ("\nThis is what is in memory now:\n"); + errors += check_loaded_objects (loaded); + printf ("\nLoading shared object neededobj2.so\n"); + obj2 = dlopen ("neededobj2.so", RTLD_LAZY); + if (obj2 == NULL) + { + printf ("%s\n", dlerror ()); + exit (1); + } + loaded[0] = "neededobj1.so"; + loaded[1] = "neededobj2.so"; + errors += check_loaded_objects (loaded); + printf ("\nLoading shared object neededobj3.so\n"); + obj3[0] = dlopen( "neededobj3.so", RTLD_LAZY); + if (obj3[0] == NULL) + { + printf ("%s\n", dlerror ()); + exit (1); + } + loaded[2] = "neededobj3.so"; + errors += check_loaded_objects (loaded); + printf ("\nNow loading shared object neededobj3.so again\n"); + obj3[1] = dlopen ("neededobj3.so", RTLD_LAZY); + if (obj3[1] == NULL) + { + printf ("%s\n", dlerror ()); + exit (1); + } + errors += check_loaded_objects (loaded); + printf ("\nClosing neededobj3.so once\n"); + dlclose (obj3[0]); + errors += check_loaded_objects (loaded); + printf ("\nClosing neededobj2.so\n"); + dlclose (obj2); + errors += check_loaded_objects (loaded); + printf ("\nClosing neededobj3.so for the second time\n"); + dlclose (obj3[1]); + loaded[0] = NULL; + loaded[1] = NULL; + loaded[2] = NULL; + errors += check_loaded_objects (loaded); + if (errors != 0) + printf ("%d errors found\n", errors); + return errors; +} -- cgit v1.1