]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Add _bfd_elf_x86_copy_special_section_fields
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 8 Dec 2025 23:33:28 +0000 (07:33 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 9 Dec 2025 23:20:17 +0000 (07:20 +0800)
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>
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index 755c2176fd250f46b469ec0d9394a9d349091889..dd2d49a263655cafa645977574a5cc3596ef4609 100644 (file)
@@ -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"
 
index 3eb2fe0aefaa0bf22191cc6d56b7e38d4bcdab2c..f39e0f66ba43e408e3f45ce93fb23afe41ae0cfd 100644 (file)
@@ -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.  */
 
index 4495b3eb00bd4e2c9afddbedf954559b7f7ad634..6400d3e6473aacf0a61d2c846d8febd63a5a91d9 100644 (file)
@@ -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)
index 99ef934156348ab82bc80fb75291b281649c6bf2..1a355f0aba939037b63e5666512a688010a82268 100644 (file)
@@ -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