<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.0.10"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>12931</bug_id>
          
          <creation_ts>2011-06-24 19:29:00 +0000</creation_ts>
          <short_desc>ARM: gas fails to set the proper alignment on code sections, causing broken output</short_desc>
          <delta_ts>2011-07-01 04:19:31 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>binutils</product>
          <component>gas</component>
          <version>2.22</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dave Martin">dave.martin</reporter>
          <assigned_to>unassigned</assigned_to>
          <cc>hp</cc>
    
    <cc>mgretton</cc>
    
    <cc>nickc</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <long_desc isprivate="0">
            <commentid>49475</commentid>
            <who name="Dave Martin">dave.martin</who>
            <bug_when>2011-06-24 19:29:40 +0000</bug_when>
            <thetext>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&apos;t be executed correctly.

I don&apos;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 &lt;&lt;EOF &gt;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 &lt;f&gt;:
   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 &lt;f&gt;:
   0:   46c0            nop                     ; (mov r8, r8)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49476</commentid>
            <who name="Dave Martin">dave.martin</who>
            <bug_when>2011-06-24 19:30:19 +0000</bug_when>
            <thetext>For details of the Firefox/WebM bug, see:

https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/789198</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49506</commentid>
              <attachid>5824</attachid>
            <who name="Dave Martin">dave.martin</who>
            <bug_when>2011-06-28 12:57:37 +0000</bug_when>
            <thetext>Created attachment 5824
possible fix

The attached patch hooks into mapping_state() to mark the alignment requirement on the current output section whenever we start emitting instructions.

It might be safer to make the alignment 4 for Thumb code as well as ARM code; the current patch gives Thumb code an alignment of 2 bytes, based on the principles that (a) this makes the current situation no worse, and (b) all realistic situations where a Thumb code section requires 4-byte alignment will involve an explicit .align or literal pool somewhere, so we don&apos;t need to worry.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49549</commentid>
            <who name="cvs-commit@gcc.gnu.org">cvs-commit</who>
            <bug_when>2011-06-29 16:29:43 +0000</bug_when>
            <thetext>CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2011-06-29 16:29:38

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-arm.c 

Log message:
	PR gas/12931
	* config/tc-arm.c (mapping_state): When changing to ARM or THUMB
	state set the minimum required alignment of the section.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&amp;r1=1.4527&amp;r2=1.4528
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-arm.c.diff?cvsroot=src&amp;r1=1.495&amp;r2=1.496</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49550</commentid>
            <who name="Nick Clifton">nickc</who>
            <bug_when>2011-06-29 16:33:44 +0000</bug_when>
            <thetext>Hi Dave,

  Thanks for reporting this problem and providing a patch to fix it too.  I think that 2 byte alignment should be fine for thumb-code-containing sections, but if someone does come up with a scenario where this assumption does not work then we can always fix the assembler again.

Cheers
  Nick</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49551</commentid>
            <who name="Dave Martin">dave.martin</who>
            <bug_when>2011-06-29 16:47:08 +0000</bug_when>
            <thetext>On Wed, Jun 29, 2011 at 5:33 PM, nickc at redhat dot com
&lt;sourceware-bugzilla@sourceware.org&gt; wrote:
&gt; http://sourceware.org/bugzilla/show_bug.cgi?id=12931
&gt;
&gt; Nick Clifton &lt;nickc at redhat dot com&gt; changed:
&gt;
&gt;           What    |Removed                     |Added
&gt; ----------------------------------------------------------------------------
&gt;             Status|NEW                         |RESOLVED
&gt;                 CC|                            |nickc at redhat dot com
&gt;         Resolution|                            |FIXED
&gt;
&gt; --- Comment #4 from Nick Clifton &lt;nickc at redhat dot com&gt; 2011-06-29 16:33:44 UTC ---
&gt; Hi Dave,
&gt;
&gt;  Thanks for reporting this problem and providing a patch to fix it too.  I
&gt; think that 2 byte alignment should be fine for thumb-code-containing sections,
&gt; but if someone does come up with a scenario where this assumption does not work
&gt; then we can always fix the assembler again.

