[PowerPC64] Use STN_UNDEF internally for edited relocs
authorAlan Modra <amodra@gmail.com>
Thu, 18 Jul 2019 01:42:40 +0000 (11:12 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 18 Jul 2019 12:47:30 +0000 (22:17 +0930)
It's not correct to use non-STT_TLS symbols with TLS relocation, not
that it matters much when editing relocs, but this edited reloc can be
output by --emit-relocs.  So don't use a symbol on the reloc.

* elf64-ppc.c (ppc64_elf_relocate_section): Don't bother selecting
a TLS section symbol for edited relocs.  Tighten TLS symbol/reloc
match test.

bfd/ChangeLog
bfd/elf64-ppc.c

index eb64f86389fdd9823595b8f044dd26dd4c27701d..a9dce78afca5d01ca6d8f1b1429a71f9a28e9438 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-18  Alan Modra  <amodra@gmail.com>
+
+       * elf64-ppc.c (ppc64_elf_relocate_section): Don't bother selecting
+       a TLS section symbol for edited relocs.  Tighten TLS symbol/reloc
+       match test.
+
 2019-07-18  Alan Modra  <amodra@gmail.com>
 
        * elf64-ppc.c (TLS_EXPLICIT): Define as 256.
index 0c0d4a4c13ef1f44e55745b082e78c8bdc7fec7a..df4a12c58d7bc478ad28cb8b2b464e295a1ca7f4 100644 (file)
@@ -14304,10 +14304,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          && (h == NULL
              || h->elf.root.type == bfd_link_hash_defined
              || h->elf.root.type == bfd_link_hash_defweak)
-         && (IS_PPC64_TLS_RELOC (r_type)
-             != (sym_type == STT_TLS
-                 || (sym_type == STT_SECTION
-                     && (sec->flags & SEC_THREAD_LOCAL) != 0))))
+         && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS))
        {
          if ((tls_mask & TLS_TLS) != 0
              && (r_type == R_PPC64_TLS
@@ -14547,20 +14544,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  if (tls_gd == 0)
                    {
                      /* Was an LD reloc.  */
-                     if (toc_symndx)
-                       sec = local_sections[toc_symndx];
-                     for (r_symndx = 0;
-                          r_symndx < symtab_hdr->sh_info;
-                          r_symndx++)
-                       if (local_sections[r_symndx] == sec)
-                         break;
-                     if (r_symndx >= symtab_hdr->sh_info)
-                       r_symndx = STN_UNDEF;
+                     r_symndx = STN_UNDEF;
                      rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
-                     if (r_symndx != STN_UNDEF)
-                       rel->r_addend -= (local_syms[r_symndx].st_value
-                                         + sec->output_offset
-                                         + sec->output_section->vma);
                    }
                  else if (toc_symndx != 0)
                    {
@@ -14669,24 +14654,12 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              if (ELF64_R_TYPE (rel[1].r_info) == R_PPC64_PLTCALL)
                bfd_put_32 (output_bfd, NOP, contents + offset + 4);
 
-             if (toc_symndx)
-               sec = local_sections[toc_symndx];
-             for (r_symndx = 0;
-                  r_symndx < symtab_hdr->sh_info;
-                  r_symndx++)
-               if (local_sections[r_symndx] == sec)
-                 break;
-             if (r_symndx >= symtab_hdr->sh_info)
-               r_symndx = STN_UNDEF;
-             rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
-             if (r_symndx != STN_UNDEF)
-               rel->r_addend -= (local_syms[r_symndx].st_value
-                                 + sec->output_offset
-                                 + sec->output_section->vma);
-
+             rel->r_offset = offset + d_offset;
+             r_symndx = STN_UNDEF;
              r_type = R_PPC64_TPREL16_LO;
              rel->r_info = ELF64_R_INFO (r_symndx, r_type);
-             rel->r_offset = offset + d_offset;
+             rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
+
              /* Zap the reloc on the _tls_get_addr call too.  */
              BFD_ASSERT (offset == rel[1].r_offset);
              rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);