This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Testcase for a ld.so bug


Hi!

This testcase shows a bug in the dynamic linker.
During the second dlclose, unload3mod3.so is unloaded, but unload3mod4.so
is not, though unload3mod4.so has a relocation dependency on unload3mod3.so
that has not been recorded because they were both loaded in the same dlopen
call as dependencies.

2005-03-03  Jakub Jelinek  <jakub@redhat.com>

	* elf/Makefile: Add rules to build and run unload3 test.
	* elf/unload3.c: New test.
	* elf/unload3mod1.c: New file.
	* elf/unload3mod2.c: New file.
	* elf/unload3mod3.c: New file.
	* elf/unload3mod4.c: New file.

--- libc/elf/Makefile.jj	2005-02-25 14:45:00.000000000 +0100
+++ libc/elf/Makefile	2005-03-03 08:13:13.207849513 +0100
@@ -84,6 +84,7 @@ distribute	:= rtld-Rules \
 		   tst-execstack-mod.c tst-dlmodcount.c \
 		   check-textrel.c dl-sysdep.h test-dlopenrpathmod.c \
 		   tst-deep1mod1.c tst-deep1mod2.c tst-deep1mod3.c \
+		   unload3mod1.c unload3mod2.c unload3mod3.c unload3mod4.c \
 		   tst-auditmod1.c
 
 CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables
@@ -159,7 +160,7 @@ tests += loadtest restest1 preloadtest l
 	 tst-tls10 tst-tls11 tst-tls12 tst-tls13 tst-tls14 tst-align \
 	 tst-align2 $(tests-execstack-$(have-z-execstack)) tst-dlmodcount \
 	 tst-dlopenrpath tst-deep1 tst-dlmopen1 tst-dlmopen2 tst-dlmopen3 \
-	 tst-audit1
+	 unload3 tst-audit1
 #	 reldep9
 test-srcs = tst-pathopt
 tests-vis-yes = vismain
@@ -194,7 +195,8 @@ modules-names = testobj1 testobj2 testob
 		tst-alignmod tst-alignmod2 \
 		$(modules-execstack-$(have-z-execstack)) \
 		tst-dlopenrpathmod tst-deep1mod1 tst-deep1mod2 tst-deep1mod3 \
-		tst-dlmopen1mod tst-auditmod1
+		tst-dlmopen1mod tst-auditmod1 \
+		unload3mod1 unload3mod2 unload3mod3 unload3mod4
 ifeq (yes,$(have-initfini-array))
 modules-names += tst-array2dep
 endif
@@ -426,6 +428,9 @@ $(objpfx)reldep8mod3.so: $(objpfx)reldep
 $(objpfx)nodel2mod3.so: $(objpfx)nodel2mod1.so $(objpfx)nodel2mod2.so
 $(objpfx)reldep9mod2.so: $(objpfx)reldep9mod1.so
 $(objpfx)reldep9mod3.so: $(objpfx)reldep9mod1.so $(objpfx)reldep9mod2.so
+$(objpfx)unload3mod1.so: $(objpfx)unload3mod3.so
+$(objpfx)unload3mod2.so: $(objpfx)unload3mod3.so
+$(objpfx)unload3mod3.so: $(objpfx)unload3mod4.so
 
 LDFLAGS-tst-tlsmod5.so = -nostdlib
 LDFLAGS-tst-tlsmod6.so = -nostdlib
@@ -465,6 +470,7 @@ circlemod3.so-no-z-defs = yes
 circlemod3a.so-no-z-defs = yes
 reldep8mod2.so-no-z-defs = yes
 reldep9mod1.so-no-z-defs = yes
+unload3mod4.so-no-z-defs = yes
 
 # filtmod1.so has a special rule
 $(filter-out $(objpfx)filtmod1.so, $(test-modules)): $(objpfx)%.so: $(objpfx)%.os
@@ -681,6 +687,10 @@ $(objpfx)tst-align: $(libdl)
 $(objpfx)tst-align.out: $(objpfx)tst-alignmod.so
 $(objpfx)tst-align2: $(objpfx)tst-alignmod2.so
 
+$(objpfx)unload3: $(libdl)
+$(objpfx)unload3.out: $(objpfx)unload3mod1.so $(objpfx)unload3mod2.so \
+		      $(objpfx)unload3mod3.so $(objpfx)unload3mod4.so
+
 ifdef libdl
 $(objpfx)tst-tls9-static: $(common-objpfx)dlfcn/libdl.a
 $(objpfx)tst-tls9-static.out: $(objpfx)tst-tlsmod5.so $(objpfx)tst-tlsmod6.so
--- libc/elf/unload3.c.jj	2005-03-03 08:10:45.809060064 +0100
+++ libc/elf/unload3.c	2005-03-03 08:10:45.809060064 +0100
@@ -0,0 +1,41 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+  void *g = dlopen ("unload3mod1.so", RTLD_GLOBAL | RTLD_NOW);
+  void *h = dlopen ("unload3mod2.so", RTLD_GLOBAL | RTLD_NOW);
+  if (g == NULL || h == NULL)
+    {
+      printf ("dlopen unload3mod{1,2}.so failed: %p %p\n", g, h);
+      return 1;
+    }
+  dlclose (h);
+  dlclose (g);
+
+  g = dlopen ("unload3mod3.so", RTLD_GLOBAL | RTLD_NOW);
+  h = dlopen ("unload3mod4.so", RTLD_GLOBAL | RTLD_NOW);
+  if (g == NULL || h == NULL)
+    {
+      printf ("dlopen unload3mod{3,4}.so failed: %p %p\n", g, h);
+      return 1;
+    }
+
+  int (*fn) (int);
+  fn = dlsym (h, "bar");
+  if (fn == NULL)
+    {
+      puts ("dlsym failed");
+      return 1;
+    }
+
+  int val = fn (16);
+  if (val != 24)
+    {
+      printf ("bar returned %d != 24\n", val);
+      return 1;
+    }
+
+  return 0;
+}
--- libc/elf/unload3mod1.c.jj	2005-03-03 08:10:45.809060064 +0100
+++ libc/elf/unload3mod1.c	2005-03-03 08:10:45.809060064 +0100
@@ -0,0 +1 @@
+int dummy1;
--- libc/elf/unload3mod2.c.jj	2005-03-03 08:10:45.809060064 +0100
+++ libc/elf/unload3mod2.c	2005-03-03 08:10:45.809060064 +0100
@@ -0,0 +1 @@
+int dummy2;
--- libc/elf/unload3mod3.c.jj	2005-03-03 08:10:45.809060064 +0100
+++ libc/elf/unload3mod3.c	2005-03-03 08:10:45.809060064 +0100
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+foo (int x)
+{
+  puts ("foo");
+  return x * 2;
+}
--- libc/elf/unload3mod4.c.jj	2005-03-03 08:10:45.809060064 +0100
+++ libc/elf/unload3mod4.c	2005-03-03 08:12:40.932588653 +0100
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int
+bar (int x)
+{
+  puts ("bar");
+  fflush (stdout);
+  x = foo (x - 4);
+  puts ("bar after foo");
+  return x;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]