This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: using BFD to load and reloc a simple file
On Thu, Mar 02, 2006 at 04:18:00PM -0500, Daniel Jacobowitz wrote:
> On Thu, Mar 02, 2006 at 01:15:18PM -0800, thockin@hockin.org wrote:
> > I am trying to load and relocate a simple ELF executable. It's entirely
> > self contained, but needs to be loadable at an arbitrary 32 bit address.
> >
> > I'm trying to use libbfd for this, but I am having trouble. The load goes
> > fine, and it copies the ELF data into memory where I tell it to. Very
> > nice and very easy. When I call perform_relocation(), though, it goes
> > haywire.
>
> That's because this is a routine for the linker, not a routine for
> in-place relocation.
Is there an in-place variant?
> > bfd_perform_relocation() eventually does:
> > reloc_target_output_section = symbol->section->output_section;
> >
> > The problem is that output_section is always NULL. I don't want to output
> > a BFD, I want to relocate it in memory.
>
> You might be able to set the section to point at itself. However, I'm
> not sure if bfd_perform_relocation even does the operation you want it
> to.
I tried that and it stopped finding any relocations at all! I did not
debug further.
I'm not sure that I am doing what I want to do most effectively. The end
goal is a small self-contained executable with a few sections that will be
located into memory at some system-specific addresses (which can not be
known at build time).
I've succeeded in making a static binary that works for a given fixed
address. Now I need to make it relocateable. Linking with -r seems to
give me the binary I want (though I am not sure it would catch
unresolvable references anymore).
Would I be better off using -pie or some other method?
> --
> Daniel Jacobowitz
> CodeSourcery
--
Tim Hockin
thockin@hockin.org
Soon anyone who's not on the World Wide Web will qualify for a government
subsidy for the home-pageless.