Properly place the NULL STT_FILE symbol revistited
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
index 8c7c3b77adac4f98f0f91d30f4c2ab1b9985c284..a2ddb41a402e370877f73489ce68c0630a8d6d8d 100644 (file)
@@ -4836,6 +4836,14 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
          isym->st_shndx = SHN_UNDEF;
        }
     }
+  else if (*sec != NULL
+          && strcmp ((*sec)->name, ".toc") == 0
+          && ELF_ST_TYPE (isym->st_info) == STT_OBJECT)
+    {
+      struct ppc_link_hash_table *htab = ppc_hash_table (info);
+      if (htab != NULL)
+       htab->params->object_in_toc = 1;
+    }
 
   if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
     {
@@ -5943,6 +5951,10 @@ opd_entry_value (asection *opd_sec,
          ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
        }
 
+      /* PR 17512: file: 64b9dfbb.  */
+      if (offset + 7 >= opd_sec->size || offset + 7 < offset)
+       return (bfd_vma) -1;
+
       val = bfd_get_64 (opd_bfd, contents + offset);
       if (code_sec != NULL)
        {
@@ -5984,7 +5996,6 @@ opd_entry_value (asection *opd_sec,
 
   /* Go find the opd reloc at the sym address.  */
   lo = relocs;
-  BFD_ASSERT (lo != NULL);
   hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
   val = (bfd_vma) -1;
   while (lo < hi)
@@ -10939,6 +10950,7 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          h->ref_regular_nonweak = 1;
          h->forced_local = 1;
          h->non_elf = 0;
+         h->root.linker_def = 1;
        }
     }
 
@@ -12642,6 +12654,7 @@ build_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
                h->ref_regular_nonweak = 1;
                h->forced_local = 1;
                h->non_elf = 0;
+               h->root.linker_def = 1;
              }
          }
 
@@ -12715,6 +12728,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
              h->ref_regular_nonweak = 1;
              h->forced_local = 1;
              h->non_elf = 0;
+             h->root.linker_def = 1;
            }
        }
       plt0 = (htab->elf.splt->output_section->vma
@@ -13409,12 +13423,16 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                                              htab->tls_get_addr,
                                              htab->tls_get_addr_fd))
                offset = rel[1].r_offset;
+             /* We read the low GOT_TLS (or TOC16) insn because we
+                need to keep the destination reg.  It may be
+                something other than the usual r3, and moved to r3
+                before the call by intervening code.  */
+             insn1 = bfd_get_32 (output_bfd,
+                                 contents + rel->r_offset - d_offset);
              if ((tls_mask & tls_gd) != 0)
                {
                  /* IE */
-                 insn1 = bfd_get_32 (output_bfd,
-                                     contents + rel->r_offset - d_offset);
-                 insn1 &= (1 << 26) - (1 << 2);
+                 insn1 &= (0x1f << 21) | (0x1f << 16);
                  insn1 |= 58 << 26;    /* ld */
                  insn2 = 0x7c636a14;   /* add 3,3,13 */
                  if (offset != (bfd_vma) -1)
@@ -13429,7 +13447,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
              else
                {
                  /* LE */
-                 insn1 = 0x3c6d0000;   /* addis 3,13,0 */
+                 insn1 &= 0x1f << 21;
+                 insn1 |= 0x3c0d0000;  /* addis r,13,0 */
                  insn2 = 0x38630000;   /* addi 3,3,0 */
                  if (tls_gd == 0)
                    {
@@ -14108,7 +14127,12 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                      {
                        outrel.r_addend += relocation;
                        if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
-                         outrel.r_addend -= htab->elf.tls_sec->vma;
+                         {
+                           if (htab->elf.tls_sec == NULL)
+                             outrel.r_addend = 0;
+                           else
+                             outrel.r_addend -= htab->elf.tls_sec->vma;
+                         }
                      }
                    loc = relgot->contents;
                    loc += (relgot->reloc_count++
@@ -14125,9 +14149,14 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                      relocation = 1;
                    else if (tls_type != 0)
                      {
-                       relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
-                       if (tls_type == (TLS_TLS | TLS_TPREL))
-                         relocation += DTP_OFFSET - TP_OFFSET;
+                       if (htab->elf.tls_sec == NULL)
+                         relocation = 0;
+                       else
+                         {
+                           relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
+                           if (tls_type == (TLS_TLS | TLS_TPREL))
+                             relocation += DTP_OFFSET - TP_OFFSET;
+                         }
 
                        if (tls_type == (TLS_TLS | TLS_GD))
                          {
@@ -14260,7 +14289,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                bfd_put_32 (output_bfd, insn, p);
              break;
            }
-         addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+         if (htab->elf.tls_sec != NULL)
+           addend -= htab->elf.tls_sec->vma + TP_OFFSET;
          if (info->shared)
            /* The TPREL16 relocs shouldn't really be used in shared
               libs as they will result in DT_TEXTREL being set, but
@@ -14280,7 +14310,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
        case R_PPC64_DTPREL16_HIGHERA:
        case R_PPC64_DTPREL16_HIGHEST:
        case R_PPC64_DTPREL16_HIGHESTA:
-         addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+         if (htab->elf.tls_sec != NULL)
+           addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
          break;
 
        case R_PPC64_ADDR64_LOCAL:
@@ -14295,11 +14326,13 @@ ppc64_elf_relocate_section (bfd *output_bfd,
          goto dodyn;
 
        case R_PPC64_TPREL64:
-         addend -= htab->elf.tls_sec->vma + TP_OFFSET;
+         if (htab->elf.tls_sec != NULL)
+           addend -= htab->elf.tls_sec->vma + TP_OFFSET;
          goto dodyn;
 
        case R_PPC64_DTPREL64:
-         addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
+         if (htab->elf.tls_sec != NULL)
+           addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
          /* Fall thru */
 
          /* Relocations that may need to be propagated if this is a
This page took 0.041837 seconds and 4 git commands to generate.