[PATCH] objcopy: Allow --dump-section to dump an empty SEC_HAS_CONTENTS section
authorFangrui Song <maskray@google.com>
Mon, 4 May 2020 16:04:25 +0000 (17:04 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 4 May 2020 16:04:25 +0000 (17:04 +0100)
* objcopy.c (copy_object): Allow empty section.
* testsuite/binutils-all/update-section.exp: Add test.

binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/binutils-all/update-section.exp

index 7cc692b3e5b9dddc91415f89bf248b24df4124ab..8da40977e1e6a589558a9a346c8fe1ba6e39ff0e 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-04  Fangrui Song   <maskray@google.com>
+
+       * objcopy.c (copy_object): Allow empty section.
+       * testsuite/binutils-all/update-section.exp: Add test.
+
 2020-05-04  Nick Clifton  <nickc@redhat.com>
 
        PR 25917
index 738ef4c2c9135742d6c0518a3bac631574e8fa58..5760d06a85959ce53ea7e52b46504cd721bfc1f5 100644 (file)
@@ -2983,6 +2983,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
       for (pdump = dump_sections; pdump != NULL; pdump = pdump->next)
        {
+         FILE * f;
+         bfd_byte *contents;
+
          osec = bfd_get_section_by_name (ibfd, pdump->name);
          if (osec == NULL)
            {
@@ -3000,14 +3003,8 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
            }
 
          bfd_size_type size = bfd_section_size (osec);
-         if (size == 0)
-           {
-             bfd_nonfatal_message (NULL, ibfd, osec,
-                                   _("can't dump section - it is empty"));
-             continue;
-           }
+         /* Note - we allow the dumping of zero-sized sections.  */
 
-         FILE * f;
          f = fopen (pdump->filename, FOPEN_WB);
          if (f == NULL)
            {
@@ -3016,7 +3013,6 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
              continue;
            }
 
-         bfd_byte *contents;
          if (bfd_malloc_and_get_section (ibfd, osec, &contents))
            {
              if (fwrite (contents, 1, size, f) != size)
index 4fd6a77214a209d00b4630935e369ae4b72d1199..81a01b0a58bf2248ccaf85cff6f11526a74c8f49 100644 (file)
@@ -82,6 +82,13 @@ foreach f [list update-1.s update-2.s update-3.s update-4.s] {
     }
 }
 
+# Check that we can dump empty sections.
+if { ![do_objcopy update-1.o "--dump-section .text=tmpdir/empty"] } {
+    fail "objcopy (dump empty section)"
+} else {
+    pass "objcopy (dump empty section)"
+}
+
 if { ![do_objcopy update-1.o \
            "--dump-section .foo=tmpdir/dumped-contents"]
      || ![do_objcopy update-2.o \
This page took 0.02882 seconds and 4 git commands to generate.