mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 15:20:10 +00:00
752a2a50d4
2000-08-19 Ulrich Drepper <drepper@redhat.com> * elf/Versions [ld] (GLIBC_2.2): Export _dl_check_map_versions. * elf/dl-deps.c (_dl_map_object_deps): If object was dependency of a dynamically loaded object remove old l_initfini list. * elf/dl-libc.c (free_mem): Used as __libc_subfreeres callback to remove some dynamically allocated memory blocks in the dynamic loading data structures. * elf/dl-load.c (add_name_to_object): Initialize dont_free to 0. * elf/dl-open.c (dl_open_workder): Don't call _dl_check_all_versions. Instead call _dl_check_map_versions only for the dependencies. * elf/rtld.c: Avoid unneccessary initializations. Mark l_libname information of initial objects as not free-able. * sysdeps/generic/ldsodefs.h (struct libname_list): Add dont_free element. * elf/filter.c: Call mtrace. * elf/restest1.c: Likewise. Close the objects. * elf/loadtest.c: Call mtrace. Check result of dlclose. Print more debug information. * elf/constload1.c: Add comment explaining not freed memory.
152 lines
3.5 KiB
C
152 lines
3.5 KiB
C
#include <assert.h>
|
|
#include <dlfcn.h>
|
|
#include <errno.h>
|
|
#include <error.h>
|
|
#include <mcheck.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
/* How many load/unload operations do we do. */
|
|
#define TEST_ROUNDS 1000
|
|
|
|
|
|
static struct
|
|
{
|
|
/* Name of the module. */
|
|
const char *name;
|
|
/* The handle. */
|
|
void *handle;
|
|
} testobjs[] =
|
|
{
|
|
{ "testobj1.so", NULL },
|
|
{ "testobj2.so", NULL },
|
|
{ "testobj3.so", NULL },
|
|
{ "testobj4.so", NULL },
|
|
{ "testobj5.so", NULL },
|
|
{ "testobj6.so", NULL },
|
|
};
|
|
#define NOBJS (sizeof (testobjs) / sizeof (testobjs[0]))
|
|
|
|
|
|
static const struct
|
|
{
|
|
/* Name of a function to call. */
|
|
const char *fname;
|
|
/* Index in status and handle array. */
|
|
int index;
|
|
/* Options while loading the module. */
|
|
int options;
|
|
} tests[] =
|
|
{
|
|
{ "obj1func2", 0, RTLD_LAZY },
|
|
{ "obj1func1", 0, RTLD_LAZY | RTLD_GLOBAL },
|
|
{ "obj1func1", 0, RTLD_NOW, },
|
|
{ "obj1func2", 0, RTLD_NOW | RTLD_GLOBAL },
|
|
{ "obj2func2", 1, RTLD_LAZY },
|
|
{ "obj2func1", 1, RTLD_LAZY | RTLD_GLOBAL, },
|
|
{ "obj2func1", 1, RTLD_NOW, },
|
|
{ "obj2func2", 1, RTLD_NOW | RTLD_GLOBAL },
|
|
{ "obj3func2", 2, RTLD_LAZY },
|
|
{ "obj3func1", 2, RTLD_LAZY | RTLD_GLOBAL },
|
|
{ "obj3func1", 2, RTLD_NOW },
|
|
{ "obj3func2", 2, RTLD_NOW | RTLD_GLOBAL },
|
|
{ "obj4func2", 3, RTLD_LAZY },
|
|
{ "obj4func1", 3, RTLD_LAZY | RTLD_GLOBAL },
|
|
{ "obj4func1", 3, RTLD_NOW },
|
|
{ "obj4func2", 3, RTLD_NOW | RTLD_GLOBAL },
|
|
{ "obj5func2", 4, RTLD_LAZY },
|
|
{ "obj5func1", 4, RTLD_LAZY | RTLD_GLOBAL },
|
|
{ "obj5func1", 4, RTLD_NOW },
|
|
{ "obj5func2", 4, RTLD_NOW | RTLD_GLOBAL },
|
|
{ "obj6func2", 5, RTLD_LAZY },
|
|
{ "obj6func1", 5, RTLD_LAZY | RTLD_GLOBAL },
|
|
{ "obj6func1", 5, RTLD_NOW },
|
|
{ "obj6func2", 5, RTLD_NOW | RTLD_GLOBAL },
|
|
};
|
|
#define NTESTS (sizeof (tests) / sizeof (tests[0]))
|
|
|
|
|
|
#include <include/link.h>
|
|
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
int count = TEST_ROUNDS;
|
|
int result = 0;
|
|
|
|
mtrace ();
|
|
|
|
/* Just a seed. */
|
|
srandom (TEST_ROUNDS);
|
|
|
|
while (count--)
|
|
{
|
|
int nr = random () % NTESTS;
|
|
int index = tests[nr].index;
|
|
|
|
printf ("%4d: %4d: ", count + 1, nr);
|
|
fflush (stdout);
|
|
|
|
if (testobjs[index].handle == NULL)
|
|
{
|
|
int (*fct) (int);
|
|
|
|
/* Load the object. */
|
|
testobjs[index].handle = dlopen (testobjs[index].name,
|
|
tests[nr].options);
|
|
if (testobjs[index].handle == NULL)
|
|
error (EXIT_FAILURE, 0, "cannot load `%s': %s",
|
|
testobjs[index].name, dlerror ());
|
|
|
|
/* Test the function call. */
|
|
fct = dlsym (testobjs[index].handle, tests[nr].fname);
|
|
if (fct == NULL)
|
|
error (EXIT_FAILURE, 0,
|
|
"cannot get function `%s' from shared object `%s': %s",
|
|
tests[nr].fname, testobjs[index].name, dlerror ());
|
|
|
|
fct (10);
|
|
|
|
printf ("successfully loaded `%s', handle %p\n",
|
|
testobjs[index].name, testobjs[index].handle);
|
|
}
|
|
else
|
|
{
|
|
if (dlclose (testobjs[index].handle) != 0)
|
|
{
|
|
printf ("failed to close %s\n", testobjs[index].name);
|
|
result = 1;
|
|
}
|
|
else
|
|
printf ("successfully unloaded `%s', handle %p\n",
|
|
testobjs[index].name, testobjs[index].handle);
|
|
|
|
testobjs[index].handle = NULL;
|
|
}
|
|
}
|
|
|
|
/* Unload all loaded modules. */
|
|
for (count = 0; count < NOBJS; ++count)
|
|
if (testobjs[count].handle != NULL)
|
|
{ printf ("\nclose: %s: l_initfini = %p, l_versions = %p\n",
|
|
testobjs[count].name,
|
|
((struct link_map*)testobjs[count].handle)->l_initfini,
|
|
((struct link_map*)testobjs[count].handle)->l_versions);
|
|
if (dlclose (testobjs[count].handle) != 0)
|
|
{
|
|
printf ("failed to close %s\n", testobjs[count].name);
|
|
result = 1;
|
|
} }
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
int
|
|
foo (int a)
|
|
{
|
|
return a - 1;
|
|
}
|