Bug 16350 - gcc only understands little endian ARM systems
Summary: gcc only understands little endian ARM systems
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch
: 39975 42081 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-07-03 15:45 UTC by Lennert Buytenhek
Modified: 2013-03-20 00:46 UTC (History)
9 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: armv5b-softfloat-linux
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 3.4.0, 3.4.2, 4.1.2, 4.2.0, 4.2.1, 4.2.2
Last reconfirmed: 2010-01-26 17:44:11


Attachments
This is a suggested fix to make gcc understand arm*b-* (972 bytes, patch)
2004-07-03 15:45 UTC, Lennert Buytenhek
Details | Diff
equivalent patch for gcc 4.0 20050305 (937 bytes, patch)
2005-03-24 09:39 UTC, Lennert Buytenhek
Details | Diff
proposed patch for gcc 3.4.0 (973 bytes, patch)
2005-03-24 10:37 UTC, Lennert Buytenhek
Details | Diff
proposed patch for gcc 4.0-20050305 (940 bytes, patch)
2005-03-24 10:39 UTC, Lennert Buytenhek
Details | Diff
gcc-4.1.0-arm-bigendian.patch (851 bytes, patch)
2006-04-12 04:01 UTC, Mike Frysinger
Details | Diff
fix target linker emulation for arm elf and eabi (1.12 KB, patch)
2006-08-08 13:31 UTC, Marc Kleine-Budde
Details | Diff
fix target linker emulation for arm elf and eabi (take 2) (1.13 KB, patch)
2006-11-03 13:49 UTC, Marc Kleine-Budde
Details | Diff
fix target linker emulation for arm elf and eabi (take 3) (1.29 KB, patch)
2006-11-29 09:55 UTC, Marc Kleine-Budde
Details | Diff
updated to gcc-4.3 trunk (1.31 KB, patch)
2007-11-07 20:50 UTC, Bernhard Reutner-Fischer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lennert Buytenhek 2004-07-03 15:45:01 UTC
The triplet armv5b-softfloat-linux gives a binutils package that generates ARM
big endian object files by default, but gcc insists that armv5b-softfloat-linux
is little endian.
Comment 1 Lennert Buytenhek 2004-07-03 15:45:51 UTC
Created attachment 6680 [details]
This is a suggested fix to make gcc understand arm*b-*
Comment 2 Andrew Pinski 2004-07-03 22:16:34 UTC
As aways patches goto gcc-patches@gcc.gnu.org after reading <http://gcc.gnu.org/contribute.html>.
Comment 3 dank 2004-08-08 18:44:06 UTC
He did submit it to gcc-patches; see
http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00233.html
The patch seems to fix a real gcc build problem here; 
I'm adding it to crosstool for gcc-3.4.[01]. 
Comment 4 Andrew Pinski 2004-10-13 01:20:23 UTC
Confirmed.
Comment 5 Mike Frysinger 2005-02-25 15:49:32 UTC
this also applies pretty nicely to 3.3.5, 3.4.2, 3.4.3, and even gcc cvs HEAD :(

one question though ... going by config/arm/arm.h, wouldnt you want to
use this logic instead ?
#if TARGET_BIG_ENDIAN_DEFAULT
#define TARGET_ENDIAN_DEFAULT ARM_FLAG_BIG_END
#else
#define TARGET_ENDIAN_DEFAULT -ARM_FLAG_BIG_END
#endif

granted i havent fully tested this change from '0' to '-ARM_FLAG_BIG_END',
but it *seems* to work :)

also, what do we have to do in order to get this into mainline gcc ?
this simple patch has been hanging around for a while :/
Comment 6 Lennert Buytenhek 2005-03-24 09:39:53 UTC
Created attachment 8444 [details]
equivalent patch for gcc 4.0 20050305
Comment 7 Lennert Buytenhek 2005-03-24 10:37:36 UTC
Created attachment 8445 [details]
proposed patch for gcc 3.4.0

fixes regex for big-endian target triples
Comment 8 Lennert Buytenhek 2005-03-24 10:39:19 UTC
Created attachment 8446 [details]
proposed patch for gcc 4.0-20050305

fix regex for big-endian target triples
Comment 9 Mike Frysinger 2006-04-12 04:01:52 UTC
Created attachment 11245 [details]
gcc-4.1.0-arm-bigendian.patch

gcc-4.1.x needs slight tweak since all the ARM_FLAG_* defines have been cut

