LD/ELF: Unify STB_GNU_UNIQUE handling
authorMaciej W. Rozycki <macro@imgtec.com>
Mon, 16 May 2016 07:51:26 +0000 (08:51 +0100)
committerMaciej W. Rozycki <macro@imgtec.com>
Tue, 17 May 2016 11:21:40 +0000 (12:21 +0100)
Take STB_GNU_UNIQUE handling scattered across targets and gather it in
the generic ELF linker.  Update test suite infrastructure accordingly.

bfd/
* elf-s390-common.c (elf_s390_add_symbol_hook): Remove
STB_GNU_UNIQUE handling.
* elf32-arc.c (elf_arc_add_symbol_hook): Likewise.
* elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Likewise.
* elf32-i386.c (elf_i386_add_symbol_hook): Remove function.
(elf_backend_add_symbol_hook): Remove macro.
* elflink.c (elf_link_add_object_symbols): Set `has_gnu_symbols'
for STB_GNU_UNIQUE symbols.

binutils/
* testsuite/lib/binutils-common.exp (supports_gnu_unique): New
procedure.
* testsuite/binutils-all/objcopy.exp: Use `supports_gnu_unique'
with the `strip-10' test.

ld/
* testsuite/ld-unique/unique.exp: Use `is_elf_format' and
`supports_gnu_unique' to qualify testing.

19 files changed:
bfd/ChangeLog
bfd/elf-s390-common.c
bfd/elf32-arc.c
bfd/elf32-arm.c
bfd/elf32-i386.c
bfd/elf32-m68k.c
bfd/elf32-ppc.c
bfd/elf32-sparc.c
bfd/elf64-ppc.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elfxx-aarch64.c
bfd/elfxx-mips.c
binutils/ChangeLog
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/lib/binutils-common.exp
ld/ChangeLog
ld/testsuite/ld-unique/unique.exp

index 9f1bb70..57a8189 100644 (file)
@@ -1,3 +1,22 @@
+2016-05-17  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * elf-s390-common.c (elf_s390_add_symbol_hook): Remove
+       STB_GNU_UNIQUE handling.
+       * elf32-arc.c (elf_arc_add_symbol_hook): Likewise.
+       * elf32-arm.c (elf32_arm_add_symbol_hook): Likewise.
+       * elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
+       * elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
+       * elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
+       * elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
+       * elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
+       * elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
+       * elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
+       * elfxx-mips.c (_bfd_mips_elf_add_symbol_hook): Likewise.
+       * elf32-i386.c (elf_i386_add_symbol_hook): Remove function.
+       (elf_backend_add_symbol_hook): Remove macro.
+       * elflink.c (elf_link_add_object_symbols): Set `has_gnu_symbols'
+       for STB_GNU_UNIQUE symbols.
+
 2016-05-16  Maciej W. Rozycki  <macro@imgtec.com>
 
        * elf32-v850.c (v850_elf_copy_notes): New function, factored out
index 51c8d7e..2170da0 100644 (file)
@@ -236,11 +236,10 @@ elf_s390_add_symbol_hook (bfd *abfd,
                          asection **secp ATTRIBUTE_UNUSED,
                          bfd_vma *valp ATTRIBUTE_UNUSED)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
index f7b0fff..d765dd4 100644 (file)
@@ -2742,11 +2742,10 @@ elf_arc_add_symbol_hook (bfd * abfd,
                         asection ** secp ATTRIBUTE_UNUSED,
                         bfd_vma * valp ATTRIBUTE_UNUSED)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
index 65b593a..c21d45a 100644 (file)
@@ -17725,11 +17725,10 @@ elf32_arm_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
                           Elf_Internal_Sym *sym, const char **namep,
                           flagword *flagsp, asection **secp, bfd_vma *valp)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   if (elf32_arm_hash_table (info) == NULL)
     return FALSE;
index df08dd4..fcb22c4 100644 (file)
@@ -5795,27 +5795,6 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h)
   return _bfd_elf_hash_symbol (h);
 }
 
