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>, tcallawa@redhat.com
Subject: [PATCH] Fix TLS handling in ld.so on i386/sh/sparc32
Date: Sat, 15 May 2004 07:50:00 -0000	[thread overview]
Message-ID: <20040514200749.GF5191@sunsite.ms.mff.cuni.cz> (raw)
Message-ID: <20040515075000.ppyt7ybvhwjrM9WeD0QsfQuD6e8KXaHcm2hUtNxxze4@z> (raw)

Hi!

When attempting to add TLS support for prelink on SPARC, I have noticed
ld.so segfaults.  CHECK_STATIC_TLS must never be called if sym_map == NULL
(which is iff sym == NULL).  Looking around revealed the same problem
on SH and in i386 RELA handling (I have added 2 new testcases to prelink
where one of them fails on i386 unless this patch is in).

2004-05-14  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Only
	CHECK_STATIC_TLS if sym != NULL.
	* sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/i386/dl-machine.h (elf_machine_rela): Likewise.

--- libc/sysdeps/sparc/sparc32/dl-machine.h.jj	2004-04-21 10:06:11.000000000 +0200
+++ libc/sysdeps/sparc/sparc32/dl-machine.h	2004-05-14 23:37:55.412726806 +0200
@@ -521,22 +521,27 @@ elf_machine_rela (struct link_map *map, 
 	  /* We know the offset of object the symbol is contained in.
 	     It is a negative value which will be added to the
 	     thread pointer.  */
-	  CHECK_STATIC_TLS (map, sym_map);
-	  *reloc_addr
-	    = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset)
-	      + reloc->r_addend;
+	  if (sym != NULL)
+	    {
+	      CHECK_STATIC_TLS (map, sym_map);
+	      *reloc_addr = sym->st_value - sym_map->l_tls_offset
+			    + reloc->r_addend;
+	    }
 	  break;
 # ifndef RTLD_BOOTSTRAP
 	case R_SPARC_TLS_LE_HIX22:
 	case R_SPARC_TLS_LE_LOX10:
-	  CHECK_STATIC_TLS (map, sym_map);
-	  value = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset)
-		  + reloc->r_addend;
-	  if (r_type == R_SPARC_TLS_LE_HIX22)
-	    *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10);
-	  else
-	    *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff)
-			  | 0x1c00;
+	  if (sym != NULL)
+	    {
+	      CHECK_STATIC_TLS (map, sym_map);
+	      value = sym->st_value - sym_map->l_tls_offset
+		      + reloc->r_addend;
+	      if (r_type == R_SPARC_TLS_LE_HIX22)
+		*reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10);
+	      else
+		*reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff)
+			      | 0x1c00;
+	    }
 	  break;
 # endif
 #endif
--- libc/sysdeps/sh/dl-machine.h.jj	2004-03-11 11:10:19.000000000 +0100
+++ libc/sysdeps/sh/dl-machine.h	2004-05-14 23:36:13.157052354 +0200
@@ -580,10 +580,12 @@ elf_machine_rela (struct link_map *map, 
 	     It is a positive value which will be added to the thread
 	     pointer.  To get the variable position in the TLS block
 	     we add the offset from that of the TLS block.  */
-	  CHECK_STATIC_TLS (map, sym_map);
-	  *reloc_addr
-	    = ((sym == NULL ? 0 : sym_map->l_tls_offset + sym->st_value)
-	       + reloc->r_addend);
+	  if (sym != NULL)
+	    {
+	      CHECK_STATIC_TLS (map, sym_map);
+	      *reloc_addr = sym_map->l_tls_offset + sym->st_value
+			    + reloc->r_addend;
+	    }
 # endif
 	  break;
 #endif	/* use TLS */
--- libc/sysdeps/i386/dl-machine.h.jj	2004-03-09 10:58:16.000000000 +0100
+++ libc/sysdeps/i386/dl-machine.h	2004-05-14 23:35:10.295317995 +0200
@@ -587,20 +587,24 @@ elf_machine_rela (struct link_map *map, 
 	     It is a positive value which will be subtracted from the
 	     thread pointer.  To get the variable position in the TLS
 	     block we subtract the offset from that of the TLS block.  */
-	  CHECK_STATIC_TLS (map, sym_map);
-	  *reloc_addr
-	    = (sym == NULL ? 0 : sym_map->l_tls_offset - sym->st_value)
-	      + reloc->r_addend;
+	  if (sym != NULL)
+	    {
+	      CHECK_STATIC_TLS (map, sym_map);
+	      *reloc_addr = sym_map->l_tls_offset - sym->st_value
+			    + reloc->r_addend;
+	    }
 	  break;
 	case R_386_TLS_TPOFF:
 	  /* The offset is negative, forward from the thread pointer.  */
 	  /* We know the offset of object the symbol is contained in.
 	     It is a negative value which will be added to the
 	     thread pointer.  */
-	  CHECK_STATIC_TLS (map, sym_map);
-	  *reloc_addr
-	    = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset)
-	      + reloc->r_addend;
+	  if (sym != NULL)
+	    {
+	      CHECK_STATIC_TLS (map, sym_map);
+	      *reloc_addr = sym->st_value - sym_map->l_tls_offset
+			    + reloc->r_addend;
+	    }
 	  break;
 #  endif	/* use TLS */
 	case R_386_COPY:

	Jakub

             reply	other threads:[~2004-05-15  0:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-14 23:15 Jakub Jelinek [this message]
2004-05-15  7:50 ` Jakub Jelinek
2004-05-18  0:40 ` Ulrich Drepper

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=20040514200749.GF5191@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    --cc=tcallawa@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).