From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-oa1-x2d.google.com with SMTP id 586e51a60fabf-1bbaa549bcbso1379063fac.3 for ; Thu, 27 Jul 2023 21:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690519199; x=1691123999; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=a+EOkrUBVqOWkctHDqPqwzEo5P/Wb11QIlw46xCZpVc=; b=gMW11eG8ZThC5Q6GKYFCjBOpbuVNM+OTCCrBS9IuJsANVrfnds7rT/jBzcRHQsITtt YEtJ1MlfCAnJIMj5VrCu38VfiKrbP+xGFrYlY76tey5A9pkAyMwSpnsFKI4UpqcGYUxz fwu1ACwCOpsbytNylUNJXf6cKp3vxGKd+cMwEz1OO8VfasLfZCspMwfMbenMHIk8HqUJ thYjvzl3Bz83xdx27lECj2xNboah1dFx31jYRykBYtE8w2VlfWc1y9Le86WaD9TJ3DvD +NOx1JRWoAeukvd04jknZaPVwrtXTjcQtiSgufmWUnq9OHh4imLVT1uXNlBCAW4WJSBN 0iMg== 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-Google-Smtp-Source: APBJJlGVaZ5Z42HIUbeizNiaO1/HvUyvYJHaiJv1hWoYBHt7XGnpwW9LEPUJOiudYZkinJ9gqnhp6g== 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 From: Alan Modra To: binutils@sourceware.org Subject: coff/pe/xcoff and --extract-symbols Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: 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 -- Alan Modra Australia Development Lab, IBM