Check sh_type/sh_flags/sh_addralign/sh_entsize when copying sh_link/sh_info
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 7 Aug 2015 17:28:42 +0000 (10:28 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 7 Aug 2015 17:35:58 +0000 (10:35 -0700)
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/ChangeLog
bfd/elf.c
binutils/testsuite/ChangeLog
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/binutils-all/strip-12.d [new file with mode: 0644]
binutils/testsuite/binutils-all/strip-12.s [new file with mode: 0644]

index 36fae0eb91439dd14471b4ac80bf0d0c6eb36fc4..c319f80b8f1c5dd25fcca1187d6bf8a710405dc6 100644 (file)
@@ -1,3 +1,13 @@
+2015-08-07  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2015-08-07  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/18720
index 67e4240dac196e618e6326221c5d8c8398576d50..9e401c8f04aee8310d8169a4ab52fabba59321f8 100644 (file)
--- 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
index 8f8f3c2276f8aad5706e7a039872b9f5c1e0da53..4f60f93fd3076e1f383ae9d10865dbd8c341731c 100644 (file)
@@ -1,3 +1,10 @@
+2015-08-07  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/18785
+       * binutils-all/objcopy.exp: Run strip-12.
+       * binutils-all/strip-12.d: New file.
+       * binutils-all/strip-12.s: Likewise.
+
 2015-08-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * binutils-all/objcopy.exp: Run new symbol tests.
index 75514e42ce5dbfbf95f4ee3694daf252ef361b84..cb8e33b5f7108f759ec858f1fad2ec01eb3a331a 100644 (file)
@@ -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 (file)
index 0000000..a33faab
--- /dev/null
@@ -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 (file)
index 0000000..46b729f
--- /dev/null
@@ -0,0 +1,6 @@
+       .bss
+       .space 8
+       .section        .debug_str,"MS",%progbits,1
+       .string ""
+       .section        .text.foo,"axG",%progbits,foo,comdat
+       .byte 0