This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: RFC: Objcopy --only-keep-debug update
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 7 Aug 2015 10:38:39 -0700
- Subject: Re: RFC: Objcopy --only-keep-debug update
- Authentication-results: sourceware.org; auth=none
- References: <87oaingwhv dot fsf at redhat dot com> <CAMe9rOpJkr1rAzAUtpr0GfUou6319R_jN1GxLMvg1YD8OMv_0g at mail dot gmail dot com>
On Fri, Aug 7, 2015 at 8:56 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Aug 4, 2015 at 3:48 AM, Nick Clifton <nickc@redhat.com> wrote:
>> Hi Guys,
>>
>> Thanks for the comments on the previous patch. I am attaching a third
>> iteration of this patch, which I hope will satisfy everyone. In this
>> version I have followed Alan's suggestion of detecting the change in
>> the _bfd_elf_copy_private_bfd_data function, and I have fixed the text
>> in binutils.texi describing how --only-keep-debug operates.
>>
>> Any more comments or suggestions ?
>>
>> Cheers
>> Nick
>>
>> bfd/ChangeLog
>> 2015-08-04 Nick Clifton <nickc@redhat.com>
>>
>> * elf.c (_bfd_elf_copy_private_bfd_data): Copy the sh_link and
>> sh_info fields of sections whose type has been changed to
>> SHT_NOBITS.
>>
>> binutils/ChangeLog
>> 2015-08-04 Nick Clifton <nickc@redhat.com>
>>
>> * doc/binutils.texi: Document that the --only-keep-debug option
>> to strip and objcopy preserves the section headers of stripped
>> sections.
>>
>> binutils/testsuite/ChangeLog
>> 2015-08-04 Nick Clifton <nickc@redhat.com>
>>
>> * binutils-all/objcopy.exp (keep_debug_symbols_and_check_links):
>> New proc. Checks that debug-info-only binaries retain the
>> sh_link field in stripped sections.
>>
>
> This breaks binutils:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=18785
>
I checked in this patch to fix it.
--
H.J.
---
When copying the sh_link and sh_info fields in stripped section headers,
we also check if the sh_type, sh_flags, /sh_addralign and sh_entsize
fields of the output section match the output. Since --only-keep-debug
turns all non-debug sections into SHT_NOBITS sections, the output
SHT_NOBITS type matches any input type.
bfd/
PR binutils/18785
* elf.c (_bfd_elf_copy_private_bfd_data): When copying the
sh_link and sh_info fields in stripped section headers, we also
check if the sh_type, sh_flags, /sh_addralign and sh_entsize
fields of the output section match the output. Since
--only-keep-debug turns all non-debug sections into SHT_NOBITS
sections, the output SHT_NOBITS type matches any input type.
binutils/testsuite/
PR binutils/18785
* binutils-all/objcopy.exp: Run strip-12.
* binutils-all/strip-12.d: New file.
* binutils-all/strip-12.s: Likewise.
-
From 115b1941bf2bd062e3f2372a475639a12a3da1a1 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 7 Aug 2015 10:28:42 -0700
Subject: [PATCH] Check sh_type/sh_flags/sh_addralign/sh_entsize when copying
sh_link/sh_info
When copying the sh_link and sh_info fields in stripped section headers,
we also check if the sh_type, sh_flags, /sh_addralign and sh_entsize
fields of the output section match the output. Since --only-keep-debug
turns all non-debug sections into SHT_NOBITS sections, the output
SHT_NOBITS type matches any input type.
bfd/
PR binutils/18785
* elf.c (_bfd_elf_copy_private_bfd_data): When copying the
sh_link and sh_info fields in stripped section headers, we also
check if the sh_type, sh_flags, /sh_addralign and sh_entsize
fields of the output section match the output. Since
--only-keep-debug turns all non-debug sections into SHT_NOBITS
sections, the output SHT_NOBITS type matches any input type.
binutils/testsuite/
PR binutils/18785
* binutils-all/objcopy.exp: Run strip-12.
* binutils-all/strip-12.d: New file.
* binutils-all/strip-12.s: Likewise.
---
bfd/elf.c | 9 ++++++++-
binutils/testsuite/binutils-all/objcopy.exp | 1 +
binutils/testsuite/binutils-all/strip-12.d | 7 +++++++
binutils/testsuite/binutils-all/strip-12.s | 6 ++++++
4 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 binutils/testsuite/binutils-all/strip-12.d
create mode 100644 binutils/testsuite/binutils-all/strip-12.s
diff --git a/bfd/elf.c b/bfd/elf.c
index 67e4240..9e401c8 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1233,7 +1233,14 @@ _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{
Elf_Internal_Shdr * iheader = iheaders[j];
- if (iheader->sh_type != SHT_NOBITS
+ /* Since --only-keep-debug turns all non-debug sections
+ into SHT_NOBITS sections, the output SHT_NOBITS type
+ matches any input type. */
+ if ((oheader->sh_type == SHT_NOBITS
+ || oheader->sh_type == oheader->sh_type)
+ && iheader->sh_flags == oheader->sh_flags
+ && iheader->sh_addralign == oheader->sh_addralign
+ && iheader->sh_entsize == oheader->sh_entsize
&& iheader->sh_size == oheader->sh_size
&& iheader->sh_addr == oheader->sh_addr
&& (iheader->sh_info != oheader->sh_info
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index 75514e4..cb8e33b 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -1033,6 +1033,7 @@ if [is_elf_format] {
run_dump_test "strip-7"
run_dump_test "strip-8"
run_dump_test "strip-9"
+ run_dump_test "strip-12"
# Non-EABI ARM targets will set OSABI to ARM
# The V850 sets the OSABI to UNIX - System V
if { ![istarget "*-*-hpux*"]
diff --git a/binutils/testsuite/binutils-all/strip-12.d b/binutils/testsuite/binutils-all/strip-12.d
new file mode 100644
index 0000000..a33faab
--- /dev/null
+++ b/binutils/testsuite/binutils-all/strip-12.d
@@ -0,0 +1,7 @@
+#PROG: strip
+#strip:
+#readelf: -S --wide
+
+#...
+ \[[ 0-9]+\] \.bss[ \t]+NOBITS[ \t0-9a-f]+WA[ \t]+0[ \t]+0[ \t]+1
+#pass
diff --git a/binutils/testsuite/binutils-all/strip-12.s b/binutils/testsuite/binutils-all/strip-12.s
new file mode 100644
index 0000000..46b729f
--- /dev/null
+++ b/binutils/testsuite/binutils-all/strip-12.s
@@ -0,0 +1,6 @@
+ .bss
+ .space 8
+ .section .debug_str,"MS",%progbits,1
+ .string ""
+ .section .text.foo,"axG",%progbits,foo,comdat
+ .byte 0
--
2.4.3