]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Solaris .strtab and .shstrtab flags
authorAlan Modra <amodra@gmail.com>
Thu, 1 Jan 2026 21:52:02 +0000 (08:22 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 1 Jan 2026 21:52:02 +0000 (08:22 +1030)
These sections have SHF_STRINGS in sh_flags on Solaris.  Commit
84865015459b 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.

bfd/elf-bfd.h
bfd/elf.c
bfd/elf32-i386.c
bfd/elf32-sparc.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elfxx-target.h

index e059af53875175498487d6eca63f107e7fdd13c9..c5a258e25ade50c2568c8d0aa361bcbe10d6949c 100644 (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
index a652e9bc41eeb4342507a51a50f0508251d68d7f..f327653e5f63eb2516deea0f69ef9dc077955d5d 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -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
index cab9a76c120c604a7ed22075b62ddf2607dcc832..d1843f501d51119ccf125aa40524c0fc5910b3e6 100644 (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.  */
index b7ac618817d4b00830f7cf0ff7852ddeacd61732..37dc926d0de83e666a968a86c74d26b67c7f64e8 100644 (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
index 936b0ce4465717d498c7c651ebb930e11f59ad16..d249cbce6deee29a3f803cf25580e46298cbaf3b 100644 (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
index 2e2687b99f7b9bd636fc0cddeb57e5bcf6e6005e..4be86c3aa24780c88142b228454076821a386919 100644 (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.  */
 
index e815e6b381bd816871a2fa2d4045c067b0fff079..d0b1ec5cb045c992f69e5a8b49db3b95b163fb61 100644 (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,
index 00552826b4c8d71540a06a57bc1d1e7bfbf8e21d..479ba47785d7498b1fdbce2cce98940a3cbb07eb 100644 (file)
 #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,