I'm having simple code as follows:
#include<stdio.h>
int glob;
int main(void)
{
int a;
printf("&a is : %p \n", &a);
printf("glob is : %p \n", &glob);
return 0;
}
Output of above program is: First run:
&a is : 0x7fff70de91ec
glob is : 0x6008f4
Second run :
&a is : 0x7fff38c4c7ac
glob is : 0x6008f4
I'm studying about virtual & physical addresses. I have following question:
In executed this program on Linux : 2.6.18-308.el5 x86_64 GNU/Linux
Compiled using : gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
Addresses seen in a program are always virtual and the behaviour described by the OP is a Linux counter-measure to avoid buffer overflow attacks.
Just to try, you can disable it with
sysctl -w kernel.randomize_va_space=0
then run again your program and watch.
The global one is in another space of memory that can't be harmful in an hackish-wise point of view. That's because it is not randomized every time.