From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BFD773858402 for ; Fri, 28 Jan 2022 12:42:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFD773858402 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-6X2kzbdFN5Ckp4afbFIOhg-1; Fri, 28 Jan 2022 07:42:11 -0500 X-MC-Unique: 6X2kzbdFN5Ckp4afbFIOhg-1 Received: by mail-wm1-f69.google.com with SMTP id l20-20020a05600c1d1400b0035153bf34c3so3096412wms.2 for ; Fri, 28 Jan 2022 04:42:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:subject:in-reply-to :content-transfer-encoding; bh=si4+ZkOoUlg7vSA157Yklsy2U4kLUvqH/mhCeApS2Zo=; b=FLWg3zmoHso0UpqvNuSsqsWc3A72oi8B032Smsn3Hec4pzXVyjhwy/BOh2B2Xz+Eup Y0DgsssZ6nh4lVudeuwKUSeJ39kR9m890YW0L3VWs4od9OfRcZN94sK/ElkwDjDujVue mQqVH+9mEIIe4WbePig9rwWLKOGaEQtJ36eWTEUXwfI+6z80mRxvEPwKIKtAJ2An02kU RN1zCFyoXfBynLR/JRO+ZlK4QAD8SF0yFhgzEkNdOKoh1XWfl/PVQtvaTYTGsS0Tg9OA 1E0fSS+GS5e0v066P5l3u8knkPyWpEngk0vxDUvIaidbA6FayArXmmc519RwNexzGrrE zpAg== X-Gm-Message-State: AOAM5338tD1SswRz4Eaw3dZ+Zg0CzS7YDNznTqrKD3GKHpr7+f9labln M0HJc92EBT/OBFHaMzvdB7cBAWeEKDeA2vyVOHF9zf1hsWdCneu5lDBNNUtX9tQQQLXO55Mz+gU rxbyDokGczumax2UN9g== X-Received: by 2002:a5d:4612:: with SMTP id t18mr7431805wrq.77.1643373729843; Fri, 28 Jan 2022 04:42:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1emVex2zu65YGH8faKJWZRBaF1eDdL5LpmB1zAC3XijqO7WJLSEvnDcNmDldGCKLmN1QDNg== X-Received: by 2002:a5d:4612:: with SMTP id t18mr7431785wrq.77.1643373729648; Fri, 28 Jan 2022 04:42:09 -0800 (PST) Received: from [192.168.1.6] (adsl-164-239.freeuk.com. [80.168.164.239]) by smtp.gmail.com with ESMTPSA id j19sm2057989wmq.17.2022.01.28.04.42.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 04:42:09 -0800 (PST) Message-ID: <316159a4-8784-67eb-13e1-8feee4c76308@redhat.com> Date: Fri, 28 Jan 2022 12:42:08 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 To: Peilin Ye , binutils@sourceware.org Cc: Cong Wang , Peilin Ye References: <20220128035817.65910-1-yepeilin.cs@gmail.com> From: Nick Clifton Subject: Re: [RFC PATCH] bfd: Handle objcopy --only-keep-debug in _bfd_elf_init_private_section_data() In-Reply-To: <20220128035817.65910-1-yepeilin.cs@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-GB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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:42:13 -0000 Hi Peilin, > objcopy's --only-keep-debug option has been broken for ELF files since > commit 8c803a2dd7d3 ("elf_backend_section_flags and > _bfd_elf_init_private_section_data"): > > 1. binutils/objcopy.c:setup_section() marks non-debug sections as > SHT_NOBITS, then calls bfd_copy_private_section_data(), see > "mark_nobits"; > 2. If ISEC and OSEC share the same section flags, > bfd/elf.c:_bfd_elf_init_private_section_data() restores OSEC's > section type back to ISEC's section type, effectively undoing > "mark_nobits". > > This makes objcopy's --only-keep-debug a no-op. As an example, Linux's > scripts/package/builddeb script depends on this option to generate > debug-info-only kernel modules. > > Handle this special case by checking OSEC's size in addition to its > type (similar to bfd/elf.c:elf_fake_sections()). A non-debug section > marked as SHT_NOBITS by --only-keep-debug should have a non-zero size. I have a feeling that this change is going to have wider repercussions than simply fixing this problem. It is going to affect those sections created by elf_fake_sections() for example, and I bet that there will be other scenarios that have not occurred to me. Possibly a better fix would be to change objcopy instead so that it can cope with the behaviour of bfd_copy_private_section_data(). For example, please could you try out this patch and see if it fixes the problem ? diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d16d8ee67e4..14b76d8a65a 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4180,6 +4180,10 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg) err = _("failed to copy private data"); goto loser; } + /* Since isec.flags == osec.flags, bfd_copy_private_section_data() + will reset the section type. */ + if (make_nobits) + elf_section_type (osection) = SHT_NOBITS; /* All went well. */ return; > This patch is manually tested only. Which testsuite(s) > should I use to test this patch? Please run the binutils testsuite. ie: cd /binutils make check Cheers Nick