Solaris .strtab and .shstrtab flags

These sections have SHF_STRINGS in sh_flags on Solaris.  Commit
8486501545 in part implemented this variation by an elf_backend_data
field used to set the flags, but that only works of course if one of
the solaris targets is used.  Which in some ways is fair enough.  If
you want solaris support then it is reasonable to require the solaris
targets to be compiled in.  However if they are not the default, other
ELF targets may be used even when the solaris targets are compiled in,
because many ELF targets allow any ELFOSABI object to match.  (Which
is arguably a bug.)

So instead of the current scheme this patch implements the solaris
specific sh_flags in _bfd_elf_final_write_processing.  That way either
a solaris target being used, or ELFOSABI_SOLARIS in the object will
get the correct sh_flags.

	PR 19938
	* elf-bfd.h (struct elf_backend_data): Delete elf_strtab_flags.
	* elf.c	(_bfd_elf_final_write_processing): Handle solaris
	peculiarities here.
	(_bfd_elf_compute_section_file_positions): Leave shstrtab sh_flags
	zero, and don't re-zero other fields.
	(swap_out_syms): Similarly for sym strtab.
	* elflink.c (_bfd_elf_final_link): Likewise.
	* elf32-i386.c (elf_backend_strtab_flags): Don't define.
	* elf32-sparc.c: Likewise.
	* elf64-sparc.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfxx-target.h: Likewise.
This commit is contained in:
Alan Modra
2026-01-02 08:22:02 +10:30
parent 682332608d
commit 4bc3f403c5
8 changed files with 12 additions and 45 deletions

View File

@@ -1712,9 +1712,6 @@ struct elf_backend_data
/* Alignment for the PT_GNU_STACK segment. */
unsigned stack_align;
/* Flag bits to assign to a section of type SHT_STRTAB. */
unsigned long elf_strtab_flags;
/* This is TRUE if the linker should act like collect and gather
global constructors and destructors by name. This is TRUE for
MIPS ELF because the Irix 5 tools can not handle the .init

View File

@@ -4745,12 +4745,9 @@ _bfd_elf_compute_section_file_positions (bfd *abfd,
shstrtab_hdr = &elf_tdata (abfd)->shstrtab_hdr;
/* sh_name was set in init_file_header. */
shstrtab_hdr->sh_type = SHT_STRTAB;
shstrtab_hdr->sh_flags = bed->elf_strtab_flags;
shstrtab_hdr->sh_addr = 0;
/* sh_flags, sh_addr, sh_entsize, sh_link, sh_info are all zeroed
when tdata is allocated. */
/* sh_size is set in _bfd_elf_assign_file_positions_for_non_load. */
shstrtab_hdr->sh_entsize = 0;
shstrtab_hdr->sh_link = 0;
shstrtab_hdr->sh_info = 0;
/* sh_offset is set in _bfd_elf_assign_file_positions_for_non_load. */
shstrtab_hdr->sh_addralign = 1;
@@ -9080,11 +9077,6 @@ Unable to handle section index %x in ELF symbol. Using ABS instead."),
*sttp = stt;
symstrtab_hdr->sh_size = _bfd_elf_strtab_size (stt);
symstrtab_hdr->sh_type = SHT_STRTAB;
symstrtab_hdr->sh_flags = bed->elf_strtab_flags;
symstrtab_hdr->sh_addr = 0;
symstrtab_hdr->sh_entsize = 0;
symstrtab_hdr->sh_link = 0;
symstrtab_hdr->sh_info = 0;
symstrtab_hdr->sh_addralign = 1;
return true;
@@ -13491,12 +13483,18 @@ _bfd_elf_get_synthetic_symtab (bfd *abfd,
bool
_bfd_elf_final_write_processing (bfd *abfd)
{
Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
i_ehdrp = elf_elfheader (abfd);
Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE)
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
i_ehdrp->e_ident[EI_OSABI] = bed->elf_osabi;
if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_SOLARIS
|| bed->target_os == is_solaris)
{
elf_tdata (abfd)->strtab_hdr.sh_flags = SHF_STRINGS;
elf_tdata (abfd)->shstrtab_hdr.sh_flags = SHF_STRINGS;
}
/* Set the osabi field to ELFOSABI_GNU if the binary contains
SHF_GNU_MBIND or SHF_GNU_RETAIN sections or symbols of STT_GNU_IFUNC type

View File

@@ -4681,9 +4681,6 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 1
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
#include "elf32-target.h"
/* Intel MCU support. */
@@ -4723,8 +4720,6 @@ elf32_iamcu_elf_object_p (bfd *abfd)
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
#undef elf_backend_strtab_flags
#include "elf32-target.h"
/* Restore defaults. */

View File

@@ -291,9 +291,6 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
#undef elf_backend_static_tls_alignment
#define elf_backend_static_tls_alignment 8
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
static bool
elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
bfd *obfd ATTRIBUTE_UNUSED,
@@ -352,7 +349,6 @@ elf32_sparc_vxworks_final_write_processing (bfd *abfd)
#define elf_backend_final_write_processing \
elf32_sparc_vxworks_final_write_processing
#undef elf_backend_static_tls_alignment
#undef elf_backend_strtab_flags
#undef elf_backend_copy_special_section_fields
#undef elf32_bed

View File

@@ -1022,9 +1022,6 @@ static const struct elf_size_info elf64_sparc_size_info =
#undef elf_backend_static_tls_alignment
#define elf_backend_static_tls_alignment 16
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
static bool
elf64_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
bfd *obfd ATTRIBUTE_UNUSED,
@@ -1041,5 +1038,4 @@ elf64_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSE
#include "elf64-target.h"
#undef elf_backend_strtab_flags
#undef elf_backend_copy_special_section_fields

View File

@@ -6464,9 +6464,6 @@ elf_x86_64_special_sections[]=
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 1
#undef elf_backend_strtab_flags
#define elf_backend_strtab_flags SHF_STRINGS
#include "elf64-target.h"
/* Restore defaults. */
@@ -6474,7 +6471,6 @@ elf_x86_64_special_sections[]=
#undef elf_backend_static_tls_alignment
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
#undef elf_backend_strtab_flags
/* 32bit x86-64 support. */

View File

@@ -13475,15 +13475,8 @@ _bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
}
symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
/* sh_name was set in prep_headers. */
symstrtab_hdr->sh_type = SHT_STRTAB;
symstrtab_hdr->sh_flags = bed->elf_strtab_flags;
symstrtab_hdr->sh_addr = 0;
symstrtab_hdr->sh_size = _bfd_elf_strtab_size (flinfo.symstrtab);
symstrtab_hdr->sh_entsize = 0;
symstrtab_hdr->sh_link = 0;
symstrtab_hdr->sh_info = 0;
/* sh_offset is set just below. */
symstrtab_hdr->sh_addralign = 1;
off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr,

View File

@@ -142,9 +142,6 @@
#ifndef elf_backend_stack_align
#define elf_backend_stack_align 16
#endif
#ifndef elf_backend_strtab_flags
#define elf_backend_strtab_flags 0
#endif
#ifndef elf_backend_use_mmap
#define elf_backend_use_mmap false
#endif
@@ -942,7 +939,6 @@ static const struct elf_backend_data elfNN_bed =
elf_backend_write_secondary_reloc_section,
elf_backend_static_tls_alignment,
elf_backend_stack_align,
elf_backend_strtab_flags,
elf_backend_collect,
elf_backend_type_change_ok,
elf_backend_may_use_rel_p,