From patchwork Wed Dec 7 05:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 30643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2011wrr; Tue, 6 Dec 2022 21:57:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Oy6nMMI4iiWPYKbDEeNJ3zWKMjqZjeH15Ne5O5RlFGWEmR2v1XWnFk64efWQ5fSzCYlTu X-Received: by 2002:a17:907:a489:b0:7c0:c14f:73d7 with SMTP id vp9-20020a170907a48900b007c0c14f73d7mr18249813ejc.52.1670392659310; Tue, 06 Dec 2022 21:57:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670392659; cv=none; d=google.com; s=arc-20160816; b=jYl6sRV6g99ALx0bJ3im5sFWTjqnjoq38INF+BF+JWCLDrEBlavKUAyXEXV3YP/g1e w2oX6cQstMjwSRfIPfk1pXpFLvVbtLsLW0CexugaS7BpmJv6ydAFrge7VywPn32BAzGw zeNC2BaoatIFnEIajcbX2zWwJ3Oqm1ZlQnW9uZd0td8PFsWxJWujd37TESsceD8VqrWL E39k105aKJ0HslSwOxsldnv3va9sp0aG2U/Vh28zryUchAjoiW+a5kghKOyt6gDNIgJf Ny1nH8Ux/VrLblufzIMcAniejh0yPJJdL+mB2ltgbN62WiaXzEWq3UgQkfMeowst52JY JXkg== 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=SmdUYyfCGdlHnGJ08LJY8lBBfrnEqQTmQo3S4Y8kUOU=; b=0c8Lz47lUS4r8m9TYGZIOo3f7HqxoNeuIvQHmoF7rYQFfKOp3RtNXmh2wmSwPnBnHB D/TJNy0C2k3zPbTnG7/I8jJhoeXCr6KkMinB7arQ6zHElDP+vIDNOXHmJC1fsJNF0/zE aEz5h+qK8MyQC66uLM4yqPIAwa8tiIOGJyu4Y7bQOY1W1DWzX9ep1CxqRHYU164nkmL3 lazcR5cm8BVgLb2fxW10t1ijXZYJX90tbxO5IAgpC7SPDzfaovNf3Tvm+IqN2UGm9cIh mPfVMQRxF7dsp6kaWBd3+O6C38ibt5ZH+V0ELjpq3bmqLUweLq/u+Kv88uY0pvRPxDnP v6oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oBzSeN7D; 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 g5-20020a1709065d0500b007bf70b8527asi11385387ejt.563.2022.12.06.21.57.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 21:57:39 -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=oBzSeN7D; 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 8037C3844002 for ; Wed, 7 Dec 2022 05:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8037C3844002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670392657; bh=SmdUYyfCGdlHnGJ08LJY8lBBfrnEqQTmQo3S4Y8kUOU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oBzSeN7DvjfKiYFpPU1gfGPcz3iMyu5dZHRxoiGnrc2luN7x7FR0OqKyHihnM9DwR 8FWUwIyU9hf1ql9MaAxJw/2m/zvN9YSmbzUu2sKkvHbj4NX5HVN7wrA8ow9hcVqIdm sMq4RqvAKJNWNE7UrLt4S4RAl8MJWkuqG81p9fis= 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 AE52B384F4A5 for ; Wed, 7 Dec 2022 05:57:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE52B384F4A5 Received: by mail-pj1-x102e.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so488669pjs.4 for ; Tue, 06 Dec 2022 21:57:28 -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=SmdUYyfCGdlHnGJ08LJY8lBBfrnEqQTmQo3S4Y8kUOU=; b=z95ejc/MvaZZDXZWTYSb3P3qoo6qoLCMWxhu03bYss6jDnsCgHEVijJkP6xDM8OSz7 FGPFWEJKnhwDKbZlN12xCRV272FJSdg/PKLH5y8kSr0FeMcm7vrCcUJzPIrVpPKwyUZQ 7uSMVF8CokYolRx8rLBhLP/QuesZCbN3JLntC+RVDVGvl+Mrs1lJVAPm/L2rnIQEbHIk xaOQ+Z2AV7Q0npjzkGgYUSIy4Gn73OdSgUJpDyfokVcfu0gm/PAOylM2LcZvOkPaxQiR 1aUI83jJ0FCUFDrbXAEhSw360CxU3k6Xi7+s6EiUBurnQbUSrooOG+5Vb4pBGmEqu7rt vSNg== X-Gm-Message-State: ANoB5pkb3erVNsK5P/G2hsC/lKYnBQPr3KAYnhFHdLAyuVJ+pboMH3Eq ZVl5LGISPiU95Yarg/Iikf3AXFD2v2I= X-Received: by 2002:a17:902:d413:b0:189:eb37:253 with SMTP id b19-20020a170902d41300b00189eb370253mr6099686ple.23.1670392647520; Tue, 06 Dec 2022 21:57: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 a10-20020a1709027e4a00b0018913417ba2sm13565525pln.130.2022.12.06.21.57.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 21:57:27 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D139E1142D14; Wed, 7 Dec 2022 16:27:24 +1030 (ACDT) Date: Wed, 7 Dec 2022 16:27:24 +1030 To: binutils@sourceware.org Subject: coff make_a_section_from_file tidy Message-ID: MIME-Version: 1.0 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 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?1751533652754524497?= X-GMAIL-MSGID: =?utf-8?q?1751533652754524497?= Also support compressing a few more sections. * coffgen.c (make_a_section_from_file): Rename return_section to newsect. Don't try to be clever matching section name. Compress .gnu.debuglto_.debug_ and .gnu.linkonce.wi. too. Only rename debug sections when decompressing for linker. diff --git a/bfd/coffgen.c b/bfd/coffgen.c index e072e168cb8..09f5a28c435 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -51,7 +51,7 @@ make_a_section_from_file (bfd *abfd, struct internal_scnhdr *hdr, unsigned int target_index) { - asection *return_section; + asection *newsect; char *name; bool result = true; flagword flags; @@ -107,34 +107,33 @@ make_a_section_from_file (bfd *abfd, name[sizeof (hdr->s_name)] = 0; } - return_section = bfd_make_section_anyway (abfd, name); - if (return_section == NULL) + newsect = bfd_make_section_anyway (abfd, name); + if (newsect == NULL) return false; - return_section->vma = hdr->s_vaddr; - return_section->lma = hdr->s_paddr; - return_section->size = hdr->s_size; - return_section->filepos = hdr->s_scnptr; - return_section->rel_filepos = hdr->s_relptr; - return_section->reloc_count = hdr->s_nreloc; + newsect->vma = hdr->s_vaddr; + newsect->lma = hdr->s_paddr; + newsect->size = hdr->s_size; + newsect->filepos = hdr->s_scnptr; + newsect->rel_filepos = hdr->s_relptr; + newsect->reloc_count = hdr->s_nreloc; - bfd_coff_set_alignment_hook (abfd, return_section, hdr); + bfd_coff_set_alignment_hook (abfd, newsect, hdr); - return_section->line_filepos = hdr->s_lnnoptr; + newsect->line_filepos = hdr->s_lnnoptr; - return_section->lineno_count = hdr->s_nlnno; - return_section->userdata = NULL; - return_section->next = NULL; - return_section->target_index = target_index; + newsect->lineno_count = hdr->s_nlnno; + newsect->userdata = NULL; + newsect->next = NULL; + newsect->target_index = target_index; - if (! bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, return_section, - & flags)) + if (!bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, newsect, &flags)) result = false; /* At least on i386-coff, the line number count for a shared library section must be ignored. */ if ((flags & SEC_COFF_SHARED_LIBRARY) != 0) - return_section->lineno_count = 0; + newsect->lineno_count = 0; if (hdr->s_nreloc != 0) flags |= SEC_RELOC; @@ -142,20 +141,19 @@ make_a_section_from_file (bfd *abfd, if (hdr->s_scnptr != 0) flags |= SEC_HAS_CONTENTS; - return_section->flags = flags; + newsect->flags = flags; - /* Compress/decompress DWARF debug sections with names: .debug_* and - .zdebug_*, after the section flags is set. */ + /* Compress/decompress DWARF debug sections. */ if ((flags & SEC_DEBUGGING) != 0 && (flags & SEC_HAS_CONTENTS) != 0 - && strlen (name) > 7 - && ((name[1] == 'd' && name[6] == '_') - || (strlen (name) > 8 && name[1] == 'z' && name[7] == '_'))) + && (startswith (name, ".debug_") + || startswith (name, ".zdebug_") + || startswith (name, ".gnu.debuglto_.debug_") + || startswith (name, ".gnu.linkonce.wi."))) { enum { nothing, compress, decompress } action = nothing; - char *new_name = NULL; - if (bfd_is_section_compressed (abfd, return_section)) + if (bfd_is_section_compressed (abfd, newsect)) { /* Compressed section. Check if we should decompress. */ if ((abfd->flags & BFD_DECOMPRESS)) @@ -164,50 +162,40 @@ make_a_section_from_file (bfd *abfd, else { /* Normal section. Check if we should compress. */ - if ((abfd->flags & BFD_COMPRESS) && return_section->size != 0) + if ((abfd->flags & BFD_COMPRESS) && newsect->size != 0) action = compress; } - switch (action) + if (action == compress) { - case nothing: - break; - case compress: - if (!bfd_init_section_compress_status (abfd, return_section)) + if (!bfd_init_section_compress_status (abfd, newsect)) { _bfd_error_handler - /* xgettext: c-format */ - (_("%pB: unable to compress section %s"), - abfd, name); + /* xgettext:c-format */ + (_("%pB: unable to compress section %s"), abfd, name); return false; } - if (return_section->compress_status == COMPRESS_SECTION_DONE - && name[1] != 'z') - { - new_name = bfd_debug_name_to_zdebug (abfd, name); - if (new_name == NULL) - return false; - } - break; - case decompress: - if (!bfd_init_section_decompress_status (abfd, return_section)) + } + else if (action == decompress) + { + if (!bfd_init_section_decompress_status (abfd, newsect)) { _bfd_error_handler - /* xgettext: c-format */ - (_("%pB: unable to decompress section %s"), - abfd, name); + /* xgettext:c-format */ + (_("%pB: unable to decompress section %s"), abfd, name); return false; } - if (name[1] == 'z') + if (abfd->is_linker_input + && name[1] == 'z') { - new_name = bfd_zdebug_name_to_debug (abfd, 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); } - break; } - if (new_name != NULL) - bfd_rename_section (return_section, new_name); } return result;