From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1AAEB3947C24 for ; Fri, 28 Jan 2022 12:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1AAEB3947C24 Received: by mail-pj1-x102e.google.com with SMTP id d5so6374033pjk.5 for ; Fri, 28 Jan 2022 04:52:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qbKmaP7b6gEDsmuMOTK8pLezH46j/kxsydyWV4Iwihg=; b=GQufFBeLxc1Poma3PI2oSIT0/t+GZzYRmdRrdYD72XYgM1Y5Vi6dYRSrY4slEECzxb 6LNALcnzX9CQ3zweO+roqulYKw9BU7Ty/QxOJwLWVoA3SXGBJeEZfeXbF/IZdNv0dfB8 4gDuH3GMqRWXDCTcO1DkPxwhiiLPXuPVSHvTmGe9Ncx6FrqvF9Pugkj6mEdec0dQdzLq 1/vs1vnkFd3lCxjeRCr83dwIGeXzFUGtVF8lt437z44dM0zp0Wco8rswQYK9fa1GZwt6 O/m13rvAlGGr699wjqS1HKCa+xhN807KKwSRlhz2Wk6MYnIuguUgMFupOXmQqIR2NbHv 3vPQ== X-Gm-Message-State: AOAM533AyBEvKSnJVBnpVgP2B0COpM7B91rhS3mCWo5yfXrmEfuQplFh lpgYUEsRX7KiGUJvsWPENqw= X-Google-Smtp-Source: ABdhPJxEUsmnThLBYY041j+4DRjuoJk78DzozCa7gt5n1tbEnRiO5lcFryTAvKODMHhrWTdI426Hww== X-Received: by 2002:a17:902:bcc6:: with SMTP id o6mr8528999pls.116.1643374361180; Fri, 28 Jan 2022 04:52:41 -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 o7sm8610578pfk.184.2022.01.28.04.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 04:52:39 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 6D60B11403AA; Fri, 28 Jan 2022 23:22:36 +1030 (ACDT) Date: Fri, 28 Jan 2022 23:22:36 +1030 From: Alan Modra To: Peilin Ye Cc: binutils@sourceware.org, Cong Wang , Peilin Ye Subject: Re: [RFC PATCH] bfd: Handle objcopy --only-keep-debug in _bfd_elf_init_private_section_data() Message-ID: References: <20220128035817.65910-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220128035817.65910-1-yepeilin.cs@gmail.com> X-Spam-Status: No, score=-3038.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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 28 Jan 2022 12:52:44 -0000 Thanks for the clear analysis and patch. I think I prefer not to copy the hack I added in elf_fake_sections when it ought to work to simply do the following: * objcopy.c (setup_section): Act on make_nobits after calling bfd_copy_private_section_data. Do you have a testcase we could add to the binutils testsuite? diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d16d8ee67e4..d53aa5c6000 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4085,9 +4085,6 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) goto loser; } - if (make_nobits) - elf_section_type (osection) = SHT_NOBITS; - size = bfd_section_size (isection); size = bfd_convert_section_size (ibfd, isection, obfd, size); if (copy_byte >= 0) @@ -4181,6 +4178,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) goto loser; } + if (make_nobits) + elf_section_type (osection) = SHT_NOBITS; + /* All went well. */ return; -- Alan Modra Australia Development Lab, IBM