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]

simplify assertion check in _dl_fini()


_dl_fini() makes a special exception in its assertion checking for the
main map, because ld.so may have been removed from the object list in
rtld.c.  I'm not sure that's such a good idea in itself, since a
program without DT_NEEDED entries might legitimately dlopen a library
that DT_NEEDs ld.so, and we don't want to load it in again.

I haven't tested this case though.

What I did test was a PIE without any DT_NEEDED libs, without any
dlopening, and found out it crashed with FC3/x86's glibc.  I didn't
investigate much further, but while looking into it I noticed the
_dl_fini() assert could probably be simplified, based on what I'd just
found out while investigating an assertion failure under similar
conditions on an older glibc snapshot ported to Fujitsu FR-V.

The port is yet to be contributed, but I thought I'd contribute this
fix right away, since something may have regressed in glibc in this
regard, since the only failure in my port is the assertion failure at
the end, whereas on x86 mainline it crashes quite early.

The patch is attached below.  The test program was as simple as
`main(){}', compiled on x86 with -pie -Wl,-Bstatic.

Index: ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elf/rtld.c (dl_main): Decrement nloaded if dl_rtld_map was
	removed from the loaded chain.
	* elf/dl-fini.c (_dl_fini): Simplify corresponding assertion
	check.

Index: elf/rtld.c
===================================================================
RCS file: /cvs/glibc/libc/elf/rtld.c,v
retrieving revision 1.337
diff -u -p -r1.337 rtld.c
--- elf/rtld.c 13 Nov 2004 18:57:22 -0000 1.337
+++ elf/rtld.c 29 Nov 2004 19:29:15 -0000
@@ -1414,6 +1414,8 @@ ERROR: ld.so: object '%s' from %s cannot
 	  GL(dl_rtld_map).l_next->l_prev = &GL(dl_rtld_map);
 	}
     }
+  else
+    --GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
 
   /* Now let us see whether all libraries are available in the
      versions we need.  */
Index: elf/dl-fini.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-fini.c,v
retrieving revision 1.37
diff -u -p -r1.37 dl-fini.c
--- elf/dl-fini.c 27 Oct 2004 20:24:17 -0000 1.37
+++ elf/dl-fini.c 29 Nov 2004 19:29:15 -0000
@@ -88,8 +88,7 @@ _dl_fini (void)
 	       dlclose()ed from underneath us.  */
 	    ++l->l_opencount;
 	  }
-      assert (cnt != LM_ID_BASE || i == nloaded);
-      assert (cnt == LM_ID_BASE || i == nloaded || i == nloaded - 1);
+      assert (i == nloaded);
       unsigned int nmaps = i;
 
       if (nmaps != 0)
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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