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?
source
share