]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Set ELF_OSABI for x86 and sparc
authorAlan Modra <amodra@gmail.com>
Sat, 3 Jan 2026 03:26:01 +0000 (13:56 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 4 Jan 2026 09:00:16 +0000 (19:30 +1030)
The idea of this patch is to match the solaris target over other
targets if e_ident contains ELFOSABI_SOLARIS.  The solaris target will
continue to recognise ELFOSABI_NONE objects.

This has the side effect of disabling gnu features that require
ELFOSABI_GNU, such as ifuncs.  I think that is correct, so I've made
the required testsuite changes to fix the resulting regressions:
FAIL: nm --ifunc-chars (assembly)
FAIL: mbind sections without SHF_ALLOC

The patch also sets ELF_OSABI for the gnu x86 and sparc targets,
for the same reason as the solaris targets.  This doesn't mean object
files will automatically be marked ELFOSABI_GNU/LINUX.  As before that
will only happen when certain GNU extensions are present.

bfd/
* elf32-i386.c: Define ELF_OSABI for solaris and gnu targets.
* elf32-sparc.c: Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* format.c (bfd_check_format_matches): Bump match_priority
for matching e_ident EI_OSABI.
binutils/
* testsuite/binutils-all/nm.exp: Use !supports_gnu_osabi to
disable ifunc test.
gas/
* testsuite/gas/elf/section13.d: Only run on supports_gnu_osabi
targets.  Remove xfails.

bfd/elf32-i386.c
bfd/elf32-sparc.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/format.c
binutils/testsuite/binutils-all/nm.exp
gas/testsuite/gas/elf/section13.d

index be8c676c833145d8d2504be9063cbd700ec58668..c2b3c7dd16530fdd64579dd60bef3121760ff85d 100644 (file)
@@ -4564,6 +4564,7 @@ elf_i386_add_glibc_version_dependency
 #define ELF_TARGET_ID                  I386_ELF_DATA
 #define ELF_MACHINE_CODE               EM_386
 #define ELF_MAXPAGESIZE                        0x1000
+#define        ELF_OSABI                       ELFOSABI_GNU
 
 #define elf_backend_can_gc_sections    1
 #define elf_backend_can_refcount       1
@@ -4664,9 +4665,8 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
 #undef ELF_TARGET_OS
 #define        ELF_TARGET_OS                   is_solaris
 
-/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
-   objects won't be recognized.  */
 #undef ELF_OSABI
+#define ELF_OSABI                      ELFOSABI_SOLARIS
 #undef ELF_OSABI_EXACT
 
 #undef elf32_bed
@@ -4711,6 +4711,7 @@ elf32_iamcu_elf_object_p (bfd *abfd)
 
 #undef ELF_TARGET_OS
 #undef ELF_OSABI
+#define        ELF_OSABI                       ELFOSABI_GNU
 #undef ELF_OSABI_EXACT
 
 #undef  elf32_bed
index 421549a7a33e756faecf5bc2815b3196420460f8..b61b4bb9fb79c94c4749252a748e26917a3c6cd3 100644 (file)
@@ -221,6 +221,7 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
 #define ELF_TARGET_ID  SPARC_ELF_DATA
 #define ELF_MACHINE_CODE EM_SPARC
 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
+#define ELF_OSABI      ELFOSABI_GNU
 #define ELF_MAXPAGESIZE 0x10000
 #define ELF_COMMONPAGESIZE 0x2000
 
@@ -282,6 +283,9 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
 
 #undef  ELF_TARGET_OS
 #define ELF_TARGET_OS                          is_solaris
+#undef ELF_OSABI
+#define        ELF_OSABI                               ELFOSABI_SOLARIS
+#undef ELF_OSABI_EXACT
 
 #undef  elf32_bed
 #define elf32_bed                              elf32_sparc_sol2_bed
@@ -327,6 +331,8 @@ elf32_sparc_vxworks_final_write_processing (bfd *abfd)
 
 #undef ELF_TARGET_OS
 #define        ELF_TARGET_OS   is_vxworks
+#undef ELF_OSABI
+#undef ELF_OSABI_EXACT
 
 #undef  elf_backend_want_got_plt
 #define elf_backend_want_got_plt               1
index cf0826f52b8abe3bbc4e30e2d00a44c2c8325532..16de1562bd8a6f46ea273ef226404ea9be2676d3 100644 (file)
@@ -888,6 +888,7 @@ static const struct elf_size_info elf64_sparc_size_info =
 #define TARGET_BIG_NAME        "elf64-sparc"
 #define ELF_ARCH       bfd_arch_sparc
 #define ELF_TARGET_ID  SPARC_ELF_DATA
+#define ELF_OSABI      ELFOSABI_GNU
 #define ELF_MAXPAGESIZE 0x100000
 #define ELF_COMMONPAGESIZE 0x2000
 
@@ -1011,10 +1012,8 @@ static const struct elf_size_info elf64_sparc_size_info =
 
 #undef  ELF_TARGET_OS
 #define ELF_TARGET_OS                          is_solaris
-
-/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
-   objects won't be recognized.  */
 #undef ELF_OSABI
+#define        ELF_OSABI                               ELFOSABI_SOLARIS
 #undef ELF_OSABI_EXACT
 
 #undef  elf64_bed
index 47d24e0e77625576f44f1dafce283fceda5413c4..84c558fd157c100ce89fbddcb3f81758223364ab 100644 (file)
@@ -6340,6 +6340,7 @@ elf_x86_64_special_sections[]=
 #define ELF_ARCH                           bfd_arch_i386
 #define ELF_TARGET_ID                      X86_64_ELF_DATA
 #define ELF_MACHINE_CODE                   EM_X86_64
+#define        ELF_OSABI                           ELFOSABI_GNU
 #define ELF_MAXPAGESIZE                            0x1000
 #define ELF_COMMONPAGESIZE                 ELF_MAXPAGESIZE
 
@@ -6447,9 +6448,8 @@ elf_x86_64_special_sections[]=
 #undef ELF_TARGET_OS
 #define        ELF_TARGET_OS                       is_solaris
 
-/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
-   objects won't be recognized.  */
 #undef ELF_OSABI
+#define ELF_OSABI                          ELFOSABI_SOLARIS
 #undef ELF_OSABI_EXACT
 
 #undef  elf64_bed
@@ -6493,6 +6493,7 @@ elf_x86_64_special_sections[]=
 
 #undef ELF_TARGET_OS
 #undef ELF_OSABI
+#define        ELF_OSABI                           ELFOSABI_GNU
 #undef ELF_OSABI_EXACT
 
 #define bfd_elf32_bfd_copy_private_section_data \
index 1a56a8915fc7fc60e2c9475c50642d02a0bb5975..f35230eb28b91c9814c6dd3a0a13fb833330d1c9 100644 (file)
@@ -47,6 +47,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "plugin.h"
+#include "elf-bfd.h"
 
 /* IMPORT from targets.c.  */
 extern const size_t _bfd_target_vector_entries;
@@ -626,8 +627,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
       if (cleanup)
        {
-         int match_priority = abfd->xvec->match_priority;
-
          if (abfd->format != bfd_archive
              || (bfd_has_map (abfd)
                  && bfd_get_error () != bfd_error_wrong_object_format))
@@ -641,6 +640,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
              matching_vector[match_count] = abfd->xvec;
              match_count++;
 
+             int match_priority = abfd->xvec->match_priority;
+             if (match_priority == 1
+                 && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+               {
+                 /* If the object e_ident matches the hint elf_osabi,
+                    bump priority up.  */
+                 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+                 elf_backend_data *bed = get_elf_backend_data (abfd);
+                 if (bed->elf_osabi != ELFOSABI_NONE
+                     && i_ehdrp->e_ident[EI_OSABI] == bed->elf_osabi)
+                   match_priority = 0;
+               }
              if (match_priority < best_match)
                {
                  best_match = match_priority;
index 005c0b7b22b762ccdd7654201cc3b1c1a9b9ed7a..367e8b6168bbc3a29dc1a3c621c1f31df6839d4f 100644 (file)
@@ -296,17 +296,13 @@ if [is_elf_format] {
     # PR 22967
     # Test nm --ifunc-chars on a indirect symbols.
     
-    # The following targets are known to not support ifuncs.
-    setup_xfail "alpha*-*-*"
-    setup_xfail "arm*-elf" "arm*-*-nto*" "arm*-*-netbsd*"
-    setup_xfail "*-*-hpux*"
-    setup_xfail "mips*-*-*" "tx39*-*-*"
-    setup_xfail "msp430*-*-*"
-    setup_xfail "kvx*-*-*"
-    setup_xfail "visium*-*-*"
-
     set testname "nm --ifunc-chars"
-    if {![binutils_assemble $srcdir/$subdir/ifunc.s tmpdir/ifunc.o]} then {
+    if { ![supports_gnu_osabi] \
+        || [istarget "alpha*-*-*"] \
+        || [istarget "kvx-*-*"] \
+        || [istarget "mips*-*-*"] } {
+       unsupported $testname
+    } elseif { ![binutils_assemble $srcdir/$subdir/ifunc.s tmpdir/ifunc.o] } {
        fail "$testname (assembly)"
     } else {
        if [is_remote host] {
index 06d9ddfb67a3fc0a7c06414f78b47a3b675139a0..534ad90513eaccdaf2e72067318a5632ad9fa79f 100644 (file)
@@ -1,4 +1,3 @@
 #name: mbind sections without SHF_ALLOC
 #error_output: section13.l
-#xfail: msp430-*-* visium-*-*
-#xfail: *-*-hpux*
+#target: [supports_gnu_osabi]