Get rid of SEC_ELF_COMPRESS
authorAlan Modra <amodra@gmail.com>
Tue, 6 Dec 2022 04:38:31 +0000 (15:08 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 6 Dec 2022 04:38:31 +0000 (15:08 +1030)
This flag also isn't needed, except for some sanity checks which we
can omit.

* elf.c (elf_fake_sections): Don't set SEC_ELF_COMPRESS for
compressed debug sections, just leave sh_name as -1.
(assign_file_positions_for_non_load_sections),
(assign_file_positions_except_relocs): Decide whether a section
needs compressing and thus should not have its file offset set
by looking at sh_name.
(_bfd_elf_assign_file_positions_for_non_load): Similarly decide
which sections need compressing.
* elflink.c (bfd_elf_final_link): Don't test SEC_ELF_COMPRESS.
* merge.c (_bfd_write_merged_section): Likewise.
* section.c (SEC_ELF_COMPRESS): Don't define.
(SEC_ELF_PURECODE): Renumber.
* bfd-in2.h: Regenerate.

bfd/bfd-in2.h
bfd/elf.c
bfd/elflink.c
bfd/merge.c
bfd/section.c

index d983268563d993e0ab74077ab47e23912d09de19..11f88ae0c90859647ba76e3ff6d02f387b328650 100644 (file)
@@ -921,9 +921,8 @@ typedef struct bfd_section
      executables or shared objects. This is for COFF only.  */
 #define SEC_COFF_SHARED             0x8000000
 
-  /* This section should be compressed.  This is for ELF linker
-     internal use only.  */
-#define SEC_ELF_COMPRESS            0x8000000
+  /* Indicate that section has the purecode flag set.  */
+#define SEC_ELF_PURECODE            0x8000000
 
   /* When a section with this flag is being linked, then if the size of
      the input section is less than a page, it should not cross a page
@@ -949,9 +948,6 @@ typedef struct bfd_section
      when memory read flag isn't set. */
 #define SEC_COFF_NOREAD            0x40000000
 
-  /* Indicate that section has the purecode flag set.  */
-#define SEC_ELF_PURECODE           0x80000000
-
   /*  End of section flags.  */
 
   /* Some internal packed boolean fields.  */
index 61058deaea1d43cb6bcee02502c5145a757c9109..797ecc436d3908f387186796fb76fc12f9c4737d 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3174,9 +3174,6 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
       && name[1] == 'd'
       && name[6] == '_')
     {
-      /* Set SEC_ELF_COMPRESS to indicate this section should be
-        compressed.  */
-      asect->flags |= SEC_ELF_COMPRESS;
       /* If this section will be compressed, delay adding section
         name to section name section after it is compressed in
         _bfd_elf_assign_file_positions_for_non_load.  */
@@ -6189,10 +6186,10 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
                && hdr->bfd_section == NULL)
               /* We don't know the offset of these sections yet:
                  their size has not been decided.  */
