public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Peilin Ye <yepeilin.cs@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: binutils@sourceware.org, Cong Wang <xiyou.wangcong@gmail.com>,
	Peilin Ye <peilin.ye@bytedance.com>,
	Nick Clifton <nickc@redhat.com>,
	Peilin Ye <yepeilin.cs@gmail.com>
Subject: Re: [RFC PATCH] bfd: Handle objcopy --only-keep-debug in _bfd_elf_init_private_section_data()
Date: Sat, 29 Jan 2022 01:15:40 -0800	[thread overview]
Message-ID: <20220129091540.GA68164@bytedance> (raw)
In-Reply-To: <YfPnFLgWeZECe6Tt@squeak.grove.modra.org>

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
<peilin.ye@bytedance.com>

[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] {


  parent reply	other threads:[~2022-01-29  9:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28  3:58 Peilin Ye
2022-01-28 12:42 ` Nick Clifton
2022-01-28 12:52 ` Alan Modra
2022-01-28 23:37   ` Peilin Ye
2022-01-29  9:15   ` Peilin Ye [this message]
2022-01-30  1:08     ` Peilin Ye
2022-01-28 23:00 ` [PATCH v2] objcopy: Fix --only-keep-debug Peilin Ye
2022-02-01  0:20   ` [PATCH v3 1/2] objcopy: Fix --only-keep-debug for ELF relocatables Peilin Ye
2022-02-01  0:21   ` [PATCH v3 2/2] binutils/testsuite: Test " Peilin Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220129091540.GA68164@bytedance \
    --to=yepeilin.cs@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.com \
    --cc=peilin.ye@bytedance.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).