ASLR and addresses

Take a look at this:

int 
main() 
{
  int asd = 10;
  printf("%p\n", &asd);
  return 0;
}

Current asd address:

0x7ffff5f7c16c

Main address (always the same):

(gdb) disass main
Dump of assembler code for function main:
    0x00000000004005b4 <+0>:    push   %rbp

Why are the addresses of the variables of a regular program c changed at each execution, while the starting address of the program itself is always the same (assuming that it is not position independent)? I see that the variability of the addresses is due to the ASLR mode, but why does this only affect program variables and does not affect where the code is allocated? Is this due to the fact that, being a section of the ro code, it makes no sense to randomize it if it is not strictly necessary?

Also, why is there a huge gap between the drag address of the main and the address of the asd variable?

+3
source share
1 answer

ASLR mmap (2) . execve (2) ( ), "" . main ( - . environment (7)).

execve. crt0.o ( main) , , . x86-64 ABI.

main ELF. (.. -fPIE -fPIC ..), ( relocation). objdump -f badnack badnack, . pmap . PIC ( ).

+4

All Articles