From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6754 invoked by alias); 3 Mar 2005 07:21:50 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 6737 invoked from network); 3 Mar 2005 07:21:49 -0000 Received: from unknown (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 3 Mar 2005 07:21:49 -0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id j237Llks012139; Thu, 3 Mar 2005 08:21:47 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id j237LlXe012136; Thu, 3 Mar 2005 08:21:47 +0100 Date: Thu, 03 Mar 2005 07:21:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Testcase for a ld.so bug Message-ID: <20050303072147.GH4777@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-SW-Source: 2005-03/txt/msg00005.txt.bz2 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 * 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 +#include + +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 + +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 + +int +bar (int x) +{ + puts ("bar"); + fflush (stdout); + x = foo (x - 4); + puts ("bar after foo"); + return x; +} Jakub