From patchwork Tue Dec 6 05:03:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 30083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2635389wrr; Mon, 5 Dec 2022 21:04:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6fEaAKvyn+++sEZfHMZIsiLmG/QyizX1t3Wd8/zLPtWRBCmoSiVObesR0wZkLd7OZ64Xuy X-Received: by 2002:a17:906:1484:b0:7ae:6746:f270 with SMTP id x4-20020a170906148400b007ae6746f270mr21864579ejc.728.1670303069350; Mon, 05 Dec 2022 21:04:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670303069; cv=none; d=google.com; s=arc-20160816; b=QK3ILQxVGQhxhdsYDiG5ymNXuZFwOCIchdQb74XyEhD/BWMMHFSnatXAZ/lz4iymSb 8HP/id3LuguHyarEABL/cjYfUVlgwBnsvCq13DbJhLxaH6MejQr36JjqUmHZstsbPSPI hehvSgdhF68vv8ilI6JvESKLTAc6JehsOWkAwmsBPRhdxMbpS2SpLthrHb1mvuZLwQIO GAY8dKDLnyQURn/Zfn8AQtuiYc1EJBpGHa8JFTae/RhwqkAwacdPNmye1Ex+qRoCkOJY JRMlxRV2QqqcOtUsQDmq9+MksGfUh91Kr+Ys5wQMa+Ms8M6EbNhuxe6w8DWD3AZU81tj qVHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=dwzbXmFXtVQLBCpf1nn5LpXGxTfEoGYozyTeH5ojMP4=; b=CCCjmIB2TbvkXxr4OPr0klx8HnKEMU9JSLvDj4YL+BKUXD6IkWUXvgViXFwtMv+YVq 3cao+LA47S2JV8VkT0bZRIEQaHKAuiGAM87CIPOnl4jhM3W+0eCMSXij4DSizVj8tNYD SAmBA7Zmn5gzlPPVZGyMSGs+oZ0KfoIdcwBX7ZCjd7YXsODrHWUcGn1YnKu98pm3I6kL 4e7K93ea4Hu48ZENadiCj8e24w12Yl9x0fA8noEZLPZ9LlgOuW7fPfWc8BKR5R6q1CMj +97Xn5yFBHKTAlMILHIe7kW874K6hl1yww/4/xiEdjNpMr1tMDXqnwgpSGoN7ZrMJRi1 deWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ObKxWHZa; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k12-20020a170906680c00b007a1d4f0e7fcsi11287180ejr.655.2022.12.05.21.04.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 21:04:29 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ObKxWHZa; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ED6D38983AD for ; Tue, 6 Dec 2022 05:04:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ED6D38983AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670303068; bh=dwzbXmFXtVQLBCpf1nn5LpXGxTfEoGYozyTeH5ojMP4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ObKxWHZat3yjL+7RIhw0DnIiDC9UNixyCLtRM8ILoSClfE87uxwq/K5vPYvxejEts 2YX3x9Fkql3A0cSzyoLLhkGqFbchgvdctE3GpbGgM8HiHU72eM2vRPBUFjTs3XsMXq YtiO5FT6qpN1A1JlTHT8hgtXKHqjdYjniG9DCt5g= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 3F60A3896C03 for ; Tue, 6 Dec 2022 05:04:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F60A3896C03 Received: by mail-pj1-x102e.google.com with SMTP id z8-20020a17090abd8800b00219ed30ce47so2717463pjr.3 for ; Mon, 05 Dec 2022 21:04:01 -0800 (PST) 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=dwzbXmFXtVQLBCpf1nn5LpXGxTfEoGYozyTeH5ojMP4=; b=MG4QFQQ8ReJZxtdN1SHvby6eZhwDP8tHMEiGdJ9L7BSAZ6gTvyHUsSvnVlWV6v35G3 mdQmp2n57JfmHrr3EmcGLe9iWhJVNV+l0DPoE3A6nAtT/PshzHicAgqQuMixkkrxdY6A QOPcgve4rw8u5Kxvh9knh8ODomiKCjh0jJprbMrzuTSky/yu6LLT78CbkbOVTIoZW05/ PjFBcI5imtkQX4tU9nRh50Hsf/txdW9/XlwJG/Pj8B5LS3/TSFq0hBHFYw4kbWbtNa2y mckVGKcELsd0zsxXzLx7oQYb8D/bSrPk+/ReH67u2+9lznzOZrwQVbqSAKPxeWFY1iQ+ hbsg== X-Gm-Message-State: ANoB5pkL8/ok1o2kXEGDhobUZ5/90J96c6GPNGO/zuVm2azt4QpD89vq okbI0BzZEj+5gSOiDG9REW5FfrO8WwM= X-Received: by 2002:a17:90a:2b88:b0:219:a1e4:20e2 with SMTP id u8-20020a17090a2b8800b00219a1e420e2mr15619728pjd.182.1670303039609; Mon, 05 Dec 2022 21:03:59 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:843d:2206:6669:b617]) by smtp.gmail.com with ESMTPSA id i92-20020a17090a3de500b00218ec4ff0d4sm11964672pjc.6.2022.12.05.21.03.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 21:03:59 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B6CCB1141D85; Tue, 6 Dec 2022 15:33:56 +1030 (ACDT) Date: Tue, 6 Dec 2022 15:33:56 +1030 To: binutils@sourceware.org Subject: Get rid of SEC_ELF_RENAME Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.4 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751439711139005823?= X-GMAIL-MSGID: =?utf-8?q?1751439711139005823?= SEC_ELF_RENAME is a flag used to effect section name changes when compressing/decompressing zlib-gnu debug sections. This can be accomplished more directly in one of the objcopy specific bfd functions. Renaming for ld input is simplified too. Ld input object files always have BFD_DECOMPRESS set. bfd/ * compress.c (bfd_convert_section_size): Rename to.. (bfd_convert_section_setup): ..this. Handle objcopy renaming of compressed/decompressed debug sections. * elf.c (_bfd_elf_make_section_from_shdr): Only rename zdebug input for linker. (elf_fake_sections): Don't handle renaming of debug sections for objcopy here. * section.c (SEC_ELF_RENAME): Delete. * bfd-in2.h: Regenerate. binutils/ * objcopy.c (setup_section): Call bfd_convert_section_setup. Don't call bfd_convert_section_size. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 24f9305c47c..d983268563d 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -932,10 +932,6 @@ typedef struct bfd_section TMS320C54X only. */ #define SEC_TIC54X_BLOCK 0x10000000 - /* This section should be renamed. This is for ELF linker - internal use only. */ -#define SEC_ELF_RENAME 0x10000000 - /* Conditionally link this section; do not link if there are no references found to any symbol in the section. This is for TI TMS320C54X only. */ @@ -7982,8 +7978,9 @@ void bfd_update_compression_header int bfd_get_compression_header_size (bfd *abfd, asection *sec); -bfd_size_type bfd_convert_section_size - (bfd *ibfd, asection *isec, bfd *obfd, bfd_size_type size); +bool bfd_convert_section_setup + (bfd *ibfd, asection *isec, bfd *obfd, + const char **new_name, bfd_size_type *new_size); bool bfd_convert_section_contents (bfd *ibfd, asection *isec, bfd *obfd, diff --git a/bfd/compress.c b/bfd/compress.c index a4e6a8ee7b5..bb55a6ec0ac 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -225,53 +225,89 @@ bfd_get_compression_header_size (bfd *abfd, asection *sec) /* FUNCTION - bfd_convert_section_size + bfd_convert_section_setup SYNOPSIS - bfd_size_type bfd_convert_section_size - (bfd *ibfd, asection *isec, bfd *obfd, bfd_size_type size); + bool bfd_convert_section_setup + (bfd *ibfd, asection *isec, bfd *obfd, + const char **new_name, bfd_size_type *new_size); DESCRIPTION - Convert the size @var{size} of the section @var{isec} in input - BFD @var{ibfd} to the section size in output BFD @var{obfd}. + Do early setup for objcopy, when copying @var{isec} in input + BFD @var{ibfd} to output BFD @var{obfd}. Returns the name and + size of the output section. */ -bfd_size_type -bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd, - bfd_size_type size) +bool +bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd, + const char **new_name, bfd_size_type *new_size) { bfd_size_type hdr_size; + if ((isec->flags & SEC_DEBUGGING) != 0 + && (isec->flags & SEC_HAS_CONTENTS) != 0) + { + const char *name = *new_name; + + if ((ibfd->flags & (BFD_DECOMPRESS | BFD_COMPRESS_GABI)) != 0) + { + /* When we decompress or compress with SHF_COMPRESSED, + convert section name from .zdebug_* to .debug_*. */ + if (startswith (name, ".zdebug_")) + { + name = bfd_zdebug_name_to_debug (obfd, name); + if (name == NULL) + return false; + } + } + + /* PR binutils/18087: Compression does not always make a + section smaller. So only rename the section when + compression has actually taken place. If input section + name is .zdebug_*, we should never compress it again. */ + else if (isec->compress_status == COMPRESS_SECTION_DONE + && startswith (name, ".debug_")) + { + name = bfd_debug_name_to_zdebug (obfd, name); + if (name == NULL) + return false; + } + *new_name = name; + } + *new_size = bfd_section_size (isec); + /* Do nothing if either input or output aren't ELF. */ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour || bfd_get_flavour (obfd) != bfd_target_elf_flavour) - return size; + return true; /* Do nothing if ELF classes of input and output are the same. */ if (get_elf_backend_data (ibfd)->s->elfclass == get_elf_backend_data (obfd)->s->elfclass) - return size; + return true; /* Convert GNU property size. */ if (startswith (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME)) - return _bfd_elf_convert_gnu_property_size (ibfd, obfd); + { + *new_size = _bfd_elf_convert_gnu_property_size (ibfd, obfd); + return true; + } /* Do nothing if input file will be decompressed. */ if ((ibfd->flags & BFD_DECOMPRESS)) - return size; + return true; /* Do nothing if the input section isn't a SHF_COMPRESSED section. */ hdr_size = bfd_get_compression_header_size (ibfd, isec); if (hdr_size == 0) - return size; + return true; /* Adjust the size of the output SHF_COMPRESSED section. */ if (hdr_size == sizeof (Elf32_External_Chdr)) - return (size - sizeof (Elf32_External_Chdr) - + sizeof (Elf64_External_Chdr)); + *new_size += sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr); else - return (size - sizeof (Elf64_External_Chdr) - + sizeof (Elf32_External_Chdr)); + *new_size += sizeof (Elf32_External_Chdr) - sizeof (Elf64_External_Chdr); + return true; } /* diff --git a/bfd/elf.c b/bfd/elf.c index a013f8885c7..61058deaea1 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1246,30 +1246,16 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, return false; } #endif - } - - if (action != nothing) - { - if (abfd->is_linker_input) + if (abfd->is_linker_input + && name[1] == 'z') { - if (name[1] == 'z' - && (action == decompress - || (action == compress - && (abfd->flags & BFD_COMPRESS_GABI) != 0))) - { - /* Convert section name from .zdebug_* to .debug_* so - that linker will consider this section as a debug - section. */ - char *new_name = bfd_zdebug_name_to_debug (abfd, name); - if (new_name == NULL) - return false; - bfd_rename_section (newsect, new_name); - } + /* Rename section from .zdebug_* to .debug_* so that ld + scripts will see this section as a debug section. */ + char *new_name = bfd_zdebug_name_to_debug (abfd, name); + if (new_name == NULL) + return false; + bfd_rename_section (newsect, new_name); } - else - /* For objdump, don't rename the section. For objcopy, delay - section rename to elf_fake_sections. */ - newsect->flags |= SEC_ELF_RENAME; } } @@ -3181,57 +3167,20 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) this_hdr = &esd->this_hdr; - if (arg->link_info) - { - /* ld: compress DWARF debug sections with names: .debug_*. */ - if ((arg->link_info->compress_debug & COMPRESS_DEBUG) - && (asect->flags & SEC_DEBUGGING) - && 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. */ - delay_st_name_p = true; - } - } - else if ((asect->flags & SEC_ELF_RENAME)) - { - /* objcopy: rename output DWARF debug section. */ - if ((abfd->flags & (BFD_DECOMPRESS | BFD_COMPRESS_GABI))) - { - /* When we decompress or compress with SHF_COMPRESSED, - convert section name from .zdebug_* to .debug_* if - needed. */ - if (name[1] == 'z') - { - char *new_name = bfd_zdebug_name_to_debug (abfd, name); - if (new_name == NULL) - { - arg->failed = true; - return; - } - name = new_name; - } - } - else if (asect->compress_status == COMPRESS_SECTION_DONE - && name[1] == 'd') - { - /* PR binutils/18087: Compression does not always make a - section smaller. So only rename the section when - compression has actually taken place. If input section - name is .zdebug_*, we should never compress it again. */ - char *new_name = bfd_debug_name_to_zdebug (abfd, name); - if (new_name == NULL) - { - arg->failed = true; - return; - } - name = new_name; - } + /* ld: compress DWARF debug sections with names: .debug_*. */ + if (arg->link_info + && (arg->link_info->compress_debug & COMPRESS_DEBUG) != 0 + && (asect->flags & SEC_DEBUGGING) + && 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. */ + delay_st_name_p = true; } if (delay_st_name_p) diff --git a/bfd/section.c b/bfd/section.c index f73e0345e15..30ab6a7d338 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -347,10 +347,6 @@ CODE_FRAGMENT . TMS320C54X only. *} .#define SEC_TIC54X_BLOCK 0x10000000 . -. {* This section should be renamed. This is for ELF linker -. internal use only. *} -.#define SEC_ELF_RENAME 0x10000000 -. . {* Conditionally link this section; do not link if there are no . references found to any symbol in the section. This is for TI . TMS320C54X only. *} diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 6814e20a2fc..19dbb50d3e6 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4118,6 +4118,13 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) flags &= ~clr; } + if (!bfd_convert_section_setup (ibfd, isection, obfd, &name, &size)) + { + osection = NULL; + err = _("failed to create output section"); + goto loser; + } + osection = bfd_make_section_anyway_with_flags (obfd, name, flags); if (osection == NULL) @@ -4126,8 +4133,6 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) goto loser; } - size = bfd_section_size (isection); - size = bfd_convert_section_size (ibfd, isection, obfd, size); if (copy_byte >= 0) size = (size + interleave - 1) / interleave * copy_width; else if (extract_symbol)