From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 40EF13895FFB for ; Tue, 6 Dec 2022 05:04:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40EF13895FFB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102d.google.com with SMTP id u15-20020a17090a3fcf00b002191825cf02so13681274pjm.2 for ; Mon, 05 Dec 2022 21:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=UqH7Cx9xW2h0wzRw+dpjeNIN/uhlrCoY3nPw6s9ATjs=; b=XjrE97KBIVaZZ4ZkSwEFBHtTGCTWKTZiUs5rHKcyK/69c2vZqfDUlyaeibxNURcDlt eFjKNZp8sST/vUEKUfawk4llzeJVzGP2Y9lqOobEnuRgqxphq/l5CHW85exw7ratcPfM 2rzlcJpWVqGbwWG9M+HeZnpE1LpRteXQ9tdt58f+HPR70rIsctlKsyF9GKf0QWFHiGei 6xe2lmEn58qWXc/3dQQy/MJ9vIEXLoGqxJrAzlegI+5rwT4rOUpvSJ7Dp+ffU/Q1wUUn F56zWXlffASE2YjH9UR3OFzRNqsP76OBCYJOyaaBwwwlox97T1JI/yrXxuA3ZJWbxNgf oy8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UqH7Cx9xW2h0wzRw+dpjeNIN/uhlrCoY3nPw6s9ATjs=; b=gBROIn7mT+0Wg3gwaBCEffDetIeOtauLPTjDR/T4hx98UqVC1/6J70hRF6Ob7cm9v/ 1TkX2aAWCJqO0pH4R1Pn0+L/gownrxMDUkprzoo2knCNk08GVXxWNMSB5dZCGAurMzH2 zDzeG8sTTt71MVeVcj0IOgjZ/aRYq69mWeWLNF567kVzcTzyoNrzpwBbvZnHMEQjsj1d eYepOeQcTOo7aNIlTQ0xRHEOJuV3k3Pqbf/s/bmbrAxdrvkeXGLCGE4zu0Rtm/wlbPZw p+nUJlkJt5YrmALHCN7yVSqB47s02osduqLJ2cbc9Uxn6pVWIZfFobQ6nfvsppEvHKaz p7hg== X-Gm-Message-State: ANoB5pmBW406qj8IeGKi9dpGe2VZt+SmqbYxjIfe7vBES2BhSzMaRXMu BFZG7tf9C7cBq8Adm+zYsQ3c2YGy+QQ= X-Google-Smtp-Source: AA0mqf4eLk6YFHAxi9wQlya6lqvjjCPYgtT3oZlSD0Zj+7FOvuNMP52/xXheF0Ka6uk9LEdp2wPlHA== X-Received: by 2002:a17:90a:e556:b0:219:b502:a2d2 with SMTP id ei22-20020a17090ae55600b00219b502a2d2mr13492850pjb.230.1670303067597; Mon, 05 Dec 2022 21:04:27 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id w131-20020a628289000000b0056d2317455bsm10733824pfd.7.2022.12.05.21.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 21:04:27 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id AD6191141D85; Tue, 6 Dec 2022 15:34:24 +1030 (ACDT) Date: Tue, 6 Dec 2022 15:34:24 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Get rid of SEC_ELF_COMPRESS Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index d983268563d..11f88ae0c90 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -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. */ diff --git a/bfd/elf.c b/bfd/elf.c index 61058deaea1..797ecc436d3 100644 --- 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 diff --git a/bfd/elflink.c b/bfd/elflink.c index a141c9eb0e8..fc3edef9a05 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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); diff --git a/bfd/merge.c b/bfd/merge.c index 5e021b7f532..79d80e76679 100644 --- a/bfd/merge.c +++ b/bfd/merge.c @@ -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 diff --git a/bfd/section.c b/bfd/section.c index 30ab6a7d338..a49778eb333 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -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. *} -- Alan Modra Australia Development Lab, IBM