* elfxx-mips.c (_bfd_mips_elf_merge_private_bfd_data): Improve
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index 6d544192987c587d60bd2bd525a5d86db633d042..81a4b62ccd2ceee68f4ce9ab11597c63da67181e 100644 (file)
@@ -16,8 +16,9 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   along with this program; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 /* This file is based on a preliminary PowerPC ELF ABI.  The
    information may not match the final PowerPC ELF ABI.  It includes
@@ -147,7 +148,11 @@ static bfd_boolean ppc_elf_grok_psinfo
 #define DTP_OFFSET     0x8000
 
 /* Will references to this symbol always reference the symbol
-   in this object?  */
+   in this object?  STV_PROTECTED is excluded from the visibility test
+   here so that function pointer comparisons work properly.  Since
+   function symbols not defined in an app are set to their .plt entry,
+   it's necessary for shared libs to also reference the .plt even
+   though the symbol is really local to the shared lib.  */
 #define SYMBOL_REFERENCES_LOCAL(INFO, H)                               \
   ((! INFO->shared                                                     \
     || INFO->symbolic                                                  \
@@ -157,7 +162,7 @@ static bfd_boolean ppc_elf_grok_psinfo
    && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
 
 /* Will _calls_ to this symbol always call the version in this object?  */
-#define SYMBOL_CALLS_LOCAL(INFO, H)                            \
+#define SYMBOL_CALLS_LOCAL(INFO, H)                                    \
   ((! INFO->shared                                                     \
     || INFO->symbolic                                                  \
     || H->dynindx == -1                                                        \
@@ -194,7 +199,7 @@ struct ppc_elf_link_hash_entry
   struct ppc_elf_dyn_relocs *dyn_relocs;
 
   /* Contexts in which symbol is used in the GOT (or TOC).
-     TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
+     TLS_GD .. TLS_TLS bits are or'd into the mask as the
      corresponding relocs are encountered during check_relocs.
      tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
      indicate the corresponding GOT entry type is not needed.  */
@@ -315,6 +320,12 @@ ppc_elf_link_hash_table_create (abfd)
   return &ret->elf.root;
 }
 
+/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
+   copying dynamic variables from a shared lib into an app's dynbss
+   section, and instead use a dynamic relocation to point into the
+   shared lib.  */
+#define ELIMINATE_COPY_RELOCS 1
+
 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
 
 static void
@@ -363,7 +374,18 @@ ppc_elf_copy_indirect_symbol (bed, dir, ind)
 
   edir->tls_mask |= eind->tls_mask;
 
-  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+  if (ELIMINATE_COPY_RELOCS
+      && ind->root.type != bfd_link_hash_indirect
+      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+    /* If called to transfer flags for a weakdef during processing
+       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+    dir->elf_link_hash_flags |=
+      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+                                  | ELF_LINK_HASH_REF_REGULAR
+                                  | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+  else
+    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 \f
 static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max];
@@ -1609,10 +1631,14 @@ ppc_elf_howto_init ()
 {
   unsigned int i, type;
 
-  for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
+  for (i = 0;
+       i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
+       i++)
     {
       type = ppc_elf_howto_raw[i].type;
-      BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0]));
+      if (type >= (sizeof (ppc_elf_howto_table)
+                  / sizeof (ppc_elf_howto_table[0])))
+       abort ();
       ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
     }
 }
@@ -1626,7 +1652,8 @@ ppc_elf_howto_init ()
    2/ The branch is predicted as not taken.
    3/ The branch is taken.
    4/ The branch is located in the last 5 words of a page.
-      (The EOP limit is 5 by default but may be specified as any value from 1-10.)
+      (The EOP limit is 5 by default but may be specified as any value
+      from 1-10.)
 
    Our software solution is to detect these problematic branches in a
    linker pass and modify them as follows:
@@ -2451,12 +2478,6 @@ ppc_elf_create_dynamic_sections (abfd, info)
   return bfd_set_section_flags (abfd, s, flags);
 }
 
-/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
-   copying dynamic variables from a shared lib into an app's dynbss
-   section, and instead use a dynamic relocation to point into the
-   shared lib.  */
-#define ELIMINATE_COPY_RELOCS 1
-
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
    dynamic object, but we're not including those sections.  We have to
@@ -2496,7 +2517,7 @@ ppc_elf_adjust_dynamic_symbol (info, h)
       /* Clear procedure linkage table information for any symbol that
         won't need a .plt entry.  */
       if (! htab->elf.dynamic_sections_created
-         || SYMBOL_CALLS_LOCAL (info, h)
+         || SYMBOL_CALLS_LOCAL (info, h)
          || h->plt.refcount <= 0)
        {
          /* A PLT entry is not required/allowed when:
@@ -2673,7 +2694,9 @@ allocate_dynrelocs (h, inf)
 
   htab = ppc_elf_hash_table (info);
   if (htab->elf.dynamic_sections_created
-      && h->plt.refcount > 0)
+      && h->plt.refcount > 0
+      && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+         || h->root.type != bfd_link_hash_undefweak))
     {
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1
@@ -2768,8 +2791,10 @@ allocate_dynrelocs (h, inf)
          else
            htab->got->_raw_size += 4;
          dyn = htab->elf.dynamic_sections_created;
-         if (info->shared
-             || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
+         if ((info->shared
+              || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
+             && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
+                 || eh->elf.root.type != bfd_link_hash_undefweak))
            {
              /* All the entries we allocated need relocs.  */
              htab->relgot->_raw_size
@@ -2810,6 +2835,12 @@ allocate_dynrelocs (h, inf)
                pp = &p->next;
            }
        }
+
+      /* Also discard relocs on undefined weak syms with non-default
+        visibility.  */
+      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+         && h->root.type == bfd_link_hash_undefweak)
+       eh->dyn_relocs = NULL;
     }
   else if (ELIMINATE_COPY_RELOCS)
     {
@@ -3459,8 +3490,7 @@ ppc_elf_check_relocs (abfd, info, sec, relocs)
        case R_PPC_REL14_BRNTAKEN:
        case R_PPC_REL32:
          if (h == NULL
-             || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
-             || SYMBOL_REFERENCES_LOCAL (info, h))
+             || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
            break;
          /* fall through */
 
@@ -3745,8 +3775,7 @@ ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
        case R_PPC_REL14_BRNTAKEN:
        case R_PPC_REL32:
          if (h == NULL
-             || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
-             || SYMBOL_REFERENCES_LOCAL (info, h))
+             || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
            break;
          /* Fall thru */
 
@@ -4774,7 +4803,10 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                      }
 
                    /* Generate relocs for the dynamic linker.  */
-                   if (info->shared || indx != 0)
+                   if ((info->shared || indx != 0)
+                       && (h == NULL
+                           || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                           || h->root.type != bfd_link_hash_undefweak))
                      {
                        outrel.r_offset = (htab->got->output_section->vma
                                           + htab->got->output_offset
@@ -4976,6 +5008,9 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          /* Fall thru.  */
 
          if ((info->shared
+              && (h == NULL
+                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                  || h->root.type != bfd_link_hash_undefweak)
               && (MUST_BE_DYN_RELOC (r_type)
                   || (h != NULL
                       && h->dynindx != -1
This page took 0.028402 seconds and 4 git commands to generate.