public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix LD_DEBUG=statistics
Date: Sat, 13 Nov 2004 18:01:00 -0000	[thread overview]
Message-ID: <20041113175819.GF3536@sunsite.ms.mff.cuni.cz> (raw)

Hi!

LD_DEBUG=statistics someprog leads to segfaults with current glibc.
The problem is that print_statistics doesn't check for NULL _ns_loaded
namespaces and happily dereferences it.

While looking into it, I have noticed the num_relative_relocations
computation doesn't match what do-rel.h is actually doing, particularly
on !ELF_MACHINE_REL_RELATIVE RELA architectures it is processing relative
relocations even if l_addr == 0, but the library is not prelinked.

2004-11-13  Jakub Jelinek  <jakub@redhat.com>

	* elf/rtld.c (print_statistics): Avoid segfaults if not all namespaces
	are used.  Fix computation of num_relative_relocations on RELA
	architectures other than IA-64 and Alpha.

--- libc/elf/rtld.c.jj	2004-11-09 12:26:41.000000000 +0100
+++ libc/elf/rtld.c	2004-11-13 18:56:32.574028935 +0100
@@ -2336,19 +2336,29 @@ print_statistics (hp_timing_t *rtld_tota
   unsigned long int num_relative_relocations = 0;
   for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
     {
+      if (GL(dl_ns)[ns]._ns_loaded == NULL)
+	continue;
+
       struct r_scope_elem *scope = &GL(dl_ns)[ns]._ns_loaded->l_searchlist;
 
       for (unsigned int i = 0; i < scope->r_nlist; i++)
 	{
 	  struct link_map *l = scope->r_list [i];
 
-	  if (!l->l_addr)
-	    continue;
-
-	  if (l->l_info[VERSYMIDX (DT_RELCOUNT)])
+	  if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELCOUNT)])
 	    num_relative_relocations
 	      += l->l_info[VERSYMIDX (DT_RELCOUNT)]->d_un.d_val;
-	  if (l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#ifndef ELF_MACHINE_REL_RELATIVE
+	  /* Relative relocations are processed on these architectures if
+	     library is loaded to different address than p_vaddr or
+	     if not prelinked.  */
+	  if ((l->l_addr != 0 || !map->l_info[VALIDX(DT_GNU_PRELINKED)])
+	      && l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#else
+	  /* On e.g. IA-64 or Alpha, relative relocations are processed
+	     only if library is loaded to different address than p_vaddr.  */
+	  if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#endif
 	    num_relative_relocations
 	      += l->l_info[VERSYMIDX (DT_RELACOUNT)]->d_un.d_val;
 	}

	Jakub

             reply	other threads:[~2004-11-13 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-13 18:01 Jakub Jelinek [this message]
2004-11-13 18:58 ` Ulrich Drepper
  -- strict thread matches above, loose matches on Subject: below --
2002-10-24 12:03 Jakub Jelinek
2002-10-25  3:38 ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041113175819.GF3536@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).