public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* simplify assertion check in _dl_fini()
@ 2004-11-29 19:44 Alexandre Oliva
  2004-12-06  5:03 ` Ulrich Drepper
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2004-11-29 19:44 UTC (permalink / raw)
  To: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]

_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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: glibc-rtld-removed-from-list.patch --]
[-- Type: text/x-patch, Size: 1362 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 188 bytes --]


-- 
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}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: simplify assertion check in _dl_fini()
  2004-11-29 19:44 simplify assertion check in _dl_fini() Alexandre Oliva
@ 2004-12-06  5:03 ` Ulrich Drepper
  2004-12-06 21:14   ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Drepper @ 2004-12-06  5:03 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: libc-hacker

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why should runtime overhead be added just to simplify asserts which are
not present in final binaries?  The patch is completely bogus.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBs+f12ijCOnn/RHQRAl8IAJ45Lj05u4EwY3v+1CPJKTOqzf7V3ACfcorm
EJF9eprATdoMyXwkjN/1quk=
=qqth
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: simplify assertion check in _dl_fini()
  2004-12-06  5:03 ` Ulrich Drepper
@ 2004-12-06 21:14   ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2004-12-06 21:14 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libc-hacker

On Dec  6, 2004, Ulrich Drepper <drepper@redhat.com> wrote:

> Why should runtime overhead be added just to simplify asserts which are
> not present in final binaries?

To keep the data structure consistent before the inconsistency
actually bites?

-- 
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}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-12-06 21:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29 19:44 simplify assertion check in _dl_fini() Alexandre Oliva
2004-12-06  5:03 ` Ulrich Drepper
2004-12-06 21:14   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).