3 ms·
I'm confused why would IP-relative addressing be useful. Have you got some interesting examples?
by viraptor 11y ago
I'm confused why would IP-relative addressing be useful. Have you got some interesting examples?
- cnvogel 11y agoFor any shared object loaded on an unknown address it makes it trivially easy to load data also in that library.
- gsg 11y agoIt'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 11y agoThanks, I've seen it so many times it seems I developed (%rip) blindness :) Of course it's useful this way.