This is the mail archive of the
mailing list for the binutils project.
Re: Newbie questions
- From: Nicholas Clifton <nickc at redhat dot com>
- To: Bernhard Damberger <bernied at gmail dot com>, binutils at sourceware dot org
- Date: Mon, 08 Sep 2014 10:07:25 +0100
- Subject: Re: Newbie questions
- Authentication-results: sourceware.org; auth=none
- References: <CAB3wU3oVcDLtQrJvJFZsidM0Cvrjd+HWqPHS=jhdQnNZceShhA at mail dot gmail dot com>
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.