* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Warn on
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index d4ef6120d25792afc1ea34eff6d2ac44e0182d75..bfb1ee83905a4d52d98974222a1ac68e3b8e2400 100644 (file)
@@ -1668,8 +1668,8 @@ typedef struct elf_linker_section
   const char *bss_name;
   /* Associated symbol name.  */
   const char *sym_name;
-  /* Value of symbol.  */
-  bfd_vma sym_val;
+  /* Associated symbol.  */
+  struct elf_link_hash_entry *sym;
 } elf_linker_section_t;
 
 /* Linked list of allocated pointer entries.  This hangs off of the
@@ -2363,7 +2363,7 @@ struct ppc_elf_link_hash_table
   asection *sgotplt;
 
   /* Short-cuts to frequently used symbols on VxWorks targets.  */
-  struct elf_link_hash_entry *hgot, *hplt;
+  struct elf_link_hash_entry *hplt;
 
   /* True if the target system is VxWorks.  */
   int is_vxworks;
@@ -2734,6 +2734,20 @@ ppc_elf_add_symbol_hook (bfd *abfd,
   return TRUE;
 }
 \f
+static bfd_boolean
+create_sdata_sym (struct ppc_elf_link_hash_table *htab,
+                 elf_linker_section_t *lsect)
+{
+  lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
+                                    TRUE, FALSE, TRUE);
+  if (lsect->sym == NULL)
+    return FALSE;
+  if (lsect->sym->root.type == bfd_link_hash_new)
+    lsect->sym->non_elf = 0;
+  lsect->sym->ref_regular = 1;
+  return TRUE;
+}
+
 /* Create a special linker section.  */
 
 static bfd_boolean
@@ -2760,7 +2774,7 @@ ppc_elf_create_linker_section (bfd *abfd,
     return FALSE;
   lsect->section = s;
 
-  return TRUE;
+  return create_sdata_sym (htab, lsect);
 }
 
 /* Find a linker generated pointer with a given addend and type.  */
@@ -3090,6 +3104,11 @@ ppc_elf_check_relocs (bfd *abfd,
          if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
                                                  h, rel))
            return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
          break;
 
          /* Indirect .sdata2 relocation.  */
@@ -3106,12 +3125,65 @@ ppc_elf_check_relocs (bfd *abfd,
          if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
                                                  h, rel))
            return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
          break;
 
        case R_PPC_SDAREL16:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[0].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[0]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_SDA2REL:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[1].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[1]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_SDA21:
        case R_PPC_EMB_RELSDA:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[0].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[0]))
