Newbie questions

Nicholas Clifton nickc@redhat.com
Mon Sep 8 09:07:00 GMT 2014


Hi Bernhard,

> I figured out if I call bfd_check_format() it will force the sections
> to be loaded into memory, but now the file is marked as
> output_has_begun so I can't modify it.
>
> Is there a standard way to force the sections to be loaded so you can
> iterate over them (and modify)?

Yes - use bfd_open and bfd_check_format as you have been doing, but open 
the input file for reading only and then create a new output file.  Ie 
do not try to modify the input file, but instead copy it to a different 
output file, making changes on the way.  Have a look at the code in 
binutils/objcopy.c for examples of this.


> Calling bfd_set_section_contents fails because the sizes don't match.

This should be resolved by the change suggested above.

> 3. Would a tool that converts bfd (internal structures) to json and
> back be useful?

Not sure.  (Not being a json user myself).  But it would certainly be 
interesting, and educational to create one.

Cheers
   Nick




More information about the Binutils mailing list