public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Peilin Ye <yepeilin.cs@gmail.com>
To: binutils@sourceware.org
Cc: Nick Clifton <nickc@redhat.com>, Alan Modra <amodra@gmail.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Peilin Ye <yepeilin.cs@gmail.com>,
	Peilin Ye <peilin.ye@bytedance.com>
Subject: [PATCH v4] binutils/testsuite: Test --only-keep-debug on ELF relocatables
Date: Wed,  2 Feb 2022 22:33:22 -0800	[thread overview]
Message-ID: <20220203063322.72281-1-yepeilin.cs@gmail.com> (raw)

From: Peilin Ye <peilin.ye@bytedance.com>

Add a test for commit 7c4643efe7be, which fixed --only-keep-debug for ELF
relocatables.

binutils/ChangeLog:
    * testsuite/binutils-all/objcopy.exp
      (keep_debug_symbols_for_elf_relocatable): Test if --only-keep-debug
      marks non-debug output sections as NOBITS for ELF relocatables
---
change since v3:
    - deleted unnecessary tag and improved commit message

 binutils/testsuite/binutils-all/objcopy.exp | 57 +++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index bb80c1f0b554..3dbb512b69cf 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -967,6 +967,60 @@ proc keep_debug_symbols_and_check_links { prog flags test } {
     }
 }
 
+# For ELF relocatables, test that --only-keep-debug
+# marks non-debug output sections as NOBITS.
+
+proc keep_debug_symbols_for_elf_relocatable { prog flags test } {
+    global srcdir
+    global subdir
+    global READELF
+
+    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
+        untested $test
+        return
+    }
+
+    if [is_remote host] {
+        set relocatable [remote_download host tmpdir/testprog.o]
+    } else {
+        set relocatable tmpdir/testprog.o
+    }
+
+    set non_debug_sections {}
+    set got [binutils_run $READELF "-S --wide ${relocatable}"]
+    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 $prog "$flags ${relocatable}"]
+    if ![string equal "" $exec_output] {
+        fail $test
+        return
+    }
+
+    set fails 0
+    set got [binutils_run $READELF "-S --wide ${relocatable}"]
+    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 == 1 } {
+        fail $test
+        return
+    }
+
+    pass $test
+}
 
 set test1 "simple objcopy of executable"
 set test1r "run objcopy of executable"
@@ -978,6 +1032,7 @@ set test4 "keep only debug data"
 set test5 "simple objcopy of debug data"
 if [is_elf_format] {
     set test6 "NOBITS sections retain sh_link field"
+    set test7 "--only-keep-debug for ELF relocatables"
 }
 
 switch [copy_setup] {
@@ -1008,6 +1063,7 @@ switch [copy_setup] {
 					 "$OBJCOPY" "$OBJCOPYFLAGS" "$test5"
 	if [is_elf_format] {
 	    keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6"
+	    keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7"
 	}
     }
     "0" {
@@ -1018,6 +1074,7 @@ switch [copy_setup] {
 					 "$OBJCOPY" "$OBJCOPYFLAGS" "$test5"
 	if [is_elf_format] {
 	    keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6"
+	    keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7"
 	}
     }
 }
-- 
2.20.1


             reply	other threads:[~2022-02-03  6:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03  6:33 Peilin Ye [this message]
2022-02-09  8:40 ` Alan Modra

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=20220203063322.72281-1-yepeilin.cs@gmail.com \
    --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).