+           return FALSE;
+         if (htab->sdata[1].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[1]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_NADDR32:
        case R_PPC_EMB_NADDR16:
        case R_PPC_EMB_NADDR16_LO:
@@ -3123,11 +3195,7 @@ ppc_elf_check_relocs (bfd *abfd,
              return FALSE;
            }
          if (h != NULL)
-           {
-             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
-             /* We may need a copy reloc.  */
-             h->non_got_ref = TRUE;
-           }
+           h->non_got_ref = TRUE;
          break;
 
        case R_PPC_PLT32:
@@ -3728,8 +3796,12 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
+         if (info->shared)
+           break;
+
        case R_PPC_PLT32:
        case R_PPC_PLTREL24:
+       case R_PPC_PLTREL32:
        case R_PPC_PLT16_LO:
        case R_PPC_PLT16_HI:
        case R_PPC_PLT16_HA:
@@ -4042,24 +4114,6 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   /* This is a reference to a symbol defined by a dynamic object which
      is not a function.  */
 
-  /* First, a fudge for old shared libs that export some symbols they
-     should not.  */
-  if (!h->def_regular
-      && (strcmp (h->root.root.string, "_SDA_BASE_") == 0
-         || strcmp (h->root.root.string, "_SDA2_BASE_") == 0))
-    {
-      /* These symbols will be defined later, as if they were defined in
-        a linker script.  We don't want to use a definition in a shared
-        object.  */
-      const struct elf_backend_data *bed;
-
-      bed = get_elf_backend_data (htab->elf.dynobj);
-      (*bed->elf_backend_hide_symbol) (info, h, TRUE);
-      h->root.type = bfd_link_hash_undefined;
-      h->root.u.undef.abfd = htab->elf.dynobj;
-      return TRUE;
-    }
-
   /* If we are creating a shared library, we must presume that the
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
@@ -4093,6 +4147,13 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
        }
     }
 
+  if (h->size == 0)
+    {
+      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
+                            h->root.root.string);
+      return TRUE;
+    }
+
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
      an entry for this symbol in the .dynsym section.  The dynamic
@@ -4646,15 +4707,13 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 
   if (htab->is_vxworks)
     {
-      /* Save the GOT and PLT symbols in the hash table for easy access.
-        Mark them as having relocations; they might not, but we won't
-        know for sure until we build the GOT in finish_dynamic_symbol.  */
+      /* Save the PLT symbol in the hash table for easy access.
+        Mark GOT and PLT syms as having relocations; they might not,
+        but we won't know for sure until we build the GOT in
+        finish_dynamic_symbol.  */
 
-      htab->hgot = elf_link_hash_lookup (elf_hash_table (info),
-                                        "_GLOBAL_OFFSET_TABLE_",
-                                        FALSE, FALSE, FALSE);
-      if (htab->hgot)
-       htab->hgot->indx = -2;
+      if (htab->elf.hgot)
+       htab->elf.hgot->indx = -2;
       htab->hplt = elf_link_hash_lookup (elf_hash_table (info),
                                         "_PROCEDURE_LINKAGE_TABLE_",
                                         FALSE, FALSE, FALSE);
@@ -4672,14 +4731,17 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
     {
       unsigned int g_o_t = 32768;
 
-      /* If we haven't allocated the header, do so now.  */
+      /* If we haven't allocated the header, do so now.  When we get here,
+        for old plt/got the got size will be 0 to 32764 (not allocated),
+        or 32780 to 65536 (header allocated).  For new plt/got, the
+        corresponding ranges are 0 to 32768 and 32780 to 65536.  */
       if (htab->got->size <= 32768)
        {
          g_o_t = htab->got->size;
+         if (htab->old_plt)
+           g_o_t += 4;
          htab->got->size += htab->got_header_size;
        }
-      if (htab->old_plt && !htab->is_vxworks)
-       g_o_t += 4;
 
       htab->elf.hgot->root.u.def.value = g_o_t;
     }
@@ -5254,64 +5316,19 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
-   set here rather than via PROVIDE in the default linker script,
-   because using PROVIDE inside an output section statement results in
-   unnecessary output sections.  Using PROVIDE outside an output section
-   statement runs the risk of section alignment affecting where the
-   section starts.  */
+/* What to do when ld finds relocations against symbols defined in
+   discarded sections.  */
 
-bfd_boolean
-ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
+static unsigned int
+ppc_elf_action_discarded (asection *sec)
 {
-  struct ppc_elf_link_hash_table *htab;
-  unsigned i;
-  asection *s;
-  bfd_vma val;
-
-  htab = ppc_elf_hash_table (info);
-
-  for (i = 0; i < 2; i++)
-    {
-      elf_linker_section_t *lsect = &htab->sdata[i];
+  if (strcmp (".fixup", sec->name) == 0)
+    return 0;
 
-      s = lsect->section;
-      if (s != NULL)
-       s = s->output_section;
-      if (s == NULL)
-       s = bfd_get_section_by_name (obfd, lsect->name);
-      if (s == NULL)
-       s = bfd_get_section_by_name (obfd, lsect->bss_name);
+  if (strcmp (".got2", sec->name) == 0)
+    return 0;
 
-      if (s)
-       {
-         /* VxWorks executables are relocatable, so the sdata base symbols
-            must be section-relative.  If the section is zero sized leave
-            them as absolute symbols to avoid creationg an unused
-            output section.  */
-         val = 32768;
-         lsect->sym_val = val + s->vma;
-         if (s->size == 0)
-           {
-             val += s->vma;
-             s = NULL;
-           }
-       }
-      else
-       {
-         val = 0;
-         lsect->sym_val = 0;
-       }
-
-      _bfd_elf_provide_symbol (info, lsect->sym_name, val, s);
-    }
-
-  s = bfd_get_section_by_name (obfd, ".sbss");
-  _bfd_elf_provide_section_bound_symbols (info, s,
-                                         "__sbss_start", "__sbss_end");
-  _bfd_elf_provide_section_bound_symbols (info, s,
-                                         "___sbss_start", "___sbss_end");
-  return TRUE;
+  return _bfd_elf_default_action_discarded (sec);
 }
 \f
 /* Fill in the address for a pointer generated in a linker section.  */
@@ -6342,6 +6359,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_SDAREL16:
          {
            const char *name;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
@@ -6358,7 +6376,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
                   howto->name,
                   name);
              }
-           addend -= htab->sdata[0].sym_val;
+           sh = htab->sdata[0].sym;
+           addend -= (sh->root.u.def.value
+                      + sh->root.u.def.section->output_offset
+                      + sh->root.u.def.section->output_section->vma);
          }
          break;
 
@@ -6366,6 +6387,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_EMB_SDA2REL:
          {
            const char *name;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
@@ -6384,7 +6406,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
                ret = FALSE;
                continue;
              }
