mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 13:30:06 +00:00
20fe49b93a
Change type of l_idx to int. * elf/dl-close.c: Basically rewrite. Do not use l_opencount to determine whether a DSO has to be unloaded. Instead compute this in this function. * elf/dl-deps.c: No need to manipulate l_opencount anymore. * elf/dl-lookup.c: Likewise. * elf/rtld.c: Likewise * elf/dl-open.c: Likewise. Use l_init_called to determine whether object was just loaded. * elf/dl-fini.c: Bump l_direct_opencount instead of l_opencount. * elf/dl-load.c (_dl_map_object_from_fd): Do not recognize DSO which is about to be unloaded as a match. (_dl_map_object): Likewise. * elf/do-lookup.h (do_lookup_x): Do not look into DSO which is about to be unloaded. * elf/circleload1.c: Don't use l_opencount anymore. * elf/neededtest.c: Likewise. * elf/neededtest2.c: Likewise. * elf/neededtest3.c: Likewise. * elf/neededtest4.c: Likewise. * elf/unload.c: Likewise. * elf/unload2.c: Likewise. * elf/loadtest.c: Likewise. * elf/rtld.c: Preloading errors are now never fatal. 2005-03-08 Jakub Jelinek <jakub@redhat.com> * elf/Makefile: Add rules to build and run unload5 test. * elf/unload5.c: New file. 2005-03-08 Jakub Jelinek <jakub@redhat.com> * elf/Makefile: Add rules to build and run unload4 test. * elf/unload4.c: New file. * elf/unload4mod1.c: New file. * elf/unload4mod2.c: New file. * elf/unload4mod3.c: New file. * elf/unload4mod4.c: New file.
157 lines
3.3 KiB
C
157 lines
3.3 KiB
C
#include <dlfcn.h>
|
|
#include <libintl.h>
|
|
#include <link.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
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_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;
|
|
}
|
|
|
|
extern void c_function (void);
|
|
extern char *dirname (__const char *__filename);
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
void *obj;
|
|
const char *loaded[] = { NULL, NULL, NULL};
|
|
int errors = 0;
|
|
void (*f) (void);
|
|
const char *dir = dirname (argv [0]);
|
|
char *oldfilename;
|
|
char *newfilename;
|
|
|
|
c_function ();
|
|
|
|
printf ("\nThis is what is in memory now:\n");
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf( "Loading shared object neededobj6.so\n");
|
|
obj = dlopen( "neededobj6.so", RTLD_LAZY);
|
|
if (obj == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
f = dlsym (obj, "a2_function");
|
|
if (f == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
f ();
|
|
loaded[0] = "neededobj5.so";
|
|
loaded[1] = "neededobj6.so";
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Closing neededobj6.so\n");
|
|
dlclose (obj);
|
|
loaded[0] = NULL;
|
|
errors += check_loaded_objects (loaded);
|
|
|
|
printf ("Rename neededobj5.so\n");
|
|
oldfilename = alloca (strlen (dir) + 1 + sizeof ("neededobj5.so"));
|
|
strcpy (oldfilename, dir);
|
|
strcat (oldfilename, "/");
|
|
strcat (oldfilename, "neededobj5.so");
|
|
newfilename = alloca (strlen (oldfilename) + sizeof (".renamed"));
|
|
strcpy (newfilename, oldfilename);
|
|
strcat (newfilename, ".renamed");
|
|
if (rename (oldfilename, newfilename))
|
|
{
|
|
perror ("rename");
|
|
exit (1);
|
|
}
|
|
|
|
printf( "Loading shared object neededobj6.so\n");
|
|
obj = dlopen( "neededobj6.so", RTLD_LAZY);
|
|
if (obj == NULL)
|
|
printf ("%s\n", dlerror ());
|
|
else
|
|
{
|
|
printf ("neededobj6.so should fail to load\n");
|
|
exit (1);
|
|
}
|
|
|
|
printf( "Loading shared object neededobj1.so\n");
|
|
obj = dlopen( "neededobj1.so", RTLD_LAZY);
|
|
if (obj == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
errors += check_loaded_objects (loaded);
|
|
f = dlsym (obj, "c_function");
|
|
if (f == NULL)
|
|
{
|
|
printf ("%s\n", dlerror ());
|
|
exit (1);
|
|
}
|
|
f ();
|
|
|
|
printf ("Restore neededobj5.so\n");
|
|
if (rename (newfilename, oldfilename))
|
|
{
|
|
perror ("rename");
|
|
exit (1);
|
|
}
|
|
|
|
if (errors != 0)
|
|
printf ("%d errors found\n", errors);
|
|
return errors;
|
|
}
|