-              || (hdr->bfd_section != NULL
-                  && (hdr->bfd_section->flags & SEC_ELF_COMPRESS
-                      || (bfd_section_is_ctf (hdr->bfd_section)
-                          && abfd->is_linker_output)))
+              || (abfd->is_linker_output
+                  && hdr->bfd_section != NULL
+                  && (hdr->sh_name == -1u
+                      || bfd_section_is_ctf (hdr->bfd_section)))
               || hdr == i_shdrpp[elf_onesymtab (abfd)]
               || (elf_symtab_shndx_list (abfd) != NULL
                   && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
@@ -6424,10 +6421,10 @@ assign_file_positions_except_relocs (bfd *abfd,
               && hdr->bfd_section == NULL)
              /* Do not assign offsets for these sections yet: we don't know
                 their sizes.  */
-             || (hdr->bfd_section != NULL
-                 && (hdr->bfd_section->flags & SEC_ELF_COMPRESS
-                     || (bfd_section_is_ctf (hdr->bfd_section)
-                         && abfd->is_linker_output)))
+             || (abfd->is_linker_output
+                 && hdr->bfd_section != NULL
+                 && (hdr->sh_name == -1u
+                     || bfd_section_is_ctf (hdr->bfd_section)))
              || i == elf_onesymtab (abfd)
              || (elf_symtab_shndx_list (abfd) != NULL
                  && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
@@ -6630,67 +6627,59 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
       if (shdrp->sh_offset == -1)
        {
          asection *sec = shdrp->bfd_section;
-         bool is_rel = (shdrp->sh_type == SHT_REL
-                        || shdrp->sh_type == SHT_RELA);
-         bool is_ctf = sec && bfd_section_is_ctf (sec);
-         if (is_rel
-             || is_ctf
-             || (sec != NULL && (sec->flags & SEC_ELF_COMPRESS)))
-           {
-             if (!is_rel && !is_ctf)
-               {
-                 const char *name = sec->name;
-                 struct bfd_elf_section_data *d;
-
-                 /* Compress DWARF debug sections.  */
-                 if (!bfd_compress_section (abfd, sec,
-                                            shdrp->contents))
-                   return false;
+         if (sec == NULL
+             || shdrp->sh_type == SHT_REL
+             || shdrp->sh_type == SHT_RELA)
+           ;
+         else if (bfd_section_is_ctf (sec))
+           {
+             /* Update section size and contents.      */
+             shdrp->sh_size = sec->size;
+             shdrp->contents = sec->contents;
+           }
+         else if (shdrp->sh_name == -1u)
+           {
+             const char *name = sec->name;
+             struct bfd_elf_section_data *d;
 
-                 if (sec->compress_status == COMPRESS_SECTION_DONE
-                     && (abfd->flags & BFD_COMPRESS_GABI) == 0
-                     && name[1] == 'd')
-                   {
-                     /* If section is compressed with zlib-gnu, convert
-                        section name from .debug_* to .zdebug_*.  */
-                     char *new_name = bfd_debug_name_to_zdebug (abfd, name);
-                     if (new_name == NULL)
-                       return false;
-                     name = new_name;
-                   }
-                 /* Add section name to section name section.  */
-                 if (shdrp->sh_name != (unsigned int) -1)
-                   abort ();
-                 shdrp->sh_name
-                   = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
-                                                         name, false);
-                 d = elf_section_data (sec);
-
-                 /* Add reloc section name to section name section.  */
-                 if (d->rel.hdr
-                     && !_bfd_elf_set_reloc_sh_name (abfd, d->rel.hdr,
-                                                     name, false))
-                   return false;
-                 if (d->rela.hdr
-                     && !_bfd_elf_set_reloc_sh_name (abfd, d->rela.hdr,
-                                                     name, true))
-                   return false;
+             /* Compress DWARF debug sections.  */
+             if (!bfd_compress_section (abfd, sec, shdrp->contents))
+               return false;
 
-                 /* Update section size and contents.  */
-                 shdrp->sh_size = sec->size;
-                 shdrp->contents = sec->contents;
-                 shdrp->bfd_section->contents = NULL;
-               }
-             else if (is_ctf)
+             if (sec->compress_status == COMPRESS_SECTION_DONE
+                 && (abfd->flags & BFD_COMPRESS_GABI) == 0
+                 && name[1] == 'd')
                {
-                 /* Update section size and contents.  */
-                 shdrp->sh_size = sec->size;
-                 shdrp->contents = sec->contents;
+                 /* If section is compressed with zlib-gnu, convert
+                    section name from .debug_* to .zdebug_*.  */
+                 char *new_name = bfd_debug_name_to_zdebug (abfd, name);
+                 if (new_name == NULL)
+                   return false;
+                 name = new_name;
                }
+             /* Add section name to section name section.  */
+             shdrp->sh_name
+               = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
+                                                     name, false);
+             d = elf_section_data (sec);
+
+             /* Add reloc section name to section name section.  */
+             if (d->rel.hdr
+                 && !_bfd_elf_set_reloc_sh_name (abfd, d->rel.hdr,
+                                                 name, false))
+               return false;
+             if (d->rela.hdr
+                 && !_bfd_elf_set_reloc_sh_name (abfd, d->rela.hdr,
+                                                 name, true))
+               return false;
 
-             off = _bfd_elf_assign_file_position_for_section (shdrp, off,
-                                                              true);
+             /* Update section size and contents.  */
+             shdrp->sh_size = sec->size;
+             shdrp->contents = sec->contents;
+             sec->contents = NULL;
            }
+
+         off = _bfd_elf_assign_file_position_for_section (shdrp, off, true);
        }
     }
 
@@ -9469,16 +9458,6 @@ _bfd_elf_set_section_contents (bfd *abfd,
           later.  */
        return true;
 
-      if ((section->flags & SEC_ELF_COMPRESS) == 0)
-       {
-         _bfd_error_handler
-           (_("%pB:%pA: error: attempting to write"
-              " into an unallocated compressed section"),
-            abfd, section);
-         bfd_set_error (bfd_error_invalid_operation);
-         return false;
-       }
-
       if ((offset + count) > hdr->sh_size)
        {
          _bfd_error_handler
index a141c9eb0e84ca562e1067e1a1938f0e13f6b4a1..fc3edef9a0564c8e52258f122f2c77eaec6b4d44 100644 (file)
@@ -12559,7 +12559,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
             later.  Use bfd_malloc since it will be freed by
             bfd_compress_section_contents.  */
          unsigned char *contents = esdo->this_hdr.contents;
-         if ((o->flags & SEC_ELF_COMPRESS) == 0 || contents != NULL)
+         if (contents != NULL)
            abort ();
          contents
            = (unsigned char *) bfd_malloc (esdo->this_hdr.sh_size);
index 5e021b7f5329733419a0ccf1f08abb584ebc78a6..79d80e766797f02555e7144a8279c5c9910bdc84 100644 (file)
@@ -850,8 +850,7 @@ _bfd_write_merged_section (bfd *output_bfd, asection *sec, void *psecinfo)
       /* We must compress this section.  Write output to the
         buffer.  */
       contents = hdr->contents;
-      if ((sec->output_section->flags & SEC_ELF_COMPRESS) == 0
-         || contents == NULL)
+      if (contents == NULL)
        abort ();
     }
   else
index 30ab6a7d3383d9921cc5b6f5d7fe68f83fd2a3a5..a49778eb333ac7f6384e1153f4bb550e6955a67e 100644 (file)
@@ -336,9 +336,8 @@ CODE_FRAGMENT
 .     executables or shared objects. This is for COFF only.  *}
 .#define SEC_COFF_SHARED             0x8000000
 .
-.  {* This section should be compressed.  This is for ELF linker
-.     internal use only.  *}
-.#define SEC_ELF_COMPRESS            0x8000000
+.  {* Indicate that section has the purecode flag set.  *}
+.#define SEC_ELF_PURECODE            0x8000000
 .
 .  {* When a section with this flag is being linked, then if the size of
 .     the input section is less than a page, it should not cross a page
@@ -364,9 +363,6 @@ CODE_FRAGMENT
 .     when memory read flag isn't set. *}
 .#define SEC_COFF_NOREAD            0x40000000
 .
-.  {* Indicate that section has the purecode flag set.  *}
-.#define SEC_ELF_PURECODE           0x80000000
-.
 .  {*  End of section flags.  *}
 .
 .  {* Some internal packed boolean fields.  *}