This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: bfd: read/write header characteristics of Win32/PE executable
- From: Dave Korn <dave dot korn dot cygwin at gmail dot com>
- To: Sean McNamara <smcnam at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 23 Jul 2010 16:46:06 +0100
- Subject: Re: bfd: read/write header characteristics of Win32/PE executable
- References: <AANLkTinzk26Qhbj2z8zORzgg-q0gqNN-0gEaJuXQqqBB@mail.gmail.com>
On 21/07/2010 09:03, Sean McNamara wrote:
> I have been using the bfd source code and documentation to try to
> understand how to do this, but most of the COFF/PE stuff is documented
> in the source, not in the binutils docs. The only user of BFD that
> appears to do what I want is in GNU ld, in the file pe.em:
>
> case OPTION_LARGE_ADDRESS_AWARE:
> real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
>
> This seems to be the place where GNU ld parses the option
> "--large-address-aware" and translates that into a flag set by BFD. I
> started researching BFD from this, and inferred that eventually I need
> to do something like this in my app:
>
> abfd->tdata.pe_obj_data->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
>
> I managed to drag in the required headers from include/ and bfd/ to
> get this to build, but when I call bfd_close(), no changes are made to
> the resulting executable.
>
> Currently I am opening the executable with bfd_fopen in "rw" mode,
> hoping that I could just make this one change and write it back out,
> without having to open the file for reading, create a new BFD for
> writing, and somehow (?) copy the contents of the one into the other.
Hmm, I dunno if bfd actually allows that or not. I think the best solution
to this would be to duplicate the various flag-setting options from ld into
objcopy.
cheers,
DaveK