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]

[PATCH] TLS i386/dl-machine.h changes


Hi!

IMHO R_386_TLS_DTPMOD32 should not use addend in REL version.
It is a counterpart of R_386_GLOB_DAT which doesn't use it either.
I believe the reason for R_386_GLOB_DAT is that if you reference
x, x + 8 and x + 16 in one library, you don't end up with 3 dynamic relocs
against x but just one.
ATM binutils will never create R_386_TLS_DTPMOD32 with addend != 0 (unlike
R_386_TLS_TPOFF32).
Not using the addend has a serious advantage for prelink - it can prelink
all DTPOFF32 relocs without the need for costly REL->RELA conversion.

Another thing is that sym != NULL implies sym_map != NULL (otherwise e.g.
Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
would crash first).
Plus we need the TLS RELA support too...

2002-09-12  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/i386/dl-machine.h (elf_machine_rel) [R_386_TLS_DTPMOD32]:
	Don't use addend.
	[R_386_TLS_TPOFF32]: Remove redundant sym_map != NULL check.
	(elf_machine_rela): Add support for TLS relocs.

--- libc/sysdeps/i386/dl-machine.h.jj	2002-08-31 09:40:43.000000000 +0200
+++ libc/sysdeps/i386/dl-machine.h	2002-09-12 18:19:22.000000000 +0200
@@ -410,8 +410,6 @@ elf_machine_rel (struct link_map *map, c
 	  *reloc_addr = value;
 	  break;
 
-	  /* XXX Remove TLS relocations which are not needed.  */
-
 #ifdef USE_TLS
 	case R_386_TLS_DTPMOD32:
 # ifdef RTLD_BOOTSTRAP
@@ -432,7 +430,7 @@ elf_machine_rel (struct link_map *map, c
 	  /* During relocation all TLS symbols are defined and used.
 	     Therefore the offset is already correct.  */
 	  if (sym != NULL)
-	    *reloc_addr += sym->st_value;
+	    *reloc_addr = sym->st_value;
 # endif
 	  break;
 	case R_386_TLS_TPOFF32:
@@ -444,7 +442,7 @@ elf_machine_rel (struct link_map *map, c
 	     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.  */
-	  if (sym_map != NULL && sym != NULL)
+	  if (sym != NULL)
 	    *reloc_addr += sym_map->l_tls_offset - sym->st_value;
 # endif
 	  break;
@@ -516,7 +514,44 @@ elf_machine_rela (struct link_map *map, 
 	case R_386_PC32:
 	  *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
 	  break;
-	  /* XXX Do we have to handle the TLS relocation here?  */
+
+#ifdef USE_TLS
+	case R_386_TLS_DTPMOD32:
+# ifdef RTLD_BOOTSTRAP
+	  /* During startup the dynamic linker is always the module
+	     with index 1.
+	     XXX If this relocation is necessary move before RESOLVE
+	     call.  */
+	  *reloc_addr = 1;
+# else
+	  /* Get the information from the link map returned by the
+	     resolv function.  */
+	  if (sym_map != NULL)
+	    *reloc_addr = sym_map->l_tls_modid;
+# endif
+	  break;
+	case R_386_TLS_DTPOFF32:
+# ifndef RTLD_BOOTSTRAP
+	  /* During relocation all TLS symbols are defined and used.
+	     Therefore the offset is already correct.  */
+	  *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
+# endif
+	  break;
+	case R_386_TLS_TPOFF32:
+	  /* The offset is positive, backward from the thread pointer.  */
+# ifdef RTLD_BOOTSTRAP
+	  *reloc_addr = map->l_tls_offset - sym->st_value + reloc->r_addend;
+# else
+	  /* We know the offset of object the symbol is contained in.
+	     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.  */
+	  *reloc_addr
+	    = (sym == NULL ? 0 : sym_map->l_tls_offset - sym->st_value)
+	      + reloc->r_addend;
+# endif
+	  break;
+#endif	/* use TLS */
 	default:
 	  /* We add these checks in the version to relocate ld.so only
 	     if we are still debugging.  */

	Jakub


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