aboutsummaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-01-16 17:09:04 +0000
committerUlrich Drepper <drepper@redhat.com>1999-01-16 17:09:04 +0000
commit482eec0d1188823ad93247f79bf965886e8bd4f7 (patch)
tree5a3157c41a1310f5440de77f841753a32bb1444d /elf
parent37a87f834a459f6136ff44c7887b013d1ae0f6be (diff)
downloadglibc-482eec0d1188823ad93247f79bf965886e8bd4f7.tar
glibc-482eec0d1188823ad93247f79bf965886e8bd4f7.tar.gz
glibc-482eec0d1188823ad93247f79bf965886e8bd4f7.tar.bz2
glibc-482eec0d1188823ad93247f79bf965886e8bd4f7.zip
Update.
1999-01-16 Ulrich Drepper <drepper@cygnus.com> * elf/Makefile (tests): Add loadtest. Add rules to generate test modules. * Makeconfig (+link): Add $(LDFLAGS-$(@F)) to command line. * elf/loadtest.c: New file. * elf/testobj1.c: New file. * elf/testobj2.c: New file. * elf/testobj3.c: New file. * elf/dl-close.c: Correct removing module from global list. * elf/dl-open.c: Add debugging code. * include/string.h: Add __rawmemchr prototype. * string/Makefile (routines): Add rawmemchr. * string/Versions [GLIBC_2.1]: Add __rawmemchr and rawmemchr. * string/string.h: Add prototype for rawmemchr. * string/bits/string2.h: Optimize strchr with rawmemchr. * sysdeps/generic/rawmemchr.c: New file. * sysdeps/i386/rawmemchr.c: New file. * sysdeps/i386/i486/bits/string.h: Add rawmemchr inline code. Optimize strchr with rawmemchr. * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define _LFS_LARGEFILE, _LFS64_LARGEFILE, and _LFS64_STDIO for Unix98. 1999-01-14 Andreas Jaeger <aj@arthur.rhein-neckar.de> * nis/nis_error.c (nis_errlist): Fix capitilasation.
Diffstat (limited to 'elf')
-rw-r--r--elf/Makefile30
-rw-r--r--elf/dl-close.c13
-rw-r--r--elf/dl-open.c42
-rw-r--r--elf/loadtest.c114
-rw-r--r--elf/testobj1.c11
-rw-r--r--elf/testobj2.c11
-rw-r--r--elf/testobj3.c11
7 files changed, 223 insertions, 9 deletions
diff --git a/elf/Makefile b/elf/Makefile
index 81aa217e3d..e029fbafd0 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+# Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -75,6 +75,8 @@ others += ldconfig
install-rootsbin += ldconfig
endif
+tests = loadtest
+
include ../Rules
@@ -200,6 +202,32 @@ else
$(objpfx)sprof: $(objpfx)libdl.a
endif
+# This macro is similar to build-shlib but it does not define a soname
+# and it does not depend on the destination name to start with `lib'.
+define build-module
+$(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
+ -B$(csu-objpfx) $(load-map-file) \
+ $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
+ -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
+ -Wl,--whole-archive -Wl,-soname,$(@F) \
+ $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
+ $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
+endef
+
+modules-names = testobj1 testobj2 testobj3
+test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
+
+$(objpfx)testobj2.so: $(objpfx)testobj1.so
+LDLIBS-testobj2.so = $(objpfx)testobj1.so
+
+$(test-modules): $(objpfx)%.so: %.c
+ $(build-module)
+
+$(objpfx)loadtest: $(objpfx)libdl.so
+LDFLAGS-loadtest = -rdynamic
+
+$(objpfx)loadtest.out: $(test-modules)
+
# muwahaha
LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
diff --git a/elf/dl-close.c b/elf/dl-close.c
index 0fbeecc4cd..6a68651d22 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -1,5 +1,5 @@
/* Close a shared object opened by `_dl_open'.
- Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -108,12 +108,11 @@ _dl_close (struct link_map *map)
do
--cnt;
while (_dl_main_searchlist->r_list[cnt] != imap);
- while (cnt < _dl_main_searchlist->r_nlist)
- {
- _dl_main_searchlist->r_list[0]
- = _dl_main_searchlist->r_list[1];
- ++cnt;
- }
+
+ while (++cnt < _dl_main_searchlist->r_nlist)
+ _dl_main_searchlist->r_list[cnt - 1]
+ = _dl_main_searchlist->r_list[cnt];
+
--_dl_main_searchlist->r_nlist;
if (_dl_main_searchlist->r_nlist
== _dl_initial_searchlist.r_nlist)
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 8cf1084a94..3db2b0e9f7 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -1,5 +1,5 @@
/* Load a shared object at runtime, relocate it, and run its initializer.
- Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -42,6 +42,11 @@ extern char **__libc_argv;
extern char **__environ;
+/* Undefine the following for debugging. */
+/* #define SCOPE_DEBUG 1 */
+#ifdef SCOPE_DEBUG
+static void show_scope (struct link_map *new);
+#endif
/* During the program run we must not modify the global data of
loaded shared object simultanously in two threads. Therefore we
@@ -86,6 +91,10 @@ dl_open_worker (void *a)
/* So far, so good. Now check the versions. */
(void) _dl_check_all_versions (new, 0);
+#ifdef SCOPE_DEBUG
+ show_scope (new);
+#endif
+
/* Relocate the objects loaded. We do this in reverse order so that copy
relocs of earlier objects overwrite the data written by later objects. */
@@ -195,3 +204,34 @@ _dl_open (const char *file, int mode)
return args.map;
}
+
+
+#ifdef SCOPE_DEBUG
+#include <unistd.h>
+
+static void
+show_scope (struct link_map *new)
+{
+ int scope_cnt;
+
+ for (scope_cnt = 0; new->l_scope[scope_cnt] != NULL; ++scope_cnt)
+ {
+ char numbuf[2];
+ unsigned int cnt;
+
+ numbuf[0] = '0' + scope_cnt;
+ numbuf[1] = '\0';
+ _dl_sysdep_message ("scope ", numbuf, ":", NULL);
+
+ for (cnt = 0; cnt < new->l_scope[scope_cnt]->r_nlist; ++cnt)
+ if (*new->l_scope[scope_cnt]->r_list[cnt]->l_name)
+ _dl_sysdep_message (" ",
+ new->l_scope[scope_cnt]->r_list[cnt]->l_name,
+ NULL);
+ else
+ _dl_sysdep_message (" <main>", NULL);
+
+ _dl_sysdep_message ("\n", NULL);
+ }
+}
+#endif
diff --git a/elf/loadtest.c b/elf/loadtest.c
new file mode 100644
index 0000000000..209f420141
--- /dev/null
+++ b/elf/loadtest.c
@@ -0,0 +1,114 @@
+#include <assert.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/* How many load/unload operations do we do. */
+#define TEST_ROUNDS 100
+
+
+static struct
+{
+ /* Name of the module. */
+ const char *name;
+ /* The handle. */
+ void *handle;
+} testobjs[] =
+{
+ { "testobj1.so", NULL },
+ { "testobj2.so", NULL },
+ { "testobj3.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 },
+};
+#define NTESTS (sizeof (tests) / sizeof (tests[0]))
+
+
+int
+main (void)
+{
+ int count = TEST_ROUNDS;
+
+ /* 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'\n", testobjs[index].name);
+ }
+ else
+ {
+ dlclose (testobjs[index].handle);
+ testobjs[index].handle = NULL;
+
+ printf ("successfully unloaded `%s'\n", testobjs[index].name);
+ }
+ }
+
+ /* Unload all loaded modules. */
+ for (count = 0; count < NOBJS; ++count)
+ if (testobjs[count].handle != NULL)
+ dlclose (testobjs[count].handle);
+
+ return 0;
+}
+
+
+int
+foo (int a)
+{
+ return a - 1;
+}
diff --git a/elf/testobj1.c b/elf/testobj1.c
new file mode 100644
index 0000000000..9f64d675c4
--- /dev/null
+++ b/elf/testobj1.c
@@ -0,0 +1,11 @@
+int
+obj1func1 (int a __attribute__ ((unused)))
+{
+ return 42;
+}
+
+int
+obj1func2 (int a)
+{
+ return foo (a) + 10;
+}
diff --git a/elf/testobj2.c b/elf/testobj2.c
new file mode 100644
index 0000000000..5c89d33c8c
--- /dev/null
+++ b/elf/testobj2.c
@@ -0,0 +1,11 @@
+int
+obj2func1 (int a __attribute__ ((unused)))
+{
+ return 43;
+}
+
+int
+obj2func2 (int a)
+{
+ return obj1func1 (a) + 10;
+}
diff --git a/elf/testobj3.c b/elf/testobj3.c
new file mode 100644
index 0000000000..8e3d8865f7
--- /dev/null
+++ b/elf/testobj3.c
@@ -0,0 +1,11 @@
+int
+obj3func1 (int a __attribute__ ((unused)))
+{
+ return 44;
+}
+
+int
+obj3func2 (int a)
+{
+ return foo (a) + 42;
+}