title: How can I best pass a Global Offset Table (GOT) for my language on x86?
body: <p>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..</p>
  
  <p>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.</p>
  
  <p>The problem is: how can I pass the GOT for my program?</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>    call 0
  here:
      pop eax
      ; do something with [eax + (got - here) + index*4]
  </code></pre>
  
  <p>Though, partially this feels complicated. I don't like about doing this.</p>
  
  <p>Any more ideas, anyone?</p>
  
  <p><strong>Edit:</strong> 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.</p>