I'm writing a small program loader for my language because I gave up on understanding ELF format (and while doing this, I may eventually understand it better). I mmap the files on the memory and tux rejoices whatever..
I don't want to hinder the sharing of the program by doing any changes on it. Therefore I end up doing the same as C and elf does: global offset table.
The problem is: how can I pass the GOT for my program?
First thing that comes to mind is giving it along in a register or stack argument. In a register it'd be great, but x86 is retarded by it's register count. This could mean I will lose ebx or ebp or some such. In a sensible architecture this'd be a fair tradeoff. In x86 it feels a bit of fail.
Disassembly of a shared library shows me that gcc is doing it as an IP-relative addressing. If I'd do this, it'd be:
call 0
here:
pop eax
; do something with [eax + (got - here) + index*4]
Though, partially this feels complicated. I don't like about doing this.
Any more ideas, anyone?
Edit: When getting to handle this with multiple libraries, I realised this: I will have multiple GOTs per app and the use of certain GOT depends on which chunk of code I am in. Therefore keeping GOT in a separate register is going to require some additional tricks I'm not aware of. I'd like to know how they solve this problem when keeping GOT in registers.