#552314 gcc produces invalid mips branch instructions

Package:
gcc
Source:
gcc-defaults
Description:
GNU C compiler
Submitter:
"Wesley W. Terpstra"
Date:
2010-05-05 08:12:03 UTC
Severity:
normal
#552314#5
Date:
2009-10-25 13:14:05 UTC
From:
To:
gcc produces invalid assembler on mips during compilation of the
package 'mlton' [1]. I have attached an example C file which triggers
this error:
/tmp/cc62P8aG.s: Assembler messages:
/tmp/cc62P8aG.s:32335: Error: Branch out of range

Compile as:
gcc -std=gnu99 -O1 -fno-strict-aliasing -w foo.c

This problem appears only sporadically. Previous builds did not
encounter this problem, nor does the current mipsel build. Possibly
the attached (generated) C file is tripping over some corner case?

Are there any work-around gcc flags I can use before this gets fixed?

[1] <https://buildd.debian.org/fetch.cgi?pkg=mlton&arch=mips&ver=20091022&stamp=1256234307&file=log&as=raw>

#552314#10
Date:
2009-12-30 00:16:02 UTC
From:
To:
tags 552314 + moreinfo
thanks

please recheck with gcc-4.4 4.4.2-8 and gcc-snapshot from unstable

#552314#17
Date:
2010-02-05 19:03:11 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
mlton, which is due to be installed in the Debian FTP archive:

mlton_20100205~svn-r7410.diff.gz
  to main/m/mlton/mlton_20100205~svn-r7410.diff.gz
mlton_20100205~svn-r7410.dsc
  to main/m/mlton/mlton_20100205~svn-r7410.dsc
mlton_20100205~svn-r7410_i386.deb
  to main/m/mlton/mlton_20100205~svn-r7410_i386.deb
mlton_20100205~svn.orig.tar.gz
  to main/m/mlton/mlton_20100205~svn.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 552314@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Wesley W. Terpstra (Debian) <terpstra@debian.org> (supplier of updated mlton package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)
Format: 1.8
Date: Fri, 05 Feb 2010 17:13:06 +0100
Source: mlton
Binary: mlton
Architecture: source i386
Version: 20100205~svn-r7410
Distribution: unstable
Urgency: low
Maintainer: Wesley W. Terpstra (Debian) <terpstra@debian.org>
Changed-By: Wesley W. Terpstra (Debian) <terpstra@debian.org>
Description:
 mlton      - Optimizing compiler for Standard ML
Closes: 552314
Changes:
 mlton (20100205~svn-r7410) unstable; urgency=low
 .
   * New snapshot from svn/HEAD
    * Split targets into sub-folder
    * makes cross-compiler packages possible
   * Add a debian/watch file for lintian
   * Correct spelling errors in the manual page
   * Updated to policy 3.8.4.0 (no changes)
   * Removed -fPIC work-around for mips (closes: #552314)
Checksums-Sha1:
 b89d0fdfde8963445372f7a196e22335e96d5540 1208 mlton_20100205~svn-r7410.dsc
 5ca5945c2515728795e127310514ce76d65a6e9e 5863195 mlton_20100205~svn.orig.tar.gz
 b5832be6848a7ba3b978cb80c9aaeedcd9ff4213 8476 mlton_20100205~svn-r7410.diff.gz
 4edbb931c95aface842c7c0cf8f89be8af4b0b60 10573266 mlton_20100205~svn-r7410_i386.deb
Checksums-Sha256:
 46aa95c626d8f7e7589bb687febd52962e9c6e82403af8ddb6a0f50cbbc4b269 1208 mlton_20100205~svn-r7410.dsc
 d5bb12c1fd59fff804de5dedd6d2c7dfe3a47fb1670f7d489d0763e859ddcc56 5863195 mlton_20100205~svn.orig.tar.gz
 7d96d25dabf8331607609e87756d7a877635995018f9f16c83b8e1fc5856146f 8476 mlton_20100205~svn-r7410.diff.gz
 3f6785ef5c012d906b6bd687491419807d7c44096a9cda89b4f4868fc6cd10fb 10573266 mlton_20100205~svn-r7410_i386.deb
Files:
 1e893f7eb728ee485d8a926036cc7add 1208 devel optional mlton_20100205~svn-r7410.dsc
 97fc8ff45dac3f9ce2a8b143449e00a6 5863195 devel optional mlton_20100205~svn.orig.tar.gz
 2253ca819694c3fdd757fbbbd7768f40 8476 devel optional mlton_20100205~svn-r7410.diff.gz
 b7b64d6627d5e9c5e0d5aa69864aaa33 10573266 devel optional mlton_20100205~svn-r7410_i386.deb
iEYEARECAAYFAktsZtoACgkQvLvElXGKklbqIACdFnw9fYblyZNOvBd1Z06Fv8R8
q0EAn0fq198KV3nAC56a1SjvD24qxm4B
=LSWN
-----END PGP SIGNATURE-----

#552314#22
Date:
2010-02-06 10:13:46 UTC
From:
To:
reopen 552314
thanks

Well, whatever was changed in the latest gcc makes gcc stop
complaining that a branch is out of range. However, the problem is NOT
fixed. Instead of the compiler aborting, it now creates broken object
code that will segfault on whatever code previously triggered this
behaviour. My work-around of using '-fPIC' to slightly alter the
program size still avoids the problem.

https://buildd.debian.org/fetch.cgi?pkg=mlton&arch=mips&ver=20100205~svn-r7410&stamp=1265408802&file=log&as=raw
https://buildd.debian.org/fetch.cgi?pkg=mlton&arch=mipsel&ver=20100205~svn-r7410&stamp=1265415414&file=log&as=raw

#552314#29
Date:
2010-05-05 08:07:27 UTC
From:
To:
The 'use -fPIC' hack I've been using to avoid this problem doesn't help with
the newest gcc in sid.

<
https://buildd.debian.org/fetch.cgi?pkg=mlton&arch=mips&ver=20100504~svn-r7459&stamp=1273006902&file=log&as=raw

      gcc -std=gnu99 -c -I/usr/lib/mlton/targets/self/include \
          -I/usr/lib/mlton/include -O1 -fno-common -fno-strict-aliasing \
          -fomit-frame-pointer -w -fPIC -o /tmp/fileTmKIAk.o \
          /tmp/file6ErB3L.257.c
/tmp/cc0HroCk.s: Assembler messages:
/tmp/cc0HroCk.s:58809: Error: Branch out of range


I suppose I should be grateful that the bug no longer causes invalid code to
be generated. Can someone please look into this problem? From reports I've
found with google, mips has had this problem on and off for over five years.
Wouldn't it be sensible to just add a bit of wiggle room to the test which
determines whether a near or far branch instruction is appropriate? Maybe a
simple heuristic like 'within 10 instructions of being outside of short
reach means use a far instruction'?