[PR40523] GCC generates invalid instructions when building for Thumb-2 on armel

Bug #347864 reported by Dave Martin
10
Affects Status Importance Assigned to Milestone
gcc
Fix Released
Undecided
Unassigned
gcc-4.3 (Ubuntu)
Fix Released
Medium
Unassigned
Jaunty
Won't Fix
Undecided
Unassigned
gcc-4.4 (Ubuntu)
Fix Released
Undecided
Unassigned
Jaunty
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: gcc-4.3

When building for the Thumb-2 instruction set, GCC appears to generate Thumb2 loads and stores with invalid address offsets and base register writeback. The Thumb-2 instruction set does not support the full offset range for these instructions, causing the assembler to fail.

The failure is observed as follows:
g++ -march=armv7 -mthumb -O2 -c asbug.c++

/tmp/ccrSTYGR.s:525: Error: offset out of range

Line 545 of the generated assembler is:
        ldr r2, [sl, #264]!
However, the allowed offset range for this instruction is restricted to be <256.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu jaunty (development branch)
Release: 9.04
Codename: jaunty

$ apt-cache policy gcc-4.3
gcc-4.3:
  Installed: 4.3.3-5ubuntu4
  Candidate: 4.3.3-5ubuntu4
  Version table:
 *** 4.3.3-5ubuntu4 0
        500 http://arm-ports-ubuntu jaunty/main Packages
        100 /var/lib/dpkg/status

Tags: armel thumb
Revision history for this message
Dave Martin (dave-martin-arm) wrote :
Revision history for this message
Matthias Klose (doko) wrote :

is this fixed on the trunk?

Revision history for this message
Matthias Klose (doko) wrote :

(either gcc or binutils)

Revision history for this message
Dave Martin (dave-martin-arm) wrote : RE: [Bug 347864] Re: GCC generates invalid instructions when building forThumb-2 on armel

Ed, what tools did you try again?

Cheers
---Dave

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On
> Behalf Of Matthias Klose
> Sent: 24 March 2009 12:43
> To: Dave P Martin
> Subject: [Bug 347864] Re: GCC generates invalid instructions
> when building forThumb-2 on armel
>
> is this fixed on the trunk?
>
> --
> GCC generates invalid instructions when building for Thumb-2 on armel
> https://bugs.launchpad.net/bugs/347864
> You received this bug notification because you are a direct
> subscriber of the bug.
>
> Status in "gcc-4.3" source package in Ubuntu: New
>
> Bug description:
> Binary package hint: gcc-4.3
>
> When building for the Thumb-2 instruction set, GCC appears to
> generate Thumb2 loads and stores with invalid address offsets
> and base register writeback. The Thumb-2 instruction set
> does not support the full offset range for these
> instructions, causing the assembler to fail.
>
> The failure is observed as follows:
> g++ -march=armv7 -mthumb -O2 -c asbug.c++
>
> /tmp/ccrSTYGR.s:525: Error: offset out of range
>
> Line 545 of the generated assembler is:
> ldr r2, [sl, #264]!
> However, the allowed offset range for this instruction is
> restricted to be <256.
>
> $ lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu jaunty (development branch)
> Release: 9.04
> Codename: jaunty
>
> $ apt-cache policy gcc-4.3
> gcc-4.3:
> Installed: 4.3.3-5ubuntu4
> Candidate: 4.3.3-5ubuntu4
> Version table:
> *** 4.3.3-5ubuntu4 0
> 500 http://arm-ports-ubuntu jaunty/main Packages
> 100 /var/lib/dpkg/status
>
--
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Revision history for this message
Dave Martin (dave-martin-arm) wrote : Re: GCC generates invalid instructions when building for Thumb-2 on armel

Oops, disregard that last comment.

I will check up on what tools we've tried...

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

It's a GCC bug, so we can disregard binutils (the assembler is correct in rejecting the problem instruction).
It looks like the problem is that GCC is making bad assumptions about operand ranges for some instructions passed to the assembler. Note that the generated instruction would be OK when generating ARM code, but it looks like the Thumb-2 is more restricted with regard to some operand ranges.

We've tried with a new compiler from the CodeSourcery branch (Sourcery G++ Lite 2009q1-123 - Preview, GCC 4.3.3) - this does not hit the bug, but it looks like this could be due to differences in code generation... so this compiler may work just because we are lucky and GCC is not generating the problem instruction when compiling this code.

I do not know the status of any fix relating to this on GCC mainline.

Someone who understands the code generation backend in GCC probably ought to take a look, but I'm not familiar with this myself... It will be hard to find a test case which is reliable across diverse compiler versions, because code generation differences may make the problem appear or disappear.

Revision history for this message
Matthias Klose (doko) wrote :

the gcc-snapshot package has a recent snapshot from the gcc trunk.

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

Useful to know, thanks.

gcc-snapshot (4.4.0 20090225) appears not to produce the error.

It looks like the difference may be connected with the code GCC generates for doubleword memory accesses in Thumb-2 code:

http://gcc.gnu.org/ml/gcc-patches/2009-01/msg00659.html

gcc-snapshot certainly makes more extensive use of LDRD instructions than gcc 4.3.3-5ubuntu4 for this code, though again it's hard to be certain whether that's by accident or by design.

Also, I think Ed Nevill (on subscribers list) is trying to build publishable updates for openjdk, and gcc-snapshot is not really usable for this.

Ed, is it feasible/possible to build the problem sources with different compiler options, or do we need some other solution?

For comparison purposes, I'll post the output of the two compilers with the same compilation options:

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

[See asbug_gcc-4.3.3-5ubuntu4.s and asbug_gcc-snapshot_20090225-0ubuntu1.s]

Matthias Klose (doko)
Changed in gcc-4.4 (Ubuntu):
status: New → Fix Released
Paul Larson (pwlars)
tags: added: arm
Paul Larson (pwlars)
tags: added: armel
removed: arm
Matthias Klose (doko)
Changed in gcc-4.3 (Ubuntu):
importance: Undecided → Medium
status: New → Triaged
Matthias Klose (doko)
summary: - GCC generates invalid instructions when building for Thumb-2 on armel
+ [PR40523] GCC generates invalid instructions when building for Thumb-2
+ on armel
Changed in gcc:
status: Unknown → In Progress
Matthias Klose (doko)
Changed in gcc-4.4 (Ubuntu Jaunty):
status: New → Invalid
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gcc-4.3 - 4.3.3-12ubuntu3

---------------
gcc-4.3 (4.3.3-12ubuntu3) karmic; urgency=low

  * Update to SVN 20090710 from the gcc-4_3-branch.
    - Fixes PR middle-end/40328, PR tree-optimization/40669,
      PR middle-end/40585, PR tree-optimization/40542,
      PR tree-optimization/40579, PR tree-optimization/40550, PR fortran/40638.
  * ARM: don't synthesize thumb-2 ldrd/strd with two 32-bit instructions.
    LP: #347864.

 -- Matthias Klose <email address hidden> Fri, 10 Jul 2009 08:18:06 +0200

Changed in gcc-4.3 (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
Matthias Klose (doko) wrote :

Dave, please could you recheck with the current gcc-4.3 from karmic?

Revision history for this message
Matthias Klose (doko) wrote :

won't fix for gcc-4.3 in jaunty

Changed in gcc-4.3 (Ubuntu Jaunty):
status: New → Won't Fix
Christian Reis (kiko)
tags: removed: thumb2
Revision history for this message
Jani Monoses (jani) wrote :

No longer affects current Ubuntu

Changed in gcc:
importance: Unknown → Undecided
status: In Progress → New
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.