This is the mail archive of the binutils@sources.redhat.com 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]

Re: ld and relocatable vs. absolute


(I lost my mail archive recently due a hard disk crash, and didn't see the
original article)

On Tue, Sep 08, 1970 at 04:39:39PM -0500, Michael Sokolov wrote:
> Chuck Meade <chuckmeade@yahoo.com> wrote:
> 
> > Several linkers (including Diab and Green Hills) support the
> > creation of a fully-linked executable image that at the same
> > time retains relocation information, allowing it to be 
> > relocated to a dynamically determined memory address at load
> > time by an on-target loader.
> >
> > Such an image would not have unresolved references, it would
> > just be relocatable.
> 
> I hear you very well, I have exactly the same issue on some m68k embedded
> systems I work with. Basically, you'll most probably need to implement a
> special feature in Binutils to do what you need for your processor / BFD
> target.

If you are going to keep relocations as relocations for a dynamic loader (as
opposed to an embedded target that needs the relocations in memory), you really
need to have a target that uses RELA relocations instead of REL (RELA
relocations keep the addend in the relocation record and ignore the contents in
the file, while REL relocations put the addend in the target location in the
object file, which means you can't rerun the relocations).  The MIPS ELF shared
library had the notation of preloading the address when doing a link, so that
if the dynmaic loader discovers that the shared library is at the same location
as when the linker ran, it doesn't have to do any relocations, and consequently
not do the initial page faults.  While I personally thought it was a neat
scheme to speed up the initial run of a process, I seem to recall that in real
life it was rather fragile.
> > I would like to be able to accomplish the same with ld for
> > PowerPC.  Has anyone out there done this?  Any tips?
> 
> As I don't know the PowerPC architecture or the state of its implementation in
> Binutils, I can't tell you for sure whether what you want can be done with
> already existing features or whether a new one would have to be added. Perhaps
> other maintainers who know more about PowerPC can fill you in. If you do need
> to implement a new feature, be sure to take a look at the three places I've
> told you about (MIPS/ECOFF, m68k COFF/ELF, and ELF shared objects) for a
> starting point on how to do this.

For the PowerPC, all you have to do is compile everything with the
-mrelocatable option, which will produce the tables so that if you plop the
code anywhere in memory, keeping the distance between the .text and the .data
sections the same, the initializer function __eabi, which is called by main,
will update all of the pointers involved to their new location.

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

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