Get rid of SEC_ELF_COMPRESS

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.
This commit is contained in:
Alan Modra
2022-12-06 15:08:31 +10:30
parent 7b5f66a118
commit da16cc96f3
5 changed files with 65 additions and 95 deletions

View File

@ -921,9 +921,8 @@ typedef struct bfd_section
executables or shared objects. This is for COFF only. */ executables or shared objects. This is for COFF only. */
#define SEC_COFF_SHARED 0x8000000 #define SEC_COFF_SHARED 0x8000000
/* This section should be compressed. This is for ELF linker /* Indicate that section has the purecode flag set. */
internal use only. */ #define SEC_ELF_PURECODE 0x8000000
#define SEC_ELF_COMPRESS 0x8000000
/* When a section with this flag is being linked, then if the size of /* 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 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. */ when memory read flag isn't set. */
#define SEC_COFF_NOREAD 0x40000000 #define SEC_COFF_NOREAD 0x40000000
/* Indicate that section has the purecode flag set. */
#define SEC_ELF_PURECODE 0x80000000
/* End of section flags. */ /* End of section flags. */
/* Some internal packed boolean fields. */ /* Some internal packed boolean fields. */

View File

@ -3174,9 +3174,6 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
&& name[1] == 'd' && name[1] == 'd'
&& name[6] == '_') && 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 /* If this section will be compressed, delay adding section
name to section name section after it is compressed in name to section name section after it is compressed in
_bfd_elf_assign_file_positions_for_non_load. */ _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) && hdr->bfd_section == NULL)
/* We don't know the offset of these sections yet: /* We don't know the offset of these sections yet:
their size has not been decided. */ their size has not been decided. */
|| (hdr->bfd_section != NULL || (abfd->is_linker_output
&& (hdr->bfd_section->flags & SEC_ELF_COMPRESS && hdr->bfd_section != NULL
|| (bfd_section_is_ctf (hdr->bfd_section) && (hdr->sh_name == -1u
&& abfd->is_linker_output))) || bfd_section_is_ctf (hdr->bfd_section)))
|| hdr == i_shdrpp[elf_onesymtab (abfd)] || hdr == i_shdrpp[elf_onesymtab (abfd)]
|| (elf_symtab_shndx_list (abfd) != NULL || (elf_symtab_shndx_list (abfd) != NULL
&& hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx]) && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
@ -6424,10 +6421,10 @@ assign_file_positions_except_relocs (bfd *abfd,
&& hdr->bfd_section == NULL) && hdr->bfd_section == NULL)
/* Do not assign offsets for these sections yet: we don't know /* Do not assign offsets for these sections yet: we don't know
their sizes. */ their sizes. */
|| (hdr->bfd_section != NULL || (abfd->is_linker_output
&& (hdr->bfd_section->flags & SEC_ELF_COMPRESS && hdr->bfd_section != NULL
|| (bfd_section_is_ctf (hdr->bfd_section) && (hdr->sh_name == -1u
&& abfd->is_linker_output))) || bfd_section_is_ctf (hdr->bfd_section)))
|| i == elf_onesymtab (abfd) || i == elf_onesymtab (abfd)
|| (elf_symtab_shndx_list (abfd) != NULL || (elf_symtab_shndx_list (abfd) != NULL
&& hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx]) && hdr == i_shdrpp[elf_symtab_shndx_list (abfd)->ndx])
@ -6630,21 +6627,23 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
if (shdrp->sh_offset == -1) if (shdrp->sh_offset == -1)
{ {
asection *sec = shdrp->bfd_section; asection *sec = shdrp->bfd_section;
bool is_rel = (shdrp->sh_type == SHT_REL if (sec == NULL
|| shdrp->sh_type == SHT_RELA); || shdrp->sh_type == SHT_REL
bool is_ctf = sec && bfd_section_is_ctf (sec); || shdrp->sh_type == SHT_RELA)
if (is_rel ;
|| is_ctf else if (bfd_section_is_ctf (sec))
|| (sec != NULL && (sec->flags & SEC_ELF_COMPRESS)))
{ {
if (!is_rel && !is_ctf) /* 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; const char *name = sec->name;
struct bfd_elf_section_data *d; struct bfd_elf_section_data *d;
/* Compress DWARF debug sections. */ /* Compress DWARF debug sections. */
if (!bfd_compress_section (abfd, sec, if (!bfd_compress_section (abfd, sec, shdrp->contents))
shdrp->contents))
return false; return false;
if (sec->compress_status == COMPRESS_SECTION_DONE if (sec->compress_status == COMPRESS_SECTION_DONE
@ -6659,8 +6658,6 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
name = new_name; name = new_name;
} }
/* Add section name to section name section. */ /* Add section name to section name section. */
if (shdrp->sh_name != (unsigned int) -1)
abort ();
shdrp->sh_name shdrp->sh_name
= (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
name, false); name, false);
@ -6679,18 +6676,10 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
/* Update section size and contents. */ /* Update section size and contents. */
shdrp->sh_size = sec->size; shdrp->sh_size = sec->size;
shdrp->contents = sec->contents; shdrp->contents = sec->contents;
shdrp->bfd_section->contents = NULL; sec->contents = NULL;
}
else if (is_ctf)
{
/* Update section size and contents. */
shdrp->sh_size = sec->size;
shdrp->contents = sec->contents;
} }
off = _bfd_elf_assign_file_position_for_section (shdrp, off, off = _bfd_elf_assign_file_position_for_section (shdrp, off, true);
true);
}
} }
} }
@ -9469,16 +9458,6 @@ _bfd_elf_set_section_contents (bfd *abfd,
later. */ later. */
return true; 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) if ((offset + count) > hdr->sh_size)
{ {
_bfd_error_handler _bfd_error_handler

View 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 later. Use bfd_malloc since it will be freed by
bfd_compress_section_contents. */ bfd_compress_section_contents. */
unsigned char *contents = esdo->this_hdr.contents; unsigned char *contents = esdo->this_hdr.contents;
if ((o->flags & SEC_ELF_COMPRESS) == 0 || contents != NULL) if (contents != NULL)
abort (); abort ();
contents contents
= (unsigned char *) bfd_malloc (esdo->this_hdr.sh_size); = (unsigned char *) bfd_malloc (esdo->this_hdr.sh_size);

View 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 /* We must compress this section. Write output to the
buffer. */ buffer. */
contents = hdr->contents; contents = hdr->contents;
if ((sec->output_section->flags & SEC_ELF_COMPRESS) == 0 if (contents == NULL)
|| contents == NULL)
abort (); abort ();
} }
else else

View File

@ -336,9 +336,8 @@ CODE_FRAGMENT
. executables or shared objects. This is for COFF only. *} . executables or shared objects. This is for COFF only. *}
.#define SEC_COFF_SHARED 0x8000000 .#define SEC_COFF_SHARED 0x8000000
. .
. {* This section should be compressed. This is for ELF linker . {* Indicate that section has the purecode flag set. *}
. internal use only. *} .#define SEC_ELF_PURECODE 0x8000000
.#define SEC_ELF_COMPRESS 0x8000000
. .
. {* When a section with this flag is being linked, then if the size of . {* 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 . 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. *} . when memory read flag isn't set. *}
.#define SEC_COFF_NOREAD 0x40000000 .#define SEC_COFF_NOREAD 0x40000000
. .
. {* Indicate that section has the purecode flag set. *}
.#define SEC_ELF_PURECODE 0x80000000
.
. {* End of section flags. *} . {* End of section flags. *}
. .
. {* Some internal packed boolean fields. *} . {* Some internal packed boolean fields. *}