[binutils-gdb/binutils-2_38-branch] objcopy --only-keep-debug

Alan Modra amodra@sourceware.org
Sat Feb 5 08:29:50 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68f543154e92ab0f5d6c569e0fa143f5e8bd2d80

commit 68f543154e92ab0f5d6c569e0fa143f5e8bd2d80
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Jan 28 23:08:27 2022 +1030

    objcopy --only-keep-debug
    
    From: Peilin Ye <peilin.ye@bytedance.com>
    objcopy's --only-keep-debug option has been broken for ELF files since
    commit 8c803a2dd7d3.
    
      1. binutils/objcopy.c:setup_section() marks non-debug sections as
         SHT_NOBITS, then calls bfd_copy_private_section_data();
      2. If ISEC and OSEC share the same section flags,
         bfd/elf.c:_bfd_elf_init_private_section_data() restores OSEC's
         section type back to ISEC's section type, effectively undoing
         "make_nobits".
    
            * objcopy.c (setup_section): Act on make_nobits after calling
            bfd_copy_private_section_data.
    
    (cherry picked from commit 7c4643efe7befea8e5063e8b56c0400fd8cee2d5)

Diff:
---
 binutils/objcopy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d16d8ee67e4..d53aa5c6000 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4085,9 +4085,6 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
       goto loser;
     }
 
-  if (make_nobits)
-    elf_section_type (osection) = SHT_NOBITS;
-
   size = bfd_section_size (isection);
   size = bfd_convert_section_size (ibfd, isection, obfd, size);
   if (copy_byte >= 0)
@@ -4181,6 +4178,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
       goto loser;
     }
 
+  if (make_nobits)
+    elf_section_type (osection) = SHT_NOBITS;
+
   /* All went well.  */
   return;


More information about the Binutils-cvs mailing list