A PIE binary, when loaded in IDA shows an offset (
0x202010) different from gdb (
0x2013a1) for instruction located at
0x555555554c68 in (gdb) and
0xc68 (in IDA). How can I explain this discrepancy?
For "Position Independent Executable" binaries, the loader is free to relocate the binary using some base address. In the case of GDB, the binary is mapped already into memory, the offset
0x2013a1 in the memory operand is calculated relatively with the current
RIP (which is the address of the next instruction). The current instruction size is
0x6f - 0x68 = 0x7 bytes, so in considering with the address of the current instruction, we have an offset:
0x2013a1 + 0x7 = 0x2013a8
In the case of
IDA, you see the "static" virtual address, the offset
0x202010 in the memory operand is calculated relatively with the base address of the code segment, so in considering with the address of the current instruction, we have an offset:
0x202010 - 0xc68 = 0x2013a8
These values are coherent for both cases.