-           addend -= htab->sdata[1].sym_val;
+           sh = htab->sdata[1].sym;
+           addend -= (sh->root.u.def.value
+                      + sh->root.u.def.section->output_offset
+                      + sh->root.u.def.section->output_section->vma);
          }
          break;
 
@@ -6394,6 +6419,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            const char *name;
            int reg;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
@@ -6403,14 +6429,20 @@ ppc_elf_relocate_section (bfd *output_bfd,
                     && (name[5] == 0 || name[5] == '.'))))
              {
                reg = 13;
-               addend -= htab->sdata[0].sym_val;
+               sh = htab->sdata[0].sym;
+               addend -= (sh->root.u.def.value
+                          + sh->root.u.def.section->output_offset
+                          + sh->root.u.def.section->output_section->vma);
              }
 
            else if (strncmp (name, ".sdata2", 7) == 0
                     || strncmp (name, ".sbss2", 6) == 0)
              {
                reg = 2;
-               addend -= htab->sdata[1].sym_val;
+               sh = htab->sdata[1].sym;
+               addend -= (sh->root.u.def.value
+                          + sh->root.u.def.section->output_offset
+                          + sh->root.u.def.section->output_section->vma);
              }
 
            else if (strcmp (name, ".PPC.EMB.sdata0") == 0
@@ -6672,10 +6704,11 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                  }
                else
                  {
-                   bfd_vma got_loc = (got_offset
-                       + htab->hgot->root.u.def.value
-                       + htab->hgot->root.u.def.section->output_offset
-                       + htab->hgot->root.u.def.section->output_section->vma);
+                   bfd_vma got_loc
+                     = (got_offset
+                        + htab->elf.hgot->root.u.def.value
+                        + htab->elf.hgot->root.u.def.section->output_offset
+                        + htab->elf.hgot->root.u.def.section->output_section->vma);
                    bfd_vma got_loc_hi = (got_loc >> 16)
                                         + ((got_loc & 0x8000) >> 15);
 
@@ -6736,7 +6769,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->plt->output_section->vma
                                     + htab->plt->output_offset
                                     + ent->plt.offset + 2);
-                   rela.r_info = ELF32_R_INFO (htab->hgot->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_HA);
                    rela.r_addend = got_offset;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -6746,7 +6779,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->plt->output_section->vma
                                     + htab->plt->output_offset
                                     + ent->plt.offset + 6);
-                   rela.r_info = ELF32_R_INFO (htab->hgot->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_LO);
                    rela.r_addend = got_offset;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -7037,7 +7070,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       unsigned char *p = htab->got->contents;
       bfd_vma val;
 
-      p += elf_hash_table (info)->hgot->root.u.def.value;
+      p += htab->elf.hgot->root.u.def.value;
       if (htab->old_plt && !htab->is_vxworks)
        bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
 
@@ -7060,9 +7093,9 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       if (!info->shared)
        {
          bfd_vma got_value =
-           (htab->hgot->root.u.def.section->output_section->vma
-            + htab->hgot->root.u.def.section->output_offset
-            + htab->hgot->root.u.def.value);
+           (htab->elf.hgot->root.u.def.section->output_section->vma
+            + htab->elf.hgot->root.u.def.section->output_offset
+            + htab->elf.hgot->root.u.def.value);
          bfd_vma got_hi = (got_value >> 16) + ((got_value & 0x8000) >> 15);
 
          bfd_put_32 (output_bfd, plt_entry[0] | (got_hi & 0xffff),
@@ -7093,7 +7126,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          rela.r_offset = (htab->plt->output_section->vma
                           + htab->plt->output_offset
                           + 2);
-         rela.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_HA);
+         rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
          rela.r_addend = 0;
          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
          loc += sizeof (Elf32_External_Rela);
@@ -7102,7 +7135,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          rela.r_offset = (htab->plt->output_section->vma
                           + htab->plt->output_offset
                           + 6);
-         rela.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_LO);
+         rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
          rela.r_addend = 0;
          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
          loc += sizeof (Elf32_External_Rela);
@@ -7115,12 +7148,12 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
              Elf_Internal_Rela rel;
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_HA);
+             rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_LO);
+             rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
 
@@ -7370,6 +7403,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_write_section              ppc_elf_write_section
 #define elf_backend_get_sec_type_attr          ppc_elf_get_sec_type_attr
 #define elf_backend_plt_sym_val                        ppc_elf_plt_sym_val
+#define elf_backend_action_discarded           ppc_elf_action_discarded
 
 #include "elf32-target.h"
 
This page took 0.030568 seconds and 4 git commands to generate.