2

I am maintaining the JIT compiler for the virtual machine in ioquake3.

Recently someone tried to build a PIE binary from ioquake3, however compiled code makes extensive use of the EBX register which in PIC code and thus PIE binaries seems to be a fixed register containing the GOT address.

The virtual machine may call into GCC-compiled code at a fixed point so there I will need to restore EBX to the GOT address. For that the JIT-compiler code needs to know the GOT address so that it can emit code that restores EBX to that address. I imagine you could directly use inline assembly like so:

void *gotptr;

__asm__ volatile("\n": "=b" (gotptr));

Compiled code is directly called from the JIT-compiler code so EBX should be the same at JIT compile and at the call into the VM. My question is: would this work, and is there a different way to retrieve the GOT address from C code, for instance, is there a symbol defined that specifies that address, or is there a function that returns it?

4

1 回答 1

4

System V i386 ABI中,它负责调用函数以在必要时设置 EBX,因此在调用 PIC/PIE 编译函数时不需要恢复它。正如 ABI 所述:

与位置无关的代码使用%ebx寄存器来保存全局偏移表的地址。如果一个函数直接或间接需要全局偏移表的地址,它负责计算该值。

于 2016-06-15T15:51:54.697 回答