How to specify ELF section alignment in GNU as?
<p>I'm trying to use GNU <code>as</code> as a generic assembler similar in use as <code>nasm</code>. I make a template source like this:</p>

<pre><code>.section .text
.globl _start
.intel_syntax noprefix
_start:
call 0xb77431c0 # the instruction I want to assemble
</code></pre>

<p>And then I run the assemble command like this:</p>

<pre><code>as --32 -o test.o test.s
ld -m elf_i386 -Ttext 0xb77431d9 --oformat binary -o test.bin test.o
</code></pre>

<p>All works well with binutils 2.24. But it appears that <code>as</code> from binutils 2.22 (the one in Ubuntu Precise) aligns <code>.text</code> section to the 4-byte boundary, thus instead of the expected disassembly I get wrong results:</p>

<pre><code> # expected and working in binutils 2.24
$ ndisasm -b 32 -o 0xb77431d9 test.bin
B77431D9  E8E2FFFFFF        call dword 0xb77431c0

 # actual in binutils 2.22
$ ndisasm -b 32 -o 0xb77431d9 test.bin
B77431D9  90                nop
B77431DA  90                nop
B77431DB  90                nop
B77431DC  E8DFFFFFFF        call dword 0xb77431c0
</code></pre>

<p>The problem is in the <code>as</code> command (i.e. not <code>ld</code>): <code>readelf -S</code> gives me the following for results of <code>as</code> 2.22:</p>

<pre><code>$ readelf -S test.o | grep ' \.text'
  [ 1] .text             PROGBITS        00000000 000034 000005 00  AX  0   0  4
</code></pre>

<p>And for 2.24 I have</p>

<pre><code>$ readelf -S test.o | grep ' \.text'
  [ 1] .text             PROGBITS        00000000 000034 000005 00  AX  0   0  1
</code></pre>

<p>So the problem is indeed alignment of <code>.text</code> section. I've tried placing <code>.align 0</code> and <code>.align 1</code> in various places in the source, but it didn't change the output.</p>

<p>So my <strong>question</strong> now: how to explicitly specify section alignment for ELF target in GNU assembler?</p>