Comment 20 for bug 789198

Revision history for this message
In , Dave Martin (dave-martin-arm) wrote :

Whenever an instruction is assembled, gas should increase the alignment of the output section.

Currently the output section alignment is often left untouched, which may result in invalid alignment when sections are merged at link-time.

This appears to be responsible for a faulty WebM codec behaviour when firefox-5 is built in Thumb, as a result of ARM code being linked into .text alongside Thumb code. The ARM instructions are placed at halfword alignment and so can't be executed correctly.

I don't know if this is a recent regression or an older bug.

It appears present in trunk as of 2011-06-24.
The bug is also present in linaro binutils 2.21.0.20110327-2ubuntu2cross1.62

In both of the cases below, the .text section alignment should not be 2**0. The alignment should probably be set to 2**2 (though it could in principle be 2**1 for some Thumb code, some Thumb instructions are alignment-sensitive modulo 1 word; the 16-bit PC-relative add and ldr instructions have this restriction).

$ cat <<EOF >tst-align.s
.type f, %function
.globl f
f: nop
EOF

$ arm-linux-gnueabi-as -o tst-align.o tst-align.s
$ arm-linux-gnueabi-objdump -hd tst-align.o

tst-align.o: file format elf32-littlearm

Sections:
Idx Name Size VMA LMA File off Algn
  0 .text 00000004 00000000 00000000 00000034 2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data 00000000 00000000 00000000 00000038 2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss 00000000 00000000 00000000 00000038 2**0
                  ALLOC
  3 .ARM.attributes 00000016 00000000 00000000 00000038 2**0
                  CONTENTS, READONLY

Disassembly of section .text:

00000000 <f>:
   0: e1a00000 nop ; (mov r0, r0)
$ arm-linux-gnueabi-as mthumb
$ arm-linux-gnueabi-objdump -hd tst-align.o

tst-align.o: file format elf32-littlearm

Sections:
Idx Name Size VMA LMA File off Algn
  0 .text 00000002 00000000 00000000 00000034 2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data 00000000 00000000 00000000 00000036 2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss 00000000 00000000 00000000 00000036 2**0
                  ALLOC
  3 .ARM.attributes 00000016 00000000 00000000 00000036 2**0
                  CONTENTS, READONLY

Disassembly of section .text:

00000000 <f>:
   0: 46c0 nop ; (mov r8, r8)