Documentation reference request - Relocating self contained ELF image (boot loader)

Graeme Russ graeme.russ@gmail.com
Mon Oct 13 04:06:00 GMT 2008


Hi All,

Firstly, sorry if this is not the right place to be asking the
following questions - I have been scouring the net but I can't find
any concise answers and since my problem (for want of a better word)
begins with the output of ld, I figured this may be an appropriate
place to continue my search.

I am trying to implement Position Independent Executable support for
a boot loader (U-Boot). The reason I want to do this is two-fold:

a) I want to relocate the code and data out of the Boot Flash so I
   can perform updates to the boot loader in-place
b) I want to relocate the boot loader to the highest possible memory
   location when the actual memory size is not known beforehand

The target is an x86 (IA_32) based board (AMD ELAN SC520 CPU)

The build environment is Ubuntu 8.04, gcc 4.2.3 & binutils 2.18.1

I'm compiling with gcc's -fpie flag, linking with ld's -pie flag
and generating an ELF binary which is then stripped to create a
boot image which is written to the Flash.

After compiling twice with a different text base, and performing a
binary compare and cross referencing the map file, I have found the
following sections differ:

.dynsym
.dynamic
.data.rel
.data.rel.local
.data.rel.ro.local
.got.plt
.got
.rel.got
.rel.text
.rel.u_boot_cmd
.rel.data.rel
.rel.data.rel.ro.local
.rel.data.rel.local

and the differences appear to be quite logical (differ by the same
amount as the difference in text base between builds).

So, what I was thinking was a trimmed down ELF loader which would copy
the Flash image to an arbitrary memory location and update the above
sections accordingly. I understand this is what security hardened
systems do when implementing Address Space Layout Randomisation for
Position Independent Executable and that this is done by either the
kernel or ld.so (or both?)

This is where I have come to screaming halt - I am finding it really
difficult finding documentation on the content of these sections,
how they are built, how they inter-relate etc.

Can anyone point me towards documentation which describes the
contents of these sections and how they need to be processed in order
to complete the relocation?

Many thanks in advance

Graeme



More information about the Binutils mailing list