From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id A0F563858D28 for ; Sat, 29 Jan 2022 09:15:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0F563858D28 Received: by mail-qk1-x730.google.com with SMTP id j24so5421223qkk.10 for ; Sat, 29 Jan 2022 01:15:44 -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=VknZbHFi+w+kr4WOS70QjRdxjiul1EKxuoPQs1iqAuk=; b=prSpshZ5YtpUoLf1kYu78b9o4aKYhAKA/ty0oxl3RP/KUhxCRyDitptn/tNxrJOXw3 xzZZfwUy8LA842Ljv6PkA3p33TPcE44ZPxQfb8PMF72kMpLuTEj6Tcix/2VPiUGywUJ+ EOaQmzWC6cLvIoTtAKIyMQiqwPleA1X/XfkO0qF3X0qJwKRvqIviftztkuZplYq+50Aq +7K4wnorOb5xZNz0tNb6I6oHONXe8BuZKOz5bd9wa7vVERqLW/PGQYYdepFkNFrt7bv6 0gF/nc093dTCLDOV4nPYQu/J6hW/5qwjYxRdfr4Z2Yxk0wRbLrYC/EtTe296jpOLvUKw wKJg== X-Gm-Message-State: AOAM532bkbmpWIQQgceGMo1cFIlSjtLvOypv/HjAlNRa3+BnIh4mtpww A5HL6ITnjw22hD4iMtmcbA== X-Google-Smtp-Source: ABdhPJxdKT8bd+Twfzm6WjdGI1gBb0aFDmsRjyc2HlF+ljzebBv3EzrNqphTs4a1sL4Fp0luYf1KNw== X-Received: by 2002:a37:c4d:: with SMTP id 74mr8054370qkm.619.1643447744291; Sat, 29 Jan 2022 01:15:44 -0800 (PST) Received: from bytedance (ec2-52-52-7-82.us-west-1.compute.amazonaws.com. [52.52.7.82]) by smtp.gmail.com with ESMTPSA id g20sm4860135qko.27.2022.01.29.01.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 01:15:43 -0800 (PST) Date: Sat, 29 Jan 2022 01:15:40 -0800 From: Peilin Ye To: Alan Modra Cc: binutils@sourceware.org, Cong Wang , Peilin Ye , Nick Clifton , Peilin Ye Subject: Re: [RFC PATCH] bfd: Handle objcopy --only-keep-debug in _bfd_elf_init_private_section_data() Message-ID: <20220129091540.GA68164@bytedance> 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: X-Spam-Status: No, score=-11.5 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: Sat, 29 Jan 2022 09:15:45 -0000 Hi Alan, On Fri, Jan 28, 2022 at 11:22:36PM +1030, Alan Modra wrote: > Do you have a testcase we could add to the binutils testsuite? I just added a check [1] to objcopy.exp:keep_debug_symbols_and_test_copy(), but unfortunately it is not testing anything: It seems that --only-keep-debug is broken for Linux kernel .ko modules, but it works just fine on tmpdir/striprog (built from testprog.c) used by this testsuite... I will take another look tomorrow and try to figure out what is so special about Linux modules, then come up with a better test. Maybe we should also mention this in the commit message of the fix. Thanks, Peilin Ye [1] diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index bb80c1f0b554..1ad90a776c48 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -890,6 +890,8 @@ proc strip_executable_with_saving_a_symbol { prog flags test1 test2 } { # Test keeping only debug symbols of an executable proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } { + global READELF + remote_file build delete tmpdir/striprog remote_download build tmpdir/copyprog tmpdir/striprog if [is_remote host] { @@ -898,12 +900,45 @@ proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } set copyfile tmpdir/striprog } + set non_debug_sections {} + if [is_elf_format] { + set got [binutils_run $READELF "-S --wide ${copyfile}"] + while {[regexp \ + {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+([A-Z]*)[ \t]+[0-9]+(.*)} \ + $got all name type flag rest]} { + if {$type != "NOTE" && [regexp {[AG]} $flag]} { + lappend non_debug_sections $name + } + set got $rest + } + } + set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"] if ![string equal "" $exec_output] { fail $test1 return } - pass $test1 + + set fails 0 + if [is_elf_format] { + set got [binutils_run $READELF "-S --wide ${copyfile}"] + while {[regexp \ + {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+[A-Z]*[ \t]+[0-9]+(.*)} \ + $got all name type rest]} { + if {[lsearch -exact $non_debug_sections $name] >= 0 && $type != "NOBITS"} { + set fails 1 + send_log "Expected SHT_NOBITS type for .$name\n" + } + set got $rest + } + } + + if {$fails == 0} { + pass $test1 + } else { + fail $test1 + return + } set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"] if ![string equal "" $exec_output] {