Commit: objcopy: Add --dump-section option

Anthony Green green@moxielogic.com
Sun Mar 9 04:15:00 GMT 2014


Nick Clifton <nickc@redhat.com> writes:

> Hi Guys,
>
>   I am applying the attached patch to add a new command line option to
>   objcopy: --dump-section.  This option is the inverse of --add-section
>   in that it dumps the contents of a specified section to a specified
>   file.  The dump is just a raw copy of the contents of the section.  It
>   is not formatted in any way.  This is useful if the section cannot be
>   copied via the --only-section option, or if it needs to be passed to a
>   --add-section option later on.

Hi Nick,

  This patch adds a check of the return code of fwrite.  It was required
to build with full warnings enabled.    Ok to commit?

AG


2014-03-08  Anthony Green  <green@moxielogic.com>

	* objcopy.c (copy_object): Check fwrite return code.


diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index cb2be49..6215919 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1875,7 +1875,12 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
 	  bfd_byte * contents = xmalloc (size);
 	  if (bfd_get_section_contents (ibfd, sec, contents, 0, size))
-	    fwrite (contents, 1, size, f);
+	    {
+	      if (fwrite (contents, 1, size, f) != size)
+		fatal (_("error writing section contents to %s (error: %s)"),
+		       pdump->filename,
+		       strerror (errno));
+	    }
 	  else
 	    bfd_nonfatal_message (NULL, ibfd, sec,
 				  _("could not retrieve section contents"));



More information about the Binutils mailing list