[binutils-gdb] Set ELF_OSABI for x86 and sparc
Alan Modra
amodra@sourceware.org
Sun Jan 4 22:35:32 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ff31f2e09db972e27e5460307318dae3e529d41d
commit ff31f2e09db972e27e5460307318dae3e529d41d
Author: Alan Modra <amodra@gmail.com>
Date: Sat Jan 3 13:56:01 2026 +1030
Set ELF_OSABI for x86 and sparc
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.
Diff:
---
bfd/elf32-i386.c | 5 +++--
bfd/elf32-sparc.c | 6 ++++++
bfd/elf64-sparc.c | 5 ++---
bfd/elf64-x86-64.c | 5 +++--
bfd/format.c | 15 +++++++++++++--
binutils/testsuite/binutils-all/nm.exp | 16 ++++++----------
gas/testsuite/gas/elf/section13.d | 3 +--
7 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index be8c676c833..c2b3c7dd165 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -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
diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c
index 421549a7a33..b61b4bb9fb7 100644
--- a/bfd/elf32-sparc.c
+++ b/bfd/elf32-sparc.c
@@ -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
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index cf0826f52b8..16de1562bd8 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -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
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 47d24e0e776..84c558fd157 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -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 \
diff --git a/bfd/format.c b/bfd/format.c
index 1a56a8915fc..f35230eb28b 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -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;
diff --git a/binutils/testsuite/binutils-all/nm.exp b/binutils/testsuite/binutils-all/nm.exp
index 005c0b7b22b..367e8b6168b 100644
--- a/binutils/testsuite/binutils-all/nm.exp
+++ b/binutils/testsuite/binutils-all/nm.exp
@@ -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] {
diff --git a/gas/testsuite/gas/elf/section13.d b/gas/testsuite/gas/elf/section13.d
index 06d9ddfb67a..534ad90513e 100644
--- a/gas/testsuite/gas/elf/section13.d
+++ b/gas/testsuite/gas/elf/section13.d
@@ -1,4 +1,3 @@
#name: mbind sections without SHF_ALLOC
#error_output: section13.l
-#xfail: msp430-*-* visium-*-*
-#xfail: *-*-hpux*
+#target: [supports_gnu_osabi]
More information about the Binutils-cvs
mailing list