objcopy: Allow --dump-section to dump an empty SEC_HAS_CONTENTS section

Message ID 20200502032930.229126-1-maskray@google.com
State New
Headers show
Series
  • objcopy: Allow --dump-section to dump an empty SEC_HAS_CONTENTS section
Related show

Commit Message

binutils
	* objcopy.c (copy_object): Allow empty section.
	* testsuite/binutils-all/update-section.exp: Add test.
---
 binutils/objcopy.c                                 | 6 ------
 binutils/testsuite/binutils-all/update-section.exp | 4 ++++
 2 files changed, 4 insertions(+), 6 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog

Comments

Hi Fangrui,

> 	binutils

> 	* objcopy.c (copy_object): Allow empty section.

> 	* testsuite/binutils-all/update-section.exp: Add test.


Approved - please apply.

I must say that if feels wrong doing this, but I can see why it might be of some use...

Cheers
  Nick
On 2020-05-04, Nick Clifton wrote:
>Hi Fangrui,

>

>> 	binutils

>> 	* objcopy.c (copy_object): Allow empty section.

>> 	* testsuite/binutils-all/update-section.exp: Add test.

>

>Approved - please apply.

>

>I must say that if feels wrong doing this, but I can see why it might be of some use...

>

>Cheers

>  Nick

>

Hi Nick, can you apply it for me? I don't have a write permission.
Hi Fangrui,

> Hi Nick, can you apply it for me? I don't have a write permission.


Done.

Cheers
  Nick

Patch

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 738ef4c2c9..d7c57be2ea 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3000,12 +3000,6 @@  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;
-	    }
 
 	  FILE * f;
 	  f = fopen (pdump->filename, FOPEN_WB);
diff --git a/binutils/testsuite/binutils-all/update-section.exp b/binutils/testsuite/binutils-all/update-section.exp
index 4fd6a77214..995c20e12f 100644
--- a/binutils/testsuite/binutils-all/update-section.exp
+++ b/binutils/testsuite/binutils-all/update-section.exp
@@ -82,6 +82,10 @@  foreach f [list update-1.s update-2.s update-3.s update-4.s] {
     }
 }
 
+if { ![do_objcopy update-1.o "--dump-section .text=tmpdir/empty"] } {
+    return
+}
+
 if { ![do_objcopy update-1.o \
            "--dump-section .foo=tmpdir/dumped-contents"]
      || ![do_objcopy update-2.o \