On Wed, 2013-01-02 at 18:47 +0000, Mark Cave-Ayland wrote:
Possibly, yes. I've been reading around how relocation works with ELF, and I've found something we could potentially use here:
http://www.math.utah.edu/docs/info/ld_3.html#SEC18
See the part about the AT keyword and the corresponding C code. Could this be used to relocate the image to a fixed location in RAM without having to create a full-blown ELF relocator?
Otherwise I guess we have to have multiple .text sections; one containing an ELF relocator and another containing the payload itself. I'm not sure whether that would affect non-QEMU use of OpenBIOS though.
On ppc64 at least, with a bit of care on the use of global symbols in asm, it's fairly easy to generate an position independent executable that relocates itself.
I've written such a relocator myself, it's about 20 lines of C (unfortunately it's some internal stuff I cannot post publicly as-is), or you can look at the asm variant in Linux written by paulus. The idea is that you can get the compiler to generate really only one type of relocs (R_PPC64_RELATIVE) which are easy to process.
I assume ppc32 should be similarly easy. I don't know about sparc however.
If you can do the relocation from qemu it's even easier.
Cheers, Ben.