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 9f1bb70bd1fb6b22eb4b70b3bb59d7297d24986a..57a818923a05bda5793a525b159e05de61f9dfc5 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 51c8d7e0832167a50a37f471572003cb6d4b8146..2170da0bdfa61b0181c6967adcc49534d7fdbc1f 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 f7b0fffa18cf3dc73395dc49711f304f0d339d48..d765dd4d6812a6ba9b8d8eb2fb58a933cbf640ed 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 65b593a6b84560ebbf6d5f4d823433f3230a0096..c21d45a4fbc5e96dd392f0cdbce3e59d7a88aa8c 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 df08dd4ff3e59f70e4f1e8cdab23a6aae187a240..fcb22c431c5d4f499ccc06ffe21ec6da44a77386 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 586f4c90a6fb26762d206b2282ab7e35105c52e6..fa52bc9de7426763c594941300517f8638300a77 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 f3e5e42d4011adee2fe7da69c7391802ff428342..856bef1b1b1813affaf77648ce7b1b438e2f5275 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 495d55a199a87e21070e133ac8ba6e16f856d663..5f2084662d13b2c7339717087500598ef20e90d9 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 d15f50b679d59944010ec799fee8b75088840d33..95d98eb49c1afd58b9fc96f9b870942fda8aa6eb 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 1aa785bec43832dafa6cacfd05315f727b839ef2..c700b7efa6bc31baf7957163199bef7d3a6e22a1 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 9fc884e2d6e2ee5ac36b346ef6ab146c3f04d582..170b61a7396d5c382e9fc798ce9a57796b54693d 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 1223d2770acfe1aeaefebd4fbe529766a70f0509..1569e93c5b8f9b0c64d8c4b436e79a3ed4536e83 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 498171cba894fad222c80d9f48a08681b5f1b81c..c8611702d870dcada7892e738187bb2f0e502e95 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 f2153415cb39c7570e339cd3e9aede9e5ef31a8d..cb775bb2d443dea516a9f1c758447fc34da9e9a3 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 57802e8ac3f32a7565aa924abc56db8e809fdf94..faa9b786120f7f65765ab58c1e341b6d82dcafd9 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 176764ae816fd3e51db5100de54d0b0da0094167..af333ac542b7c10a370cbba1e1735cbdad8af892 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 5f170127bb98fe273cb32723aa099e9de83e9d2b..33a03820a068608df394625de24a7767c0b7afb5 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 3f933e47ff0271b1e8584f72ae38af127c43a71f..783355c137a10a87eb4976370d32c3871ff174b7 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 a34bc4c786c34494f08de086880324636f3061a8..ccddad6955631b426047ceb9ab02449085358705 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
 }