开发者

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

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, 开发者_C百科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.

Update: I read something about "Order" value in the segment_flags, and didn't understand how to use it. Any help is appreciable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