this patch applies with a little fuzz to mainline
Comment 10 Marc Kleine-Budde 2006-08-08 13:31:50 UTC
Created attachment 12042 [details]
fix target linker emulation for arm elf and eabi
Comment 11 Marc Kleine-Budde 2006-08-08 13:33:01 UTC
(In reply to comment #9)
> Created an attachment (id=11245) [edit]
> gcc-4.1.0-arm-bigendian.patch
> 
> gcc-4.1.x needs slight tweak since all the ARM_FLAG_* defines have been cut
> this patch applies with a little fuzz to mainline

I've rediffed that patch against 4.1.1.
If you try to build a big-endian eabi toolchain, you need another fix (see patch of gcc/config/arm/linux-eabi.h)
Comment 12 Marc Kleine-Budde 2006-11-03 13:49:41 UTC
Created attachment 12542 [details]
fix target linker emulation for arm elf and eabi (take 2)

If you try to build a big-endian eabi toolchain, you need another fix (see
patch of gcc/config/arm/linux-eabi.h)
Comment 13 Marc Kleine-Budde 2006-11-29 09:55:24 UTC
Created attachment 12705 [details]
fix target linker emulation for arm elf and eabi (take 3)

If you try to build a big-endian eabi toolchain, you need another fix (see
patch of gcc/config/arm/linux-eabi.h)
Comment 14 Bernhard Reutner-Fischer 2007-11-07 20:50:39 UTC
Created attachment 14503 [details]
updated to gcc-4.3 trunk

updated against gcc-trunk (for 4.3.0)
Comment 15 Nick Clifton 2007-11-08 13:44:24 UTC
Subject: Bug 16350

Author: nickc
Date: Thu Nov  8 13:44:09 2007
New Revision: 129999

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129999
Log:
  PR target/16350
* config.gcc: For arm*b-* define TARGET_BIG_ENDIAN_DEFAULT.
* config/arm/linux-elf.h (TARGET_ENDIAN_DEFAULT): Define based on TARGET_BIG_ENDIAN_DEFAULT.
   Use for MULTILIB_DEFAULTS.
   (TARGET_DEFAULT): Set according to TARGET_ENDIAN_DEFAULT.
   (LINUX_TARGET_LINK_SPEC): Pass -mlittle-endian on to the assembler.
* config/arm/linux-eabi.h (TARGET_LINKER_EMULATION): Set according to TARGET_BIG_ENDIAN_DEFAULT.
   (SUBTARGET_EXTRA_LINK_SPEC): Likewise.
* gcc/config/arm/bpabi.h (TARGET_DEFAULT_MASK): Set according to TARGET_BIG_ENDIAN_DEFAULT.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config.gcc
    trunk/gcc/config/arm/bpabi.h
    trunk/gcc/config/arm/linux-eabi.h
    trunk/gcc/config/arm/linux-elf.h

Comment 16 Nick Clifton 2007-11-08 13:47:19 UTC
Hi Bernhard,

  I have applied your patch.  I made one small change:  I adjusted the new comments in the header files to:

  /* TARGET_BIG_ENDIAN_DEFAULT is set in
     config.gcc for big endian configurations.  */

This was conformance with the GNU Coding Standards and also for brevity.

Cheers
  Nick
Comment 17 Lennert Buytenhek 2007-11-08 14:26:35 UTC
Subject: Re:  gcc only understands little endian ARM systems

When I (not Bernhard) wrote the original patch, Richard Earnshaw
didn't like the approach.  See:

	http://gcc.gnu.org/ml/gcc-patches/2005-03/msg02265.html
Comment 18 patchapp@dberlin.org 2007-11-10 03:53:38 UTC
Subject: Bug number PR16350

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00358.html
Comment 19 patchapp@dberlin.org 2007-11-10 03:53:43 UTC
Subject: Bug number PR16350

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00362.html
Comment 20 patchapp@dberlin.org 2007-11-10 18:05:19 UTC
Subject: Bug number PR16350

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00358.html
Comment 21 patchapp@dberlin.org 2007-11-22 19:00:41 UTC
Subject: Bug number PR16350

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00362.html
Comment 22 Peter Maydell 2008-07-04 13:18:05 UTC
I notice that the latest patch attached to this bug report doesn't quite match up with what was committed as per comment #15: this bit in gcc/config/arm/linux-elf.h wasn't changed:

 #undef  MULTILIB_DEFAULTS
 #define MULTILIB_DEFAULTS \
-	{ "marm", "mlittle-endian", "mhard-float", "mno-thumb-interwork" }
+	{ "marm", TARGET_ENDIAN_OPTION, "mhard-float", "mno-thumb-interwork" }

I don't know if that was deliberate or not, but my guess based on the revision log for the change is that it was accidental, since the log explicitly says "use it for MULTILIB_DEFAULTS".
Comment 23 Ramana Radhakrishnan 2009-05-06 10:52:29 UTC
*** Bug 39975 has been marked as a duplicate of this bug. ***
Comment 24 Bernhard Reutner-Fischer 2009-06-07 22:51:33 UTC
Nick,

As mentioned in #22 the following hunk that was in the patch was not applied:

diff --git a/gcc/config/arm/linux-elf.h b/gcc/config/arm/linux-elf.h
index 07455ee..d8e65d2 100644
--- a/gcc/config/arm/linux-elf.h
+++ b/gcc/config/arm/linux-elf.h
@@ -51,7 +51,7 @@
 
 #undef  MULTILIB_DEFAULTS
 #define MULTILIB_DEFAULTS \
-	{ "marm", "mlittle-endian", "mhard-float", "mno-thumb-interwork" }
+	{ "marm", TARGET_ENDIAN_OPTION, "mhard-float", "mno-thumb-interwork" }
 
 /* Now we define the strings used to build the spec file.  */
 #undef  LIB_SPEC


Please install.
Comment 25 Ramana Radhakrishnan 2009-12-09 16:10:10 UTC
*** Bug 42081 has been marked as a duplicate of this bug. ***
Comment 26 Bernhard Reutner-Fischer 2010-01-26 17:44:11 UTC
ping.

Although nick's ChangeLog in
comment #c15
mentiones the "Use for MULTILIB_DEFAULTS" the hunk in comment #22 and #24 did not end up in svn:

* config/arm/linux-elf.h (TARGET_ENDIAN_DEFAULT): Define based on
TARGET_BIG_ENDIAN_DEFAULT.
   Use for MULTILIB_DEFAULTS.
   (TARGET_DEFAULT): Set according to TARGET_ENDIAN_DEFAULT.

Comment 27 Dan Egnor 2012-02-09 17:53:24 UTC
The precise scope of this bug is unclear to me.

Big endian Linux targets _do_ seem to work now, and -mbig-endian generates correct code regardless; however, non-Linux big-endian targets do not seem to be recognized as big-endian by default (which means libgcc is built in little endian mode, etc.).

See bug 52187 (which may be a dupe of this one, depending on how you interpret the scope of this bug).
Comment 28 Marc Kleine-Budde 2012-02-13 23:23:56 UTC
(In reply to comment #27)
> The precise scope of this bug is unclear to me.

It's linux specific.

> Big endian Linux targets _do_ seem to work now, and -mbig-endian generates
> correct code regardless; however, non-Linux big-endian targets do not seem to
> be recognized as big-endian by default (which means libgcc is built in little
> endian mode, etc.).
> 
> See bug 52187 (which may be a dupe of this one, depending on how you interpret
> the scope of this bug).

As Richard sid (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52187#c3) you can activate multilib on non-linux target and have both big and little endian libgcc.

regards, Marc
Comment 29 Marc Kleine-Budde 2012-02-13 23:24:28 UTC
(In reply to comment #27)
> The precise scope of this bug is unclear to me.

It's linux specific.

> Big endian Linux targets _do_ seem to work now, and -mbig-endian generates
> correct code regardless; however, non-Linux big-endian targets do not seem to
> be recognized as big-endian by default (which means libgcc is built in little
> endian mode, etc.).
> 
> See bug 52187 (which may be a dupe of this one, depending on how you interpret
> the scope of this bug).

As Richard said (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52187#c3) you can activate multilib on non-linux target and have both big and little endian libgcc.

regards, Marc
Comment 30 Sam Thursfield 2013-01-09 11:36:46 UTC
I hit this bug trying to build a GCC 4.6.2 that defaulted to ARMv7-a big-endian. Correct code would only be produced if "-mbig-endian" was passed during linking so that the --be8 flag was passed to the linker, but this meant that the compiler on my target system defaulted to producing code that didn't work on the target system -- not pretty.

This particular issue has been fixed in 4.7.3 and later, however:

    2012-07-25  Bharathi Seshadri  <bseshadr@cisco.com>
               Jim Wilson  <jimwilso@cisco.com>

           * config/arm/bpabi.h (BE8_LINK_SPEC): Set according to
           TARGET_BIG_ENDIAN_DEFAULT.

From http://gcc.gnu.org/git/gcc.git:

    commit c6e19dd6c296449f6d9e54d630f8198acf103d24
    Author: wilson <wilson@138bc75d-0d04-0410-961f-82ee72b054a4>
    Date:   Wed Jul 25 20:13:46 2012 +0000

        Pass -be8 by default for armv7-a when configured big-endian.
        config/arm/bpabi.h (BE8_LINK_SPEC): Set according to
        TARGET_BIG_ENDIAN_DEFAULT.
    
    
        git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189867
            138bc75d-0d04-0410-961f-82ee72b054a4

Backporting this patch to 4.6.2 means that I now have a compiler that produces correct code just from appending "eb" to the CPU in the target triplet and configuring GCC with the correct --with-arch= flag.
Comment 31 Sam Thursfield 2013-01-09 11:46:59 UTC
Ignore the comment about GCC 4.7.3, which doesn't even exist. Looks like the fix is only in trunk so far.
Comment 32 Andrew Pinski 2013-03-20 00:46:30 UTC
Fixed for 4.8.