That seems reasonable -- I think the proposed fix should be a useful
interim step, since it&apos;s pretty simple and makes the situation no
worse.

Did the patch look sensible to you?  I&apos;m no gas hacker...


Cheers
---Dave</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49552</commentid>
            <who name="Nick Clifton">nickc</who>
            <bug_when>2011-06-29 16:53:42 +0000</bug_when>
            <thetext>Hi Dave,

&gt; Did the patch look sensible to you?  I&apos;m no gas hacker...

Are you sure ? ... The patch was fine. :-)

Cheers
   Nick</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49579</commentid>
            <who name="cvs-commit@gcc.gnu.org">cvs-commit</who>
            <bug_when>2011-06-30 13:07:24 +0000</bug_when>
            <thetext>CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2011-06-30 13:07:21

Modified files:
	gas/testsuite  : ChangeLog 
	gas/testsuite/gas/arm: blx-bad.d inst-po-be.d inst-po.d 

Log message:
	PR gas/12931
	* gas/arm/blx-bad.d: Add exrta nop at end of disassembly.
	* gas/arm/inst-po-be.d: Add exrta nop at end of disassembly.
	* gas/arm/inst-po.d: Add exrta nop at end of disassembly.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&amp;r1=1.1925&amp;r2=1.1926
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/arm/blx-bad.d.diff?cvsroot=src&amp;r1=1.2&amp;r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/arm/inst-po-be.d.diff?cvsroot=src&amp;r1=1.1&amp;r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/arm/inst-po.d.diff?cvsroot=src&amp;r1=1.1&amp;r2=1.2</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>49607</commentid>
            <who name="Hans-Peter Nilsson">hp</who>
            <bug_when>2011-07-01 04:19:31 +0000</bug_when>
            <thetext>Nick (being already CC:ed on the referred PR) or anyone else ARM-knowledgeable, pretty please have a quick look to see if the fix for this bug was the proper fix for PR sim/12737.  Thanks.</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
              isurl="0"
          >
            <attachid>5824</attachid>
            <date>2011-06-28 12:57:00 +0000</date>
            <delta_ts>2011-06-28 12:57:37 +0000</delta_ts>
            <desc>possible fix</desc>
            <filename>align-code-sections.diff</filename>
            <type>text/plain</type>
            <size>1259</size>
            <attacher>dave.martin</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL2dhcy9jb25maWcvdGMtYXJtLmMgYi9nYXMvY29uZmlnL3RjLWFybS5jCmlu
ZGV4IDFkOTY0YzMuLmYwNGMzY2YgMTAwNjQ0Ci0tLSBhL2dhcy9jb25maWcvdGMtYXJtLmMKKysr
IGIvZ2FzL2NvbmZpZy90Yy1hcm0uYwpAQCAtMjU4OSw3ICsyNTg5LDIzIEBAIG1hcHBpbmdfc3Rh
dGUgKGVudW0gbXN0YXRlIHN0YXRlKQogICAgIC8qIFRoZSBtYXBwaW5nIHN5bWJvbCBoYXMgYWxy
ZWFkeSBiZWVuIGVtaXR0ZWQuCiAgICAgICAgVGhlcmUgaXMgbm90aGluZyBlbHNlI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isKKyAgaWYgKFRSQU5TSVRJT04gKE1BUF9VTkRFRklORUQsIE1BUF9EQVRBKSkKICAgICAv
KiBUaGlzIGNhc2Ugd2lsbCBiZSBldmFsdWF0ZWQgbGF0ZXIgaW4gdGhlIG5leHQgZWxzZS4gICov
CiAgICAgcmV0dXJuOwogICBlbHNlIGlmIChUUkFOU0lUSU9OIChNQVBfVU5ERUZJTkVELCBNQVBf
QVJNKQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>