ELF SEC_SMALL_DATA
authorAlan Modra <amodra@gmail.com>
Sun, 1 Mar 2020 23:46:39 +0000 (10:16 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2020 01:06:19 +0000 (11:36 +1030)
For those ELF targets that have .sdata or .sbss sections, or similar
sections, arrange to mark the sections with the SEC_SMALL_DATA flag.
This fixes regressions in nm symbol type caused by removing .sdata
and .sbss from coff_section_type with commit 49d9fd42ac.

* elf32-m32r.c (m32r_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elf32-nds32.c (nds32_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elf32-ppc.c (ppc_elf_section_from_shdr): Set SEC_SMALL_DATA for
.sbss and .sdata sections.
* elf32-v850.c (v850_elf_section_from_shdr): Set SEC_SMALL_DATA
for SHF_V850_GPREL sections.
* elf64-alpha.c (elf64_alpha_section_from_shdr): Delete outdated
FIXME.
* elf64-hppa.c (elf64_hppa_section_from_shdr): Set SEC_SMALL_DATA
for SHF_PARISC_SHORT sections.
* elf64-ppc.c (ppc64_elf_section_flags): New function.
(elf_backend_section_flags): Define.
* elfxx-mips.c (_bfd_mips_elf_section_from_shdr): Set SEC_SMALL_DATA
for SHF_MIPS_GPREL sections.  Delete FIXME.

bfd/ChangeLog
bfd/elf32-m32r.c
bfd/elf32-nds32.c
bfd/elf32-ppc.c
bfd/elf32-v850.c
bfd/elf64-alpha.c
bfd/elf64-hppa.c
bfd/elf64-ppc.c
bfd/elfxx-mips.c

index 4bbd048c91456ed496e410951d45b9d507ac5bb8..304efd06877d9f953e6715a3e431955bdade87c1 100644 (file)
@@ -1,3 +1,22 @@
+2020-03-02  Alan Modra  <amodra@gmail.com>
+
+       * elf32-m32r.c (m32r_elf_section_flags): New function.
+       (elf_backend_section_flags): Define.
+       * elf32-nds32.c (nds32_elf_section_flags): New function.
+       (elf_backend_section_flags): Define.
+       * elf32-ppc.c (ppc_elf_section_from_shdr): Set SEC_SMALL_DATA for
+       .sbss and .sdata sections.
+       * elf32-v850.c (v850_elf_section_from_shdr): Set SEC_SMALL_DATA
+       for SHF_V850_GPREL sections.
+       * elf64-alpha.c (elf64_alpha_section_from_shdr): Delete outdated
+       FIXME.
+       * elf64-hppa.c (elf64_hppa_section_from_shdr): Set SEC_SMALL_DATA
+       for SHF_PARISC_SHORT sections.
+       * elf64-ppc.c (ppc64_elf_section_flags): New function.
+       (elf_backend_section_flags): Define.
+       * elfxx-mips.c (_bfd_mips_elf_section_from_shdr): Set SEC_SMALL_DATA
+       for SHF_MIPS_GPREL sections.  Delete FIXME.
+
 2020-03-02  Alan Modra  <amodra@gmail.com>
 
        * elf-bfd.h (elf_backend_section_flags): Remove flagword* param.
index edc95b5d63a824edaae2c18400aedeb9c3eb0808..2a4b0b2ebea80d4bab414cb58ee00e62a74dcae6 100644 (file)
@@ -3827,6 +3827,18 @@ static const struct bfd_elf_special_section m32r_elf_special_sections[] =
   { NULL,                    0,  0, 0,            0 }
 };
 
+static bfd_boolean
+m32r_elf_section_flags (const Elf_Internal_Shdr *hdr)
+{
+  const char *name = hdr->bfd_section->name;
+
+  if (strncmp (name, ".sbss", 5) == 0
+      || strncmp (name, ".sdata", 6) == 0)
+    hdr->bfd_section->flags |= SEC_SMALL_DATA;
+
+  return TRUE;
+}
+
 static enum elf_reloc_type_class
 m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
                           const asection *rel_sec ATTRIBUTE_UNUSED,
@@ -3897,6 +3909,7 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
 #define bfd_elf32_bfd_set_private_flags                m32r_elf_set_private_flags
 #define bfd_elf32_bfd_print_private_bfd_data   m32r_elf_print_private_bfd_data
 #define elf_backend_special_sections           m32r_elf_special_sections
+#define elf_backend_section_flags              m32r_elf_section_flags
 
 #define elf_backend_linux_prpsinfo32_ugid16    TRUE
 
index 6d3c1c360f2022155d9de9db7643a2b35902bc25..fc4d002f0d9386ddc0a35b6ff31817d3099fefef 100644 (file)
@@ -12593,6 +12593,18 @@ static struct bfd_elf_special_section const nds32_elf_special_sections[] =
   {NULL, 0, 0, 0, 0}
 };
 
+static bfd_boolean
+nds32_elf_section_flags (const Elf_Internal_Shdr *hdr)
+{
+  const char *name = hdr->bfd_section->name;
+
+  if (strncmp (name, ".sbss", 5) == 0
+      || strncmp (name, ".sdata", 6) == 0)
+    hdr->bfd_section->flags |= SEC_SMALL_DATA;
+
+  return TRUE;
+}
+
 static bfd_boolean
 nds32_elf_output_arch_syms (bfd *output_bfd ATTRIBUTE_UNUSED,
                            struct bfd_link_info *info,
@@ -14093,6 +14105,7 @@ nds32_elf_unify_tls_model (bfd *inbfd, asection *insec, bfd_byte *incontents,
 #define elf_backend_object_p                   nds32_elf_object_p
 #define elf_backend_final_write_processing     nds32_elf_final_write_processing
 #define elf_backend_special_sections           nds32_elf_special_sections
+#define elf_backend_section_flags              nds32_elf_section_flags
 #define bfd_elf32_bfd_get_relocated_section_contents \
                                nds32_elf_get_relocated_section_contents
 #define bfd_elf32_bfd_is_target_special_symbol nds32_elf_is_target_special_symbol
index 3a42a4e10594f5a9b115af78b9a66b485102eafa..68b02205aafc9cb7e9ac5bfa124556a97840528f 100644 (file)
@@ -1332,15 +1332,21 @@ ppc_elf_section_from_shdr (bfd *abfd,
     return FALSE;
 
   newsect = hdr->bfd_section;
-  flags = bfd_section_flags (newsect);
+  flags = 0;
   if (hdr->sh_flags & SHF_EXCLUDE)
     flags |= SEC_EXCLUDE;
 
   if (hdr->sh_type == SHT_ORDERED)
     flags |= SEC_SORT_ENTRIES;
 
-  bfd_set_section_flags (newsect, flags);
-  return TRUE;
+  if (strncmp (name, ".PPC.EMB", 8) == 0)
+    name += 8;
+  if (strncmp (name, ".sbss", 5) == 0
+      || strncmp (name, ".sdata", 6) == 0)
+    flags |= SEC_SMALL_DATA;
+
+  return (flags == 0
+         || bfd_set_section_flags (newsect, newsect->flags | flags));
 }
 
 /* Set up any other section flags and such that may be necessary.  */
index afebb2ab86f373fda5f7f93ff8339a0821dad612..bf37a936620f12a3c6482d265ae2a7e2c6ae09d5 100644 (file)
@@ -3151,6 +3151,8 @@ v850_elf_section_from_shdr (bfd *abfd,
                            const char *name,
                            int shindex)
 {
+  flagword flags;
+
   /* There ought to be a place to keep ELF backend specific flags, but
      at the moment there isn't one.  We just keep track of the
      sections by their name, instead.  */
@@ -3158,18 +3160,21 @@ v850_elf_section_from_shdr (bfd *abfd,
   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
     return FALSE;
 
+  flags = 0;
   switch (hdr->sh_type)
     {
     case SHT_V850_SCOMMON:
     case SHT_V850_TCOMMON:
     case SHT_V850_ZCOMMON:
-      if (!bfd_set_section_flags (hdr->bfd_section,
-                                 (bfd_section_flags (hdr->bfd_section)
-                                  | SEC_IS_COMMON)))
-       return FALSE;
+      flags = SEC_IS_COMMON;
     }
 
-  return TRUE;
+  if ((hdr->sh_flags & SHF_V850_GPREL) != 0)
+    flags |= SEC_SMALL_DATA;
+
+  return (flags == 0
+         || bfd_set_section_flags (hdr->bfd_section,
+                                   hdr->bfd_section->flags | flags));
 }
 
 /* Set the correct type for a V850 ELF section.  We do this
index 9d2d7f1d4dd18fb9e386054dc452d45b97a6f9a5..ca15944e608da0138e36e6713422c5a6d09ac344 100644 (file)
@@ -1136,9 +1136,7 @@ elf64_alpha_info_to_howto (bfd *abfd, arelent *cache_ptr,
 \f
 /* Handle an Alpha specific section when reading an object file.  This
    is called when bfd_section_from_shdr finds a section with an unknown
-   type.
-   FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
-   how to.  */
+   type.  */
 
 static bfd_boolean
 elf64_alpha_section_from_shdr (bfd *abfd,
index f0354438943f62f282053ed2c8ec8c9cbdcb7929..a2602daf2b1a2027be71fe5a88082efbc98f4e90 100644 (file)
@@ -383,7 +383,9 @@ elf64_hppa_section_from_shdr (bfd *abfd,
   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
     return FALSE;
 
-  return TRUE;
+  return ((hdr->sh_flags & SHF_PARISC_SHORT) == 0
+         || bfd_set_section_flags (hdr->bfd_section,
+                                   hdr->bfd_section->flags | SEC_SMALL_DATA));
 }
 
 /* SEC is a section containing relocs for an input BFD when linking; return
index 1ea4c402e041c8c5b3a304a5b8c032a98eead42a..05ef34b030ac551cc3158080451bf31853720837 100644 (file)
@@ -125,6 +125,7 @@ static bfd_vma opd_entry_value
 #define elf_backend_finish_dynamic_sections   ppc64_elf_finish_dynamic_sections
 #define elf_backend_link_output_symbol_hook   ppc64_elf_output_symbol_hook
 #define elf_backend_special_sections         ppc64_elf_special_sections
+#define elf_backend_section_flags            ppc64_elf_section_flags
 #define elf_backend_merge_symbol_attribute    ppc64_elf_merge_symbol_attribute
 #define elf_backend_merge_symbol             ppc64_elf_merge_symbol
 #define elf_backend_get_reloc_section        bfd_get_section_by_name
@@ -2011,6 +2012,18 @@ ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
   return _bfd_elf_new_section_hook (abfd, sec);
 }
 
+static bfd_boolean
+ppc64_elf_section_flags (const Elf_Internal_Shdr *hdr)
+{
+  const char *name = hdr->bfd_section->name;
+
+  if (strncmp (name, ".sbss", 5) == 0
+      || strncmp (name, ".sdata", 6) == 0)
+    hdr->bfd_section->flags |= SEC_SMALL_DATA;
+
+  return TRUE;
+}
+
 static struct _opd_sec_data *
 get_opd_info (asection * sec)
 {
index ae33acb8d5caa71ec560bf042810f3f45d4dc31c..4671b5044975a0f6710390035e0f38fe755a2f38 100644 (file)
@@ -7425,10 +7425,7 @@ _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr)
 
 /* Handle a MIPS specific section when reading an object file.  This
    is called when elfcode.h finds a section with an unknown type.
-   This routine supports both the 32-bit and 64-bit ELF ABI.
-
-   FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
-   how to.  */
+   This routine supports both the 32-bit and 64-bit ELF ABI.  */
 
 bfd_boolean
 _bfd_mips_elf_section_from_shdr (bfd *abfd,
@@ -7517,6 +7514,9 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
     return FALSE;
 
+  if (hdr->sh_flags & SHF_MIPS_GPREL)
+    flags |= SEC_SMALL_DATA;
+
   if (flags)
     {
       if (!bfd_set_section_flags (hdr->bfd_section,
This page took 0.052817 seconds and 4 git commands to generate.