1
votes

I am using the GNU linker script in which the bss sections variables are getting non 4 byte aligned address and this is big problem as the variable address is being used by hardware,which needs word aligned address.

Instead of using align attribute of single one of them, lets if I have 10 variables or I would like to have linker generate word aligned address for each variables in a particular section how can I do it ?

I have tried using ALIGN() with no effect.

This is the example:

 .bss.a 9cdf8        0x1

 .bss.b 9cdf9        0x1

For .bss.b I would like to to get 0x9cdf8 + 4 and so for all the variables.

How can I achieve this ?

1
There are two type of alignment. One if for an input section and the other is for an output section. You have to set the alignment in the source files. See SORT_BY_ALIGNMENT, SORT_BY_NAME, alternatively you can specify each file. .bss { foo.o(.bss); . = ALIGN(4); bar.o(.bss); }. The ALIGN just aligns the current output address. - artless noise

1 Answers

0
votes

You're probably best off marking the variables that need 4-byte alignment where they are defined. For example, in gcc:

char a __attribute__((aligned(4)));
char b __attribute__((aligned(4)));

See http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Variable-Attributes.html