Bug 43961 - [4.7 Regression] [ARM thumb] "branch out of range" with thumb1_output_casesi
Summary: [4.7 Regression] [ARM thumb] "branch out of range" with thumb1_output_casesi
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 44603 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-05-02 10:59 UTC by Daisuke Ban
Modified: 2014-06-12 12:56 UTC (History)
4 users (show)

See Also:
Host: i686-pc-cygwin
Target: arm-elf,arm-eabi
Build:
Known to work: 4.8.0
Known to fail: 4.6.0, 4.7.4
Last reconfirmed: 2010-05-10 16:03:26


Attachments
test source for reproduce the bug (83.91 KB, text/plain)
2010-05-02 11:05 UTC, Daisuke Ban
Details
patch (quick hack ;-) (784 bytes, patch)
2010-05-02 11:08 UTC, Daisuke Ban
Details | Diff
proposed fix for PR43961 (486 bytes, patch)
2010-06-22 12:28 UTC, Mikael Pettersson
Details | Diff
More complicated fix for 4.6 (1.01 KB, patch)
2013-01-09 21:55 UTC, Joseph S. Myers
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daisuke Ban 2010-05-02 10:59:34 UTC
Environment:

$ arm-elf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-elf-gcc
COLLECT_LTO_WRAPPER=/cygdrive/c/usr/local/cross/libexec/gcc/arm-elf/4.5.0/lto-wrapper.exe
Target: arm-elf
Configured with: ../configure --prefix=/cygdrive/c/usr/local/cross --target=arm-elf --with-float=soft --enable-languages=c,c++ --enable-lto --with-libelf=/usr/local
Thread model: single
gcc version 4.5.0 (GCC)

Error:

$ arm-elf-gcc -c -Os -mthumb test.i
/cygdrive/c/Users/exceed/AppData/Local/Temp/cc6UR3zm.s: Assembler messages:
/cygdrive/c/Users/exceed/AppData/Local/Temp/cc6UR3zm.s:32816: Error: branch out of range

Problem:

I think that the length of jump table does not contains a align code.
When jump table mode is SImode, ASM_OUTPUT_CASE_LABEL generates a align code.
But length does not contains this align code. (And ADDR_VEC_ALIGN is defined to 0)

Quick hack (for 4.5 branch):

Please see attached file.
Comment 1 Daisuke Ban 2010-05-02 11:05:39 UTC
Created attachment 20532 [details]
test source for reproduce the bug

$ arm-elf-gcc -c -Os -mthumb test.i
Comment 2 Daisuke Ban 2010-05-02 11:08:26 UTC
Created attachment 20533 [details]
patch (quick hack ;-)

From gcc-4_5-branch (svn r158961)
Comment 3 Mikael Pettersson 2010-05-02 19:37:45 UTC
Also breaks on armv5tel-unknown-linux-gnueabi with gcc-4.5-20100429 and gcc-4.6-20100501. It works with gcc-4.4-20100427 and gcc-4.3-20100103.
Comment 4 Ramana Radhakrishnan 2010-05-10 16:03:26 UTC
Confirmed - marking as a target bug .
Comment 5 Mikael Pettersson 2010-06-22 12:22:41 UTC
It's caused by r148770, which is when Richard Earnshaw added compressed switch table support for Thumb-1.  See also:

http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01698.html
Comment 6 Mikael Pettersson 2010-06-22 12:28:09 UTC
Created attachment 20979 [details]
proposed fix for PR43961

Update ARM's ADDR_VEC_ALIGN to correctly describe that its ASM_OUTPUT_CASE_LABEL will add a 2-byte alignment directive for Thumb-1 compressed switch tables.  This fixes the test cases (both the PR43961 and the PR44603 one) for me.  Untested beyond that, will include in full bootstraps and regtests shortly.
Comment 7 Ramana Radhakrishnan 2010-07-03 00:21:11 UTC
*** Bug 44603 has been marked as a duplicate of this bug. ***
Comment 8 Joseph S. Myers 2013-01-03 00:00:08 UTC
Mikael, ping on this patch from June 2010 ... what happened in testing?  And shouldn't this bug be marked as a regression, given the identification of the responsible revision?
Comment 9 Mikael Pettersson 2013-01-03 08:54:35 UTC
(In reply to comment #8)
> Mikael, ping on this patch from June 2010 ... what happened in testing?

I've included this patch in my local 4.6-based branch since June 2010, and it's tested w/o regressions on armv5te ever since (configured w/o --disable-multilib, so I assume the test suite will also test Thumb-1 not just ARM mode).

The patch apparently didn't work in a 4.5-based compiler, but I don't have any notes explaining what the issue was.  4.5 is EOL anyway.

Somehow I forgot to forward-port it to 4.7 so I haven't tested it yet in my 4.7-based branch.  Will do that asap.
Comment 10 Joseph S. Myers 2013-01-03 16:19:42 UTC
If the patch works for mainline, please do send it to gcc-patches as usual.
Comment 11 Joseph S. Myers 2013-01-09 21:55:08 UTC
Created attachment 29133 [details]
More complicated fix for 4.6

The previous proposed patch breaks Thumb-2, because alignments for labels get set based on ADDR_VEC_ALIGN before jump tables get shortened from SImode to a narrower mode, and not updated afterwards so there is spurious alignment between a tbb instruction and a jump table.  This patch adds code to shorten_branches to allow for this issue.  4.6-based; I'll test for mainline.
Comment 12 Joseph S. Myers 2013-01-15 16:17:53 UTC
Author: jsm28
Date: Tue Jan 15 16:17:28 2013
New Revision: 195208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195208
Log:
2013-01-15  Joseph Myers  <joseph@codesourcery.com>
	    Mikael Pettersson  <mikpe@it.uu.se>

	PR target/43961
	* config/arm/arm.h (ADDR_VEC_ALIGN): Align SImode jump tables for
	Thumb.
	(ASM_OUTPUT_CASE_LABEL): Remove.
	(ASM_OUTPUT_BEFORE_CASE_LABEL): Define to empty.
	* final.c (shorten_branches): Update alignment of labels before
	jump tables if CASE_VECTOR_SHORTEN_MODE.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.h
    trunk/gcc/final.c
Comment 13 Joseph S. Myers 2013-01-15 16:21:51 UTC
Fixed for 4.8.
Comment 14 Jakub Jelinek 2013-04-12 15:15:47 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 15 Richard Biener 2014-06-12 12:56:38 UTC
Fixed for 4.8.0