linker allocation order VS declaration order

Hua Yanghao huayanghao@gmail.com
Tue Jul 31 09:09:00 GMT 2012


Hi,
While porting an old arm RVDS based code to arm-GCC,
I found a behavior difference regarding variable allocation order
with regard to its declaration order in C file.

I know this is bad design and should not be relied on,
but that's the burden must be carried for the porting.

For example, if in a C file, two variable declared:
int a;
int b;

After compilation, a and b is in bss section (common section).
The linker script could be:
.bss 0x8000 : { *(COMMON) }

Here the RVDS always place a @ 0x8000 and b @ 0x8004,
however for GNU/Binutils the placement is completely random.
Sometimes if I initialized a and b to 0, which in theory should have
no difference but in reality do change the address for a and b.

So here my question is,in GNU/ld is there any way to make the
variable allocation order (or assignment order) exactly the same
as the declaration order?

Thanks,
Yanghao



More information about the Binutils mailing list