views:

70

answers:

0

The gnu linker "ld" supplies the option "-sort-common" which sorts the uninitialized global parameters, known as the COMMON section symbols, by their size. When the linker aligns the symbols to even addresses, this option helps minimizing the holes in the section. For example, if we define:

--main.c

char a;

short b;

char c;

int main() { return 0; }

and compile it to main.o without "sort-common" we will get a "hole" of one byte between the address of "a" and the address of "b". If we use "sort-common" the linker will reorder the parameters to "a, c, b", and since a's size is 1 byte and c's size is 1 byte, there will be no "hole" between their adresses. My problem is that my code looks like:

--main.c

char a = 0;

short b = 0;

char c = 0;

...

In this case a, b, and c are in the BSS section, which means that "sort-common" will not affect them.

How do I sort the symbols of other sections besides the "COMMON" section?

I also searched many options in the LD scripts, unsuccessfully.

Thanks,

Oren