This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] PPC64 dl-machine.h fixes for TLS
- From: Steven Munroe <sjmunroe at us dot ibm dot com>
- To: libc-alpha <libc-alpha at sources dot redhat dot com>
- Date: Wed, 05 Mar 2003 17:32:45 -0600
- Subject: [PATCH] PPC64 dl-machine.h fixes for TLS
- Organization: IBM Linux Developement
- Reply-to: sjmunroe at vnet dot ibm dot com
It took me while to find the last bug from cvs head.
- Elf64_Addr value = ((sym == NULL ? 0 : sym_map->l_addr + sym->st_value)
+ Elf64_Addr value = ((sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value)
This caused various segfaults when building --without-tls.
With this fixed I defined the elf_machine_tprel function and added back the
TPREL16* relocations. This patch was tested both --with-tls and --without-tls
and runs make/make check successfully.
2003-03-05 Steven Munroe <sjmunroe at us dot ibm dot com>
* sysdeps/powerpc/powerpc64/dl-machine.h
[USE_TLS] (elf_machine_tprel): New function.
(elf_machine_rela): Check sym_map != NULL before use.
(elf_machine_rela) [USE_TLS]: Declare tprel_value. Data only TOC
relocations should return. Use elf_machine_tprel function for
all TPREL class relocations.
--
Steven Munroe
sjmunroe at us dot ibm dot com
Linux on PowerPC-64 Development
GLIBC for PowerPC-64 Development
diff -urN libc23-cvstip-20030305/sysdeps/powerpc/powerpc64/dl-machine.h libc23/sysdeps/powerpc/powerpc64/dl-machine.h
--- libc23-cvstip-20030305/sysdeps/powerpc/powerpc64/dl-machine.h 2003-03-04 21:27:03.000000000 -0600
+++ libc23/sysdeps/powerpc/powerpc64/dl-machine.h 2003-03-05 16:39:05.000000000 -0600
@@ -545,6 +545,27 @@
*reloc_addr = l_addr + reloc->r_addend;
}
+#if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
+static Elf64_Addr
+elf_machine_tprel ( struct link_map *map,
+ struct link_map *sym_map,
+ const Elf64_Sym *sym,
+ const Elf64_Rela *reloc)
+{
+ Elf64_Addr tprel_value = 0;
+# ifndef RTLD_BOOTSTRAP
+ if (sym_map)
+ {
+ CHECK_STATIC_TLS (map, sym_map);
+# endif
+ tprel_value = TLS_TPREL_VALUE (sym_map, sym, reloc);
+# ifndef RTLD_BOOTSTRAP
+ }
+# endif
+ return tprel_value;
+}
+#endif
+
/* Perform the relocation specified by RELOC and SYM (which is fully
resolved). MAP is the object containing the reloc. */
static inline void
@@ -558,6 +579,9 @@
#ifndef RTLD_BOOTSTRAP
const Elf64_Sym *const refsym = sym;
#endif
+#if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
+ Elf64_Addr tprel_value = 0;
+#endif
if (r_type == R_PPC64_RELATIVE)
{
@@ -570,7 +594,7 @@
/* We need SYM_MAP even in the absence of TLS, for elf_machine_fixup_plt. */
struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
- Elf64_Addr value = ((sym == NULL ? 0 : sym_map->l_addr + sym->st_value)
+ Elf64_Addr value = ((sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value)
+ reloc->r_addend);
/* For relocs that don't edit code, return.
@@ -598,27 +622,74 @@
/* Get the information from the link map returned by the
resolve function. */
if (sym_map != NULL)
- *reloc_addr = sym_map->l_tls_modid;
+ *reloc_addr = sym_map->l_tls_modid;
# endif
return;
case R_PPC64_DTPREL64:
/* During relocation all TLS symbols are defined and used.
- Therefore the offset is already correct. */
+ Therefore the offset is already correct. */
# ifndef RTLD_BOOTSTRAP
*reloc_addr = TLS_DTPREL_VALUE (sym, reloc);
# endif
- break;
+ return;
+
case R_PPC64_TPREL64:
-# ifndef RTLD_BOOTSTRAP
- if (sym_map)
- {
- CHECK_STATIC_TLS (map, sym_map);
-# endif
- *reloc_addr = TLS_TPREL_VALUE (sym_map, sym, reloc);
-# ifndef RTLD_BOOTSTRAP
- }
-# endif
+ *reloc_addr = elf_machine_tprel (map, sym_map, sym, reloc);
+ return;
+
+ case R_PPC64_TPREL16_LO_DS:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ if (dont_expect ((tprel_value & 3) != 0))
+ _dl_reloc_overflow (map, "R_PPC64_TPREL16_LO_DS",
+ reloc_addr, sym, refsym);
+ *(Elf64_Half *) reloc_addr = BIT_INSERT (*(Elf64_Half *) reloc_addr,
+ tprel_value, 0xfffc);
+ break;
+
+ case R_PPC64_TPREL16_DS:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ if (dont_expect ((tprel_value + 0x8000) >= 0x10000
+ || (tprel_value & 3) != 0))
+ _dl_reloc_overflow (map, "R_PPC64_TPREL16_DS", reloc_addr,
+ sym, refsym);
+ *(Elf64_Half *) reloc_addr = BIT_INSERT (*(Elf64_Half *) reloc_addr,
+ tprel_value, 0xfffc);
+ break;
+
+ case R_PPC64_TPREL16_LO:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_LO (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HI:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HI (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HA:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HA (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HIGHER:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HIGHER (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HIGHEST:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HIGHEST (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HIGHERA:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HIGHERA (tprel_value);
+ break;
+
+ case R_PPC64_TPREL16_HIGHESTA:
+ tprel_value = elf_machine_tprel (map, sym_map, sym, reloc);
+ *(Elf64_Half *) reloc_addr = PPC_HIGHESTA (tprel_value);
break;
#endif /* USE_TLS etc. */