I'm trying to use GNU as as a generic assembler similar in use as nasm. I make a template source like this:
.section .text
.globl _start
.intel_syntax noprefix
_start:
call 0xb77431c0 # the instruction I want to assemble
And then I run the assemble command like this:
as --32 -o test.o test.s
ld -m elf_i386 -Ttext 0xb77431d9 --oformat binary -o test.bin test.o
All works well with binutils 2.24. But it appears that as from binutils 2.22 (the one in Ubuntu Precise) aligns .text section to the 4-byte boundary, thus instead of the expected disassembly I get wrong results:
# 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
The problem is in the as command (i.e. not ld): readelf -S gives me the following for results of as 2.22:
$ readelf -S test.o | grep ' \.text'
[ 1] .text PROGBITS 00000000 000034 000005 00 AX 0 0 4
And for 2.24 I have
$ readelf -S test.o | grep ' \.text'
[ 1] .text PROGBITS 00000000 000034 000005 00 AX 0 0 1
So the problem is indeed alignment of .text section. I've tried placing .align 0 and .align 1 in various places in the source, but it didn't change the output.
So my question now: how to explicitly specify section alignment for ELF target in GNU assembler?