mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-30 00:31:08 +00:00
d78efd9f36
* elf/Makefile (tests): Add it. ($(objpfx)tst-tls-dlinfo): Depend on $(libdl). ($(objpfx)tst-tls-dlinfo.out): Depend on $(objpfx)tst-tlsmod2.so. * dlfcn/dlfcn.h (RTLD_DI_PROFILENAME, RTLD_DI_PROFILEOUT): New enum values, reserve unsupported requested names used on Solaris. (RTLD_DI_TLS_MODID, RTLD_DI_TLS_DATA): New enum values. (RTLD_DI_MAX): Likewise. * dlfcn/dlinfo.c (dlinfo_doit): Handle RTLD_DI_TLS_MODID and RTLD_DI_TLS_DATA. * elf/dl-tls.c (_dl_tls_get_addr_soft): New function. * sysdeps/generic/ldsodefs.h: Declare it. * elf/Versions (ld: GLIBC_PRIVATE): Add it. * elf/link.h (struct dl_phdr_info): New members dlpi_tls_modid, dlpi_tls_data. * elf/dl-iteratephdr.c (__dl_iterate_phdr): Fill them in. * include/link.h: Don't copy contents from elf/link.h. Instead, #include it while #define'ing around link_map. * elf/dl-debug.c (_dl_debug_initialize): Add a cast. Add bogus extern decl to verify link_map members. * elf/loadtest.c (MAPS): New macro, cast _r_debug._r_map. (OUT, main): Use it in place of _r_debug._r_map. * elf/unload.c: Likewise. * elf/unload2.c: Likewise. * elf/neededtest.c (check_loaded_objects): Likewise. * elf/neededtest2.c (check_loaded_objects): Likewise. * elf/neededtest3.c (check_loaded_objects): Likewise. * elf/neededtest4.c (check_loaded_objects): Likewise. * elf/circleload1.c (check_loaded_objects): Likewise.
130 lines
2.7 KiB
C
130 lines
2.7 KiB
C
#include <dlfcn.h>
|
|
#include <libintl.h>
|
|
#include <link.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAPS ((struct link_map *) _r_debug.r_map)
|
|
|
|
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 = MAPS; lm; lm = lm->l_next)
|
|
{
|
|
if (lm->l_name && lm->l_name[0])
|
|
printf(" %s, count = %d\n", lm->l_name, (int) lm->l_direct_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;
|
|
void *obj4;
|
|
const char *loaded[] = { NULL, NULL, NULL, NULL, NULL };
|
|
int errors = 0;
|
|
|
|
printf ("\nThis is what is in memory now:\n");
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Now loading 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( "Loading shared object neededobj3.so\n");
|
|
obj3 = dlopen( "neededobj3.so", RTLD_LAZY);
|
|
if (obj3 == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
loaded[2] = "neededobj3.so";
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
|
|
printf( "Loading shared object neededobj4.so\n");
|
|
obj4 = dlopen( "neededobj4.so", RTLD_LAZY);
|
|
if (obj4 == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
loaded[3] = "neededobj4.so";
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Closing neededobj2.so\n");
|
|
dlclose (obj2);
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Closing neededobj3.so\n");
|
|
dlclose (obj3);
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Closing neededobj4.so\n");
|
|
dlclose (obj4);
|
|
loaded[0] = NULL;
|
|
loaded[1] = NULL;
|
|
loaded[2] = NULL;
|
|
loaded[3] = NULL;
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
if (errors != 0)
|
|
printf ("%d errors found\n", errors);
|
|
return errors;
|
|
}
|