-/* Hook called by the linker routine which adds symbols from an object
-   file.  */
-
-static bfd_boolean
-elf_i386_add_symbol_hook (bfd * abfd,
-                         struct bfd_link_info * info,
-                         Elf_Internal_Sym * sym,
-                         const char ** namep ATTRIBUTE_UNUSED,
-                         flagword * flagsp ATTRIBUTE_UNUSED,
-                         asection ** secp ATTRIBUTE_UNUSED,
-                         bfd_vma * valp ATTRIBUTE_UNUSED)
-{
-  if (ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE
-      && (abfd->flags & DYNAMIC) == 0
-      && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols
-      |= elf_gnu_symbol_unique;
-
-  return TRUE;
-}
-
 #define TARGET_LITTLE_SYM              i386_elf32_vec
 #define TARGET_LITTLE_NAME             "elf32-i386"
 #define ELF_ARCH                       bfd_arch_i386
@@ -5863,7 +5842,6 @@ elf_i386_add_symbol_hook (bfd * abfd,
 #define elf_backend_omit_section_dynsym \
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
 #define elf_backend_hash_symbol                      elf_i386_hash_symbol
-#define elf_backend_add_symbol_hook           elf_i386_add_symbol_hook
 #define elf_backend_fixup_symbol             elf_i386_fixup_symbol
 
 #include "elf32-target.h"
@@ -6053,9 +6031,6 @@ elf32_iamcu_elf_object_p (bfd *abfd)
 #undef  elf_backend_strtab_flags
 #undef  elf_backend_copy_special_section_fields
 
-#undef elf_backend_add_symbol_hook
-#define elf_backend_add_symbol_hook    elf_i386_add_symbol_hook
-
 #include "elf32-target.h"
 
 /* Restore defaults.  */
index 586f4c9..fa52bc9 100644 (file)
@@ -4839,11 +4839,10 @@ elf_m68k_add_symbol_hook (bfd *abfd,
                          asection **secp ATTRIBUTE_UNUSED,
                          bfd_vma *valp ATTRIBUTE_UNUSED)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
index f3e5e42..856bef1 100644 (file)
@@ -3674,11 +3674,10 @@ ppc_elf_add_symbol_hook (bfd *abfd,
       *valp = sym->st_size;
     }
 
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
index 495d55a..5f20846 100644 (file)
@@ -180,11 +180,10 @@ elf32_sparc_add_symbol_hook (bfd * abfd,
                             asection ** secp ATTRIBUTE_UNUSED,
                             bfd_vma * valp ATTRIBUTE_UNUSED)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
   return TRUE;
 }
 
index d15f50b..95d98eb 100644 (file)
@@ -4894,11 +4894,10 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
                           asection **sec,
                           bfd_vma *value)
 {
-  if ((ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
       && (ibfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   if (*sec != NULL
       && strcmp ((*sec)->name, ".opd") == 0)
index 1aa785b..c700b7e 100644 (file)
@@ -426,11 +426,10 @@ elf64_sparc_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
 {
   static const char *const stt_types[] = { "NOTYPE", "OBJECT", "FUNCTION" };
 
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   if (ELF_ST_TYPE (sym->st_info) == STT_REGISTER)
     {
index 9fc884e..170b61a 100644 (file)
@@ -6277,7 +6277,7 @@ elf_x86_64_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr,
 
 static bfd_boolean
 elf_x86_64_add_symbol_hook (bfd *abfd,
-                           struct bfd_link_info *info,
+                           struct bfd_link_info *info ATTRIBUTE_UNUSED,
                            Elf_Internal_Sym *sym,
                            const char **namep ATTRIBUTE_UNUSED,
                            flagword *flagsp ATTRIBUTE_UNUSED,
@@ -6306,12 +6306,6 @@ elf_x86_64_add_symbol_hook (bfd *abfd,
       return TRUE;
     }
 
-  if (ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE
-      && (abfd->flags & DYNAMIC) == 0
-      && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols
-      |= elf_gnu_symbol_unique;
-
   return TRUE;
 }
 
index 1223d27..1569e93 100644 (file)
@@ -4380,6 +4380,11 @@ error_free_dyn:
              (struct bfd_link_hash_entry **) sym_hash)))
        goto error_free_vers;
 
+      if ((flags & BSF_GNU_UNIQUE)
+         && (abfd->flags & DYNAMIC) == 0
+         && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
+       elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_unique;
+
       h = *sym_hash;
       /* We need to make sure that indirect symbol dynamic flags are
         updated.  */
index 498171c..c861170 100644 (file)
@@ -538,11 +538,10 @@ _bfd_aarch64_elf_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
                                  asection **secp ATTRIBUTE_UNUSED,
                                  bfd_vma *valp ATTRIBUTE_UNUSED)
 {
-  if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
-       || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
       && (abfd->flags & DYNAMIC) == 0
       && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
+    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
 
   return TRUE;
 }
index f215341..cb775bb 100644 (file)
@@ -7526,11 +7526,6 @@ _bfd_mips_elf_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
       mips_elf_hash_table (info)->rld_symbol = h;
     }
 
-  if (ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE
-      && (abfd->flags & DYNAMIC) == 0
-      && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
-    elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_unique;
-
   /* If this is a mips16 text symbol, add 1 to the value to make it
      odd.  This will cause something like .word SYM to come up with
      the right value when it is loaded into the PC.  */
index 57802e8..faa9b78 100644 (file)
@@ -1,3 +1,10 @@
+2016-05-17  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * testsuite/lib/binutils-common.exp (supports_gnu_unique): New
+       procedure.
+       * testsuite/binutils-all/objcopy.exp: Use `supports_gnu_unique'
+       with the `strip-10' test.
+
 2016-05-16  Maciej W. Rozycki  <macro@imgtec.com>
 
        * testsuite/binutils-all/objcopy.exp: Don't skip the `strip-10'
index 176764a..af333ac 100644 (file)
@@ -1060,11 +1060,8 @@ if [is_elf_format] {
     run_dump_test "strip-8"
     run_dump_test "strip-9"
     run_dump_test "strip-12"
-    # Non-EABI ARM targets will set OSABI to ARM
-    if { ![istarget "*-*-hpux*"]
-        && ![istarget "msp*-*-*"]
-        && ![istarget "visium-*-*"]
-         && !([istarget "arm*-*-*"] && ![istarget "arm-*-*eabi*"])} {
+    # This requires STB_GNU_UNIQUE support with OSABI set to GNU.
+    if { [supports_gnu_unique] } {
        run_dump_test "strip-10"
     }
     set extra_strip11 ""
index 5f17012..33a0382 100644 (file)
@@ -162,6 +162,46 @@ proc is_elf64 { binary_file } {
     return 0
 }
 
+# True if the ELF target supports STB_GNU_UNIQUE with the ELF header's
+# OSABI field set to ELFOSABI_GNU.
+#
+# This generally depends on the target OS only, however there are a
+# number of exceptions for bare metal targets as follows.  The MSP430
+# and Visium targets set OSABI to ELFOSABI_STANDALONE and cannot
+# support STB_GNU_UNIQUE.  Likewise non-EABI ARM targets set OSABI to
+# ELFOSABI_ARM, and TI C6X targets to ELFOSABI_C6000_*.  Finally
+# rather than `bfd_elf_final_link' AM33/2.0, D30V, DLX, i960, and
+# picoJava targets use `_bfd_generic_final_link', which does not
+# support STB_GNU_UNIQUE symbol binding causing assertion failures.
+#
+proc supports_gnu_unique {} {
+    if { [istarget *-*-gnu*]
+        || [istarget *-*-linux*]
+        || [istarget *-*-nacl*] } {
+       return 1
+    }
+    if { [istarget "arm*-*-*eabi*"] } {
+       return 1
+    }
+    if { ![istarget "*-*-elf*"] } {
+       return 0
+    }
+    if { [istarget "arm*-*-*"]
+        || [istarget "msp430-*-*"]
+        || [istarget "tic6x-*-*"]
+        || [istarget "visium-*-*"] } {
+       return 0
+    }
+    if { [istarget "am33_2.0-*-*"]
+        || [istarget "d30v-*-*"]
+        || [istarget "dlx-*-*"]
+        || [istarget "i960-*-*"]
+        || [istarget "pj*-*-*"] } {
+       return 0
+    }
+    return 1
+}
+
 # Compare two files line-by-line.  FILE_1 is the actual output and FILE_2
 # is the expected output.  Ignore blank lines in either file.
 #
index 3f933e4..783355c 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-17  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * testsuite/ld-unique/unique.exp: Use `is_elf_format' and
+       `supports_gnu_unique' to qualify testing.
+
 2016-05-16  Maciej W. Rozycki  <macro@imgtec.com>
 
        * testsuite/ld-elf/flags1.d: Update the xfail list.
index a34bc4c..ccddad6 100644 (file)
 # Adapted for unique checking by Mark J. Wielaard <mjw@redhat.com>
 
 
-# STB_GNU_UNIQUE support has only been implemented for the ix86, x86_64,
-# arm, mips, powerpc, and sparc so far.
-if {!(([istarget "i?86-*-*"]
-       || [istarget "x86_64-*-*"]
-       || [istarget "arm*-*-*"]
-       || [istarget "mips*-*-*"]
-       || [istarget "powerpc*-*-*"]
-       || [istarget "sparc*-*-*"])
-      && ([istarget "*-*-elf*"]
-         || [istarget "*-*-nacl*"]
-         || (([istarget "*-*-linux*"]
-              || [istarget "*-*-gnu*"])
-             && ![istarget "*-*-*aout*"]
-             && ![istarget "*-*-*oldld*"]))) } {
+# Exclude non-ELF targets.
+if { ![is_elf_format] } {
+    return
+}
+
+# Require STB_GNU_UNIQUE support with OSABI set to GNU.
+if { ![supports_gnu_unique] } {
     verbose "UNIQUE tests not run - target does not support UNIQUE"
     return
 }