[binutils-gdb] x86: Add _bfd_elf_x86_copy_special_section_fields
H.J. Lu
hjl@sourceware.org
Tue Dec 9 23:21:04 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f5c3ce3687f7e1047c2f8a5c5dd9af2f36055663
commit f5c3ce3687f7e1047c2f8a5c5dd9af2f36055663
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Dec 9 07:33:28 2025 +0800
x86: Add _bfd_elf_x86_copy_special_section_fields
When Linux/x86 objcopy is used on Solaris binary, it sets EI_OSABI to
ELFOSABI_SOLARIS, but it doesn't set the sh_info and sh_link fields of
Solaris specific sections.
Add _bfd_elf_x86_copy_special_section_fields to return false for Solaris
binary to properly set the sh_info and sh_link fields of Solaris specific
sections.
PR binutils/33705
* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
Removed.
(elf_backend_copy_special_section_fields): Likewise.
* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
Likewise.
(elf_backend_copy_special_section_fields): Likewise.
* elfxx-x86.c (_bfd_elf_x86_copy_special_section_fields): New.
* elfxx-x86.h (_bfd_elf_x86_copy_special_section_fields): Likewise.
(elf_backend_copy_special_section_fields): Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diff:
---
bfd/elf32-i386.c | 81 ------------------------------------------------------
bfd/elf64-x86-64.c | 15 ----------
bfd/elfxx-x86.c | 11 ++++++++
bfd/elfxx-x86.h | 7 +++++
4 files changed, 18 insertions(+), 96 deletions(-)
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 755c2176fd2..dd2d49a2636 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -4684,86 +4684,6 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
-/* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
- has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
- FALSE otherwise. ISECTION is the best guess matching section from the
- input bfd IBFD, but it might be NULL. */
-
-static bool
-elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
- bfd *obfd ATTRIBUTE_UNUSED,
- const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
- Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
-{
- /* PR 19938: FIXME: Need to add code for setting the sh_info
- and sh_link fields of Solaris specific section types. */
- return false;
-
- /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
- Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
-
-http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
-
- The following values should be set:
-
-Type Link Info
------------------------------------------------------------------------------
-SHT_SUNW_ancillary The section header index of 0
- [0x6fffffee] the associated string table.
-
-SHT_SUNW_capinfo The section header index of For a dynamic object, the
- [0x6ffffff0] the associated symbol table. section header index of
- the associated
- SHT_SUNW_capchain table,
- otherwise 0.
-
-SHT_SUNW_symsort The section header index of 0
- [0x6ffffff1] the associated symbol table.
-
-SHT_SUNW_tlssort The section header index of 0
- [0x6ffffff2] the associated symbol table.
-
-SHT_SUNW_LDYNSYM The section header index of One greater than the
- [0x6ffffff3] the associated string table. symbol table index of the
- This index is the same string last local symbol,
- table used by the SHT_DYNSYM STB_LOCAL. Since
- section. SHT_SUNW_LDYNSYM only
- contains local symbols,
- sh_info is equivalent to
- the number of symbols in
- the table.
-
-SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
- [0x6ffffff5] the section header index of to named strings, the
- the associated section header index of
- SHT_SUNW_capinfo table, the associated string
- otherwise 0. table, otherwise 0.
-
-SHT_SUNW_move The section header index of 0
- [0x6ffffffa] the associated symbol table.
-
-SHT_SUNW_COMDAT 0 0
- [0x6ffffffb]
-
-SHT_SUNW_syminfo The section header index of The section header index
- [0x6ffffffc] the associated symbol table. of the associated
- .dynamic section.
-
-SHT_SUNW_verdef The section header index of The number of version
- [0x6ffffffd] the associated string table. definitions within the
- section.
-
-SHT_SUNW_verneed The section header index of The number of version
- [0x6ffffffe] the associated string table. dependencies within the
- section.
-
-SHT_SUNW_versym The section header index of 0
- [0x6fffffff] the associated symbol table. */
-}
-
-#undef elf_backend_copy_special_section_fields
-#define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
-
#include "elf32-target.h"
/* Intel MCU support. */
@@ -4804,7 +4724,6 @@ elf32_iamcu_elf_object_p (bfd *abfd)
#define elf_backend_want_plt_sym 0
#undef elf_backend_strtab_flags
-#undef elf_backend_copy_special_section_fields
#include "elf32-target.h"
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 3eb2fe0aefa..f39e0f66ba4 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -6467,20 +6467,6 @@ elf_x86_64_special_sections[]=
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
-static bool
-elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
- bfd *obfd ATTRIBUTE_UNUSED,
- const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
- Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
-{
- /* PR 19938: FIXME: Need to add code for setting the sh_info
- and sh_link fields of Solaris specific section types. */
- return false;
-}
-
-#undef elf_backend_copy_special_section_fields
-#define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields
-
#include "elf64-target.h"
/* Restore defaults. */
@@ -6489,7 +6475,6 @@ elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUS
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
#undef elf_backend_strtab_flags
-#undef elf_backend_copy_special_section_fields
/* 32bit x86-64 support. */
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 4495b3eb00b..6400d3e6473 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -4971,6 +4971,17 @@ _bfd_x86_elf_link_fixup_gnu_properties
}
}
+bool
+_bfd_elf_x86_copy_special_section_fields
+ (const bfd *ibfd, bfd *obfd ATTRIBUTE_UNUSED,
+ const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
+ Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
+{
+ /* Return false for Solaris binary to properly set the sh_info and
+ sh_link fields of Solaris specific sections. */
+ return elf_elfheader (ibfd)->e_ident[EI_OSABI] != ELFOSABI_SOLARIS;
+}
+
void
bfd_elf_linker_x86_set_options (struct bfd_link_info *info,
struct elf_linker_x86_params *params)
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 99ef9341563..1a355f0aba9 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -955,6 +955,11 @@ extern void _bfd_x86_elf_link_report_tls_invalid_section_error
(bfd *, asection *, Elf_Internal_Shdr *, struct elf_link_hash_entry *,
Elf_Internal_Sym *, reloc_howto_type *) ATTRIBUTE_HIDDEN;
+extern bool
+_bfd_elf_x86_copy_special_section_fields
+ (const bfd *, bfd *, const Elf_Internal_Shdr *,
+ Elf_Internal_Shdr *) ATTRIBUTE_HIDDEN;
+
#define bfd_elf64_mkobject \
_bfd_x86_elf_mkobject
#define bfd_elf32_mkobject \
@@ -1002,6 +1007,8 @@ extern void _bfd_x86_elf_link_report_tls_invalid_section_error
_bfd_elf_x86_finish_relative_relocs
#define elf_backend_get_reloc_section \
_bfd_elf_x86_get_reloc_section
+#define elf_backend_copy_special_section_fields \
+ _bfd_elf_x86_copy_special_section_fields
#define elf_backend_use_mmap true
#define ELF_P_ALIGN ELF_MINPAGESIZE
More information about the Binutils-cvs
mailing list