This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

runtime linking .o/.so files [Re: Free linker hash table from bfd_close]


On Sat, 21 Jun 2014 02:07:00 +0200, Alan Modra wrote:
> On Thu, Jun 19, 2014 at 07:53:33AM -0600, Tom Tromey wrote:
> > Alan> However, I think you're going to be sorely disappointed in the
> > Alan> linker's ability to relocate final linked binaries.
> > 
> > I think we're only relocating .o files.

This is because for .so file bfd will not process its relocation table (as
.rel* do not point to .symtab/.dynsym).  This means for .so GDB would have to
re-implement some part of ld.so to get its arch-dependent relocationing part.


> And then running the code?  Ick.  Won't work for PIC that uses the
> GOT.

It is using -mcmodel=large for 64-bit targets, that way no GOT is needed.
I am not aware if any target can have incompatible ABI due to using -mcmodel.

To avoid -mcmodel one could build the code as non-PIC but then one would need
to reserve very large space in the inferior in advance to get the final address.
But in such case I had some difficulties specifying the fixed address using
default system linker scripts.  Customizing linker scripts I tried seemed to
me as even more incompatible across target platforms than just using -mcmodel.

I was also generating GOT by hand (and not using the 64-bit -mcmodel) but it
had some other disadvantage I cannot remember now, I could try it again.


I was considering patching bfd so that it could parse relocation tables even
for .so and implementing some simple ld.so-like relocator.  But in the end
I find -mcmodel=large much easier/safer and so far compatible enough.


Thanks for possible advice,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]