I'm using gas and trying to align a .lcomm buffer on 16 bytes.
Code :
.align 16
.lcomm Buffer, size
But when checking the address of Buffer using leal instruction. it seems that it is NOT aligned. I think that the .align directive doesn't work correctly.
Do you have any idea please ?
Of course it works correctly, but you use it wrong. The manual says:
Some targets permit a third argument to be used with .lcomm. This argument specifies the desired alignment of the symbol in the bss section.
So the correct code is .lcomm Buffer, size, 16
.
Note that .align
does not affect .lcomm
especially if you are not in the .bss
section. If you want to allocate stuff by hand, switch to .bss
, then use the .align
and then allocate using .space
not .lcomm
.
Also, the manual gives a workaround suggestion as:
For targets where the .lcomm directive (see Lcomm) does not accept an alignment argument, which is the case for most ELF targets, the .local directive can be used in combination with .comm (see Comm) to define aligned local common data.
Indeed, for x86 ELF the alignment argument is not supported, so implementing this workaround would look like:
.local Buffer
.comm Buffer, size, 16
(Thanks to @wumpus-q-wumbley for pointing this out.)