Have a look at this main:
int
main()
{
int asd = 10;
printf("%p\n", &asd);
return 0;
}
Address of asd at at a given moment:
0x7ffff5f7c16c
Address of main (always the same):
(gdb) disass main
Dump of assembler code for function main:
0x00000000004005b4 <+0>: push %rbp
Why the addresses of the variables, of a regular c program, change at every execution, whereas the starting address of the program itself it is always the same (assuming that it is not position independent)? I see that the address variability is due to the ASLR mode, but why it does affect only the program variables, and does not affect where the code is allocated? Is this related to the fact that as being the code section ro it doesn't make sense randomizing it when not strictly necessary?
Furthermore, why is there an enormous gap between the tarting address of the main and the address of the variable asd?