This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
linker allocation order VS declaration order
- From: Hua Yanghao <huayanghao at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 31 Jul 2012 17:09:20 +0800
- Subject: linker allocation order VS declaration order
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