This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Using bfd to change the .text section of an executable
- From: Alan Modra <amodra at gmail dot com>
- To: Eric Schulte <schulte dot eric at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 28 Mar 2011 14:48:58 +1030
- Subject: Re: Using bfd to change the .text section of an executable
- References: <87sjuda8bm.fsf@gmail.com>
On Wed, Mar 23, 2011 at 02:29:40PM -0600, Eric Schulte wrote:
> However, any changes which change the size of the .text section (in this
> case appending four noops to the end) the resulting file is no longer a
> working executable but rather throws segfaults on execution.
Not surprising. I suspect you seriously underestimate how much work
is required to change section VMAs in a final linked executable, and
have it run afterwards.
> After some investigation it appears that while bfd is updating the lma
> address of all sections following the .text section in memory (as shown
> in the bfd warnings printed in [1] when running my `copy' program, the
> source code for which is included below in [2]) bfd is not making
> similar adjustments to the vma field of these sections.
>
> Is it possible to convince bfd to manage vma addresses for me?
Nope.
> I've
> tried setting the `user_set_vma' flag to 0 before making the copy, but
> to no avail. Also, attempts to set the vma field of these sections
> manually before calling bfd_close don't have any effect on the resulting
> output file.
See objcopy --change-section-vma code.
--
Alan Modra
Australia Development Lab, IBM