]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix TLS relocations against local symbols on powerpc32, sparc32 and sparc64
authorJames Clarke <jrtc27@jrtc27.com>
Fri, 13 Oct 2017 18:44:39 +0000 (15:44 -0300)
committerAurelien Jarno <aurelien@aurel32.net>
Tue, 14 Nov 2017 20:07:52 +0000 (21:07 +0100)
Normally, TLS relocations against local symbols are optimised by the linker
to be absolute.  However, gold does not do this, and so it is possible to
end up with, for example, R_SPARC_TLS_DTPMOD64 referring to a local symbol.
Since sym_map is left as null in elf_machine_rela for the special local
symbol case, the relocation handling thinks it has nothing to do, and so
the module gets left as 0.  Havoc then ensues when the variable in question
is accessed.

Before this fix, the main_local_gold program would receive a SIGBUS on
sparc64, and SIGSEGV on powerpc32.  With this fix applied, that test now
passes like the rest of them.

* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
Assign sym_map to be map for local symbols, as TLS relocations
use sym_map to determine whether the symbol is defined and to
extract the TLS information.
* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Likewise.
* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela): Likewise.

(cherry picked from commit 8644588807215ab09716ac04a150f91ac83acffd)

ChangeLog
sysdeps/powerpc/powerpc32/dl-machine.h
sysdeps/sparc/sparc32/dl-machine.h
sysdeps/sparc/sparc64/dl-machine.h

index e08430554822c1cf9315d8e9516cb7f4158e1ce2..e17a716e535097cc84ea5d8a799c8cfbd8d38753 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-10-13  James Clarke  <jrtc27@jrtc27.com>
+
+       * sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
+       Assign sym_map to be map for local symbols, as TLS relocations
+       use sym_map to determine whether the symbol is defined and to
+       extract the TLS information.
+       * sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Likewise.
+       * sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela): Likewise.
+
 2017-08-23  H.J. Lu  <hongjiu.lu@intel.com>
 
        * sysdeps/x86_64/fpu/libm-test-ulps: Regenerated.
index 1f8437ed9cf9e734d5416d2d36b2846d4314e05f..c19b3b7a16cd9e840b6ac7ac657bfe110b546eed 100644 (file)
@@ -310,7 +310,10 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
      against local symbols.  */
   if (__builtin_expect (ELF32_ST_BIND (sym->st_info) == STB_LOCAL, 0)
       && sym->st_shndx != SHN_UNDEF)
-    value = map->l_addr;
+    {
+      sym_map = map;
+      value = map->l_addr;
+    }
   else
     {
       sym_map = RESOLVE_MAP (&sym, version, r_type);
index 436e4e6cc3e33a66ec4d9e41affa7f2788e9d1bc..debf67bd1ba40f347c745fc800724f9281c0e08e 100644 (file)
@@ -376,6 +376,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
   if (__builtin_expect (ELF32_ST_BIND (sym->st_info) == STB_LOCAL, 0)
       && sym->st_shndx != SHN_UNDEF)
     {
+      sym_map = map;
       value = map->l_addr;
     }
   else
index c2871dca3ab6b25532acbf8f8d24ad288b734a68..e1ec7a532cd2fc5aeb52d56864813f5434a545a0 100644 (file)
@@ -403,6 +403,7 @@ elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc,
   if (__builtin_expect (ELF64_ST_BIND (sym->st_info) == STB_LOCAL, 0)
       && sym->st_shndx != SHN_UNDEF)
     {
+      sym_map = map;
       value = map->l_addr;
     }
   else