When and How is %rip-relative addressing resolved?

903 Views Asked by At

Take the following assembly program:

_start:
    mov myvar,       %rax
    mov myvar(%rip), %rax
    mov myvar(%rip), %rax
    mov myvar(%rip), %rax
    mov myvar(%rip), %rax

The produces the following when run in gdb:

!0x00000000004000b0  ? mov    0x600107,%rax
 0x00000000004000b8  ? mov    0x200048(%rip),%rax        # 0x600107
 0x00000000004000bf  ? mov    0x200041(%rip),%rax        # 0x600107
 0x00000000004000c6  ? mov    0x20003a(%rip),%rax        # 0x600107
 0x00000000004000cd  ? mov    0x200033(%rip),%rax        # 0x600107

Of course, it's not surprising that all the myvar references resolves to 0x600107. Where (or perhaps when is a better question) do the %rip-relative items get resolved to an actual address? How does that process work at a high level?

Related: Why does this MOVSS instruction use RIP-relative addressing?.

0

There are 0 best solutions below