Deleting sections with libbfd

Dave Korn dave.korn@artimi.com
Sun Oct 8 23:02:00 GMT 2006


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
makefile trickery).

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Binutils mailing list