0
#include <stdio.h>
int main() {
    printf("text at %p\n", main);
    int c = getchar();
}

Compiling the above code on VirtualBox Ubuntu 64 bit and running it, I get:
text at 0x55555555468a
pmap:
0000555555554000 4K r-x-- a.out

However,

objdump -dj .text a.out | sed -n '/:/,/^$/p':
000000000000068a :
68a: 55 push %rbp

gdb a.out
Dump of assembler code for function main:
0x000000000000068a <+0>: push %rbp

Entirely different addresses for linked code ?

pie
  • 1
  • 3
  • What is the output of `file a.out` ? There are different relocation rules for different types of executable files. – Mark Plotnick Feb 13 '20 at 14:56
  • > Entirely different addresses for linked code ? You are looking at [position-independent executable](https://en.wikipedia.org/wiki/Position-independent_code#Position-independent_executables), which is relocated to a random address at runtime. – Employed Russian Feb 13 '20 at 16:43

0 Answers0