From patchwork Fri Jul 28 04:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 127316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp192407vqg; Thu, 27 Jul 2023 21:40:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlFCsTBLEvr5O3DftQVCkDlID2b9pdgTl8qbHiqPwCX8C+mKBuodO0BPzM/uL6q8eX9I/JWk X-Received: by 2002:aa7:c3cf:0:b0:51e:26dc:b35e with SMTP id l15-20020aa7c3cf000000b0051e26dcb35emr669517edr.21.1690519210234; Thu, 27 Jul 2023 21:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690519210; cv=none; d=google.com; s=arc-20160816; b=sTG5OtI4WEiKiRvOD0+z5rHwnxxQ350kUQMmZrcGcC+3MwXv95rSJpFena64u4eyvG Hi+MbgO9L1ZEUvjoCPE2qM0Khedzz9C2P9aHqpGqobZgaaaOyyO+4d9SvKOSBXMm/6HQ d5NNZtdAwjwOAv0aUJQMWGjbjMbP/Sda3eg8fQvPlbAs+WcnTzHk7cAJL0pjftHA1ghU mtPAERI6jdDAtVC6e1IDWY0T7i/BmcXXFmFAnlLoTgHlB0LaScrsybeSmSMhztP7QVTV 90VpOAZH9A0w6z8+cchPeW+m76YSpIqols0dIusW+/UEztqf7Qe2oLMO79EjHCoyiJ4V bKOA== 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=a+EOkrUBVqOWkctHDqPqwzEo5P/Wb11QIlw46xCZpVc=; fh=HNIqzTA9Dp00ovCAyCdXfuEvWDT00OlFxFRPLybXRis=; b=WGeVlmd7eZzF95KtF0URuBr/rFi4mWqB4r8bj8j3Ga+6QlYZ7OtT0bAh0yu4Yw8/zp R2XighzPD5RmETDdfPNlTnc09YFrC/ZtKOOCv3xxtUWslXfWW2d0xO6aUh1eFf917HGQ QZvfBNipWQX9BL9JaNEEIdoTFKjxp7o6zng4QXiapqECtcNZbHLywZd0YYgzJsrZgiJ+ V6d9EjM6nYlaGgWJ5wLVqgnAoSFX9xesog9xfcPGN7hNvtHyvc0EKNabAgvxkAxZ5fuG cYXJ/8/WW/52SkfFgPFWQIHI9M3ei9yCsNpp7bk25M8zx1+Yb0i3IdceVk2xMG3YiA6u jeIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=OQqz4wXo; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bq2-20020a056402214200b005222831c8acsi1497691edb.691.2023.07.27.21.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 21:40:10 -0700 (PDT) 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=OQqz4wXo; 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 25747385AFA4 for ; Fri, 28 Jul 2023 04:40:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25747385AFA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690519209; bh=a+EOkrUBVqOWkctHDqPqwzEo5P/Wb11QIlw46xCZpVc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OQqz4wXot2qERLpNKXekHJ6QkM0TwoAJVGburkDxhlm8ZMwGI6/pv5CYMZ0ylsG6q IyCmqcmwB8DZ1BmBa//JskPennigISmGJsE6ZNLv0TUVnDdJuPanWAPh+rMbrqWQCs 0oK/khY2Wwic196o43FqDQuiBQAWBqHSSu8PxLow= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id C3EED3858D1E for ; Fri, 28 Jul 2023 04:40:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3EED3858D1E Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1bbaa549bcbso1379063fac.3 for ; Thu, 27 Jul 2023 21:40:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690519199; x=1691123999; 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=a+EOkrUBVqOWkctHDqPqwzEo5P/Wb11QIlw46xCZpVc=; b=Py1Sa4CsEH1B0wf+fF0Tnp8ZtSJ8mlCJvDILxVBdGI/B/hvGQE2UGKQV2FyOABfqMA SvKsVpJW2EPPNYPdGtz9mGum5Fz+qgRoWFzOamg5vQSmKJyQHlBtxAV/zbYAyGD//Ztr shTxQC6eC20WMTIJqKc9uY/UrSlRpJOlhOKBh1N3NIfoY7dPeWBIOSqRVN8Xizrbd65j 4U1uz1/s2W7BqHlUDeU4pR/6bHQ+isIWfwSl6e+Pz4fEdkQPwtv8s/eQbvTm2/iUpvGY gKbLuv4eMTue19Y2HBuyWzMVIYYbHU620AQIYhcUDccB8YCObI3qo+4FPD5f29hKURBd FAvw== X-Gm-Message-State: ABy/qLbAaifl/Y0xohFqkieyCJdhJjBeZcQTVUIkEW3ORU9yFUULBwb1 6uLV/LiUAL43yq2mvsNeb7wd7cKKhgU= X-Received: by 2002:a05:6870:e0d0:b0:1aa:192e:9f35 with SMTP id a16-20020a056870e0d000b001aa192e9f35mr2023321oab.26.1690519199462; Thu, 27 Jul 2023 21:39:59 -0700 (PDT) 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 d26-20020aa78e5a000000b006870ff20242sm280213pfr.186.2023.07.27.21.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 21:39:58 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4AD98114001A; Fri, 28 Jul 2023 14:09:56 +0930 (ACST) Date: Fri, 28 Jul 2023 14:09:56 +0930 To: binutils@sourceware.org Subject: coff/pe/xcoff and --extract-symbols Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.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, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1772637871377326127 X-GMAIL-MSGID: 1772637871377326127 This fixes failure of the "extract symbols" test for rs6000, where --extract-symbols generates a non-zero sized .text. By the look of coffcode.h the same problem might occur for coff/pe too, but doesn't happen to trigger a test failure. bfd/ * coffcode.h (coff_compute_section_file_positions): Don't adjust size of !SEC_LOAD sections. binutils/ * objcopy.c (setup_section): Clear SEC_LOAD for --extract-symbol. diff --git a/bfd/coffcode.h b/bfd/coffcode.h index f37d029ef75..6c8080c841e 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -3176,8 +3176,9 @@ coff_compute_section_file_positions (bfd * abfd) created and not just improve performances with gdb. */ - if ((!strcmp (current->name, _TEXT) - || !strcmp (current->name, _DATA)) + if ((current->flags & SEC_LOAD) != 0 + && (!strcmp (current->name, _TEXT) + || !strcmp (current->name, _DATA)) && (previous == NULL || strcmp(previous->name, _TDATA))) { bfd_vma align = 4096; @@ -3190,7 +3191,8 @@ coff_compute_section_file_positions (bfd * abfd) sofar += align + vma_off - sofar_off; } #endif - if (previous != NULL) + if (previous != NULL + && (previous->flags & SEC_LOAD) != 0) previous->size += sofar - old_sofar; } diff --git a/binutils/objcopy.c b/binutils/objcopy.c index beb655cafc2..b2b7ab6ab7e 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4161,13 +4161,25 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC)); flags = check_new_section_flags (flags, obfd, bfd_section_name (isection)); } - else if (strip_symbols == STRIP_NONDEBUG - && (flags & (SEC_ALLOC | SEC_GROUP)) != 0 - && !is_nondebug_keep_contents_section (ibfd, isection)) + else { - flagword clr = SEC_HAS_CONTENTS | SEC_LOAD | SEC_GROUP; - - if (bfd_get_flavour (obfd) == bfd_target_elf_flavour) + flagword clr = 0; + + /* For --extract-symbols where section sizes are zeroed, clear + SEC_LOAD to indicate to coff_compute_section_file_positions that + section sizes should not be adjusted for ALIGN_SECTIONS_IN_FILE. + We don't want to clear SEC_HAS_CONTENTS as that will result + in symbols being classified as 'B' by nm. */ + if (extract_symbol) + clr = SEC_LOAD; + /* If only keeping debug sections then we'll be keeping section + sizes in headers but making the sections have no contents. */ + else if (strip_symbols == STRIP_NONDEBUG + && (flags & (SEC_ALLOC | SEC_GROUP)) != 0 + && !is_nondebug_keep_contents_section (ibfd, isection)) + clr = SEC_HAS_CONTENTS | SEC_LOAD | SEC_GROUP; + + if (clr && bfd_get_flavour (obfd) == bfd_target_elf_flavour) { /* PR 29532: Copy group sections intact as otherwise we end up with empty groups. This prevents separate debug info files from @@ -4175,7 +4187,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) originally contained groups. */ if (flags & SEC_GROUP) clr = SEC_LOAD; - else + if ((clr & SEC_HAS_CONTENTS) != 0) make_nobits = true; /* Twiddle the input section flags so that it seems to