Commit: objcopy: Add --dump-section option

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Commit: objcopy: Add --dump-section option

Nick Clifton
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.

Cheers
  Nick

binutils/ChangeLog
2013-12-31  Nick Clifton  <[hidden email]>

        * objcopy.c (dump_sections): New list.
        (command_line_switch): Add OPTION_DUMP_SECTION.
        (copy_options): Add dump-section.
        (copy_usage): Document new option.
        (copy_object): Dump requested sections.
        (copy_main): Handle --dump-section.
        * doc/binutils.texi: Document --dump-section option.
        * NEWS: Mention new feature.


objcopy.patch.xz (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Commit: objcopy: Add --dump-section option

Anthony Green
Nick Clifton <[hidden email]> 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  <[hidden email]>

        * 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"));
Reply | Threaded
Open this post in threaded view
|

Re: Commit: objcopy: Add --dump-section option

Nick Clifton
Hi Anthony,

> 2014-03-08  Anthony Green  <[hidden email]>
>
> * objcopy.c (copy_object): Check fwrite return code.

Approved - please apply - thanks for the catch.

Cheers
   Nick

Reply | Threaded
Open this post in threaded view
|

Re: Commit: objcopy: Add --dump-section option

Anthony Green
Nicholas Clifton <[hidden email]> writes:

> Hi Anthony,
>
>> 2014-03-08  Anthony Green  <[hidden email]>
>>
>> * objcopy.c (copy_object): Check fwrite return code.
>
> Approved - please apply - thanks for the catch.

Thanks Nick.  Applied!

AG


>
> Cheers
>   Nick