Today I came across the following situation. I run several times the following program:
#include <stdio.h>
int main(int argc, char **argv) {
printf("%p\n", &argc);
}
On an Intel i7 with linux and gcc compiler, this program gives different output at each run:
i7:~/tmp$ gcc t.c
i7:~/tmp$ ./a.out
0x7fffc127636c
i7:~/tmp$ ./a.out
0x7fffdefed97c
i7:~/tmp$ ./a.out
0x7fff7f32454c
I would expect that developers of linux, elf, gcc or whatever is related would try to ensure that the stack is positioned on the same address at each invocation of a program. It would facilitate tracing and fixing of strange bugs which may happen when dealing with pointers and addresses of variables (similarly as virtual addresses are better for fixing bugs compared to physical addresses).
I wonder why the stack is mapped to different addresses at each invocation of the program?