This is the mail archive of the
mailing list for the binutils project.
RE: Deleting sections with libbfd
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Brendon Costa'" <brendon at christian dot net>, <binutils at sourceware dot org>
- Cc: "'Brendon Costa'" <bcosta at avdat dot com dot au>
- Date: Mon, 9 Oct 2006 00:02:53 +0100
- Subject: RE: Deleting sections with libbfd
On 08 October 2006 23:36, Brendon Costa wrote:
> Hi all,
> I have been working on an extension for GCC that allows me to perform
> static analysis of C++ exceptions. This extension generates data while
> objects are being compiled and embeds that data into the .o files in a
> section named ".edoc".
> In post processing the resulting exes I wish to ensure that the number
> of .edoc sections contained in an exe is exactly 1. This seems to always
> be the case on my machine however I read in the libbfd manual that it is
> possible for an exe to contain more than 1 section with the same name.
> My plan was to search the output exe for any sections named ".edoc" and
> delete them, and then create a new single section ".edoc" and set its
> contents as i require.
> I could not find any mention of "Deleting Sections" in the libbfd manual
> or in the archives. Is this at all possible?
You delete a section by not copying it from an input bfd to output bfd.
> If not would it suffice for me to set the size of all ".edoc" sections
> in the binary except the one i wish to use to 0?
> Also is it possible to open a bfd for reading and writing? I need to
> write, but if i use bfd_openw then it does not read in the existing
> contents of the binary file. I really need to modify the bfd so read it
> in, modify the appropriate sections and save the changed file.
You have to open an input bfd and an output bfd and read from one, modify in
memory, and write to the other; bfd doesn't support modify in-place.
Take a look at objcopy.c; ISTM that you should be able to adapt it to your
purposes. (You may even be able to use it as-is with a bit of scripting or
Can't think of a witty .sigline today....