Bugzilla – Bug 283
Need support for position independent code & relocations
Last modified: 2004-11-22 16:07:11
You need to log in before you can comment on or make changes to this bug.
Our current mechanism for outputing machine code is basically the bare minimum required to get the JIT working. Long term, we want to be able to write the code generated by the JIT out and read it back in as well. To do this, we will need to generate relocatable machine code along with a list of relocations. Currently the code emission process looks something like this: X86CodeGen: emit an instruction 'mov EAX, [global]' X86CodeGen: "hey jit, what's the address of global" JIT : Hey code generator, it's at 0x12345678 X86CodeGen: Ok, emit 0xAB 0xCD 0x12345678 So currently the code generators produce a stream of binary machine code, but has to call into the JIT to get the addresses of various globals, constant pool entries, etc. Instead the code generator should be independent of the JIT and produce both machine code and *relocations*, so that it does not need to call into the JIT at all. Consumers of this information could choose to write out a native ELF .o file, or could choose to splat it to memory and then execute it (like the JIT). Once the LLVM code generators can write out PIC code, making the JIT cache translations would be really quite easy :) -Chris
This is now fixed. The target code emitters now produce a block of machine code and a bunch of MachineRelocation objects. The JIT now uses these to relocate the machine code to where ever the code ends up. Both the X86 and V9 JITs have been updated to use the new interfaces, and I sped up the V9 JIT and fixed bugs in it in the process (Olden works with the V9 JIT again now, woo!). This makes the code much cleaner, gets a bunch of JIT-specific cruft out of the MachineCodeEmitter class, and factors common code out of targets into the JIT. For all of these reasons and more it also makes the PPC JIT easier to do. -Chris