3 ms·
It's the basis of efficient relocations in position independent code, which is now very common. PIC can be emitted on older x86 machines without RIP-relative a
by gsg 10y ago
It's the basis of efficient relocations in position independent code, which is now very common.
PIC can be emitted on older x86 machines without RIP-relative addressing, but the code is larger and slower. As an example, consider -m32 gcc output for the C program
int x;
int getx() {
return x;
}
With no PIC:
getx:
movl x, %eax
ret
With PIC:
getx:
call __x86.get_pc_thunk.cx
addl $_GLOBAL_OFFSET_TABLE_, %ecx
movl x@GOT(%ecx), %eax
movl (%eax), %eax
ret
And with -m64, which emits PIC and uses x86-64s RIP-relative addressing:
getx:
movl x(%rip), %eax
ret
Hopefully that makes the motivation clear.
- viraptor 10y agoThanks, I've seen it so many times it seems I developed (%rip) blindness :) Of course it's useful this way.