Compiling big-endian code on powerpc64le

GCC allows to build either little endian or big endian code on PowerPC
using -mlittle-endian or -mbig-endian. As far as I know clang supports
this option only on AArch64. Is there other options that allow it?
I /think/ that selecting the right target could do it, like in

clang -target powerpc

Am I right?

TIA

-andrei

LLVM doesn't support little endian 32-bit PowerPC currently. There is some support for little-endian ppc64 though, it can be enabled with '-target powerpc64-your-triple' or with '-mlittle-endian' (after r241528).

- Benjamin

В Tue, 7 Jul 2015 02:05:01 +0200
Benjamin Kramer <benny.kra@gmail.com> пишет:

>
> GCC allows to build either little endian or big endian code on PowerPC
> using -mlittle-endian or -mbig-endian. As far as I know clang supports
> this option only on AArch64. Is there other options that allow it?
> I /think/ that selecting the right target could do it, like in
>
> clang -target powerpc
>
> Am I right?

LLVM doesn't support little endian 32-bit PowerPC currently. There is some support for little-endian ppc64 though, it can be enabled with '-target powerpc64-your-triple' or with '-mlittle-endian' (after r241528).

I do not need little endian 32-bit PowerPC. I want to compile for 32 bit
big endian PowerPC.

Background - PowerPC starts in big endian mode after power reset and
firmware runs in big endian mode as well. I want to compile standalone
bootloader that should run on bare metal. This bootloader already fully
supports ppc32 so the most simple solution is to compile it as existing
big endian ppc32 on ppc64le. This should be possible on native ppc64le
Linux with as little (ideal, no) requirement for cross tool chain.

In the mean time I made some progress.

1. Using --target=powerpc indeed *compiles* into ppc32 BE object
module.

2. Adding support for -mbig-endian/-mlittle-endian to driver looks
trivial, unless I miss something obvious. Does attached patch
clang-ppc-endian-switch.patch has chances to be accepted?

3. The problem is linking. As the whole point is to avoid installing
cross tool chain, clang falls back to using gcc as linker (linker
itself is built with support for all targets). Unfortunately, in this
case it passes no indication about using big endian target, meaning, gcc
tries to link for default little endian and fails with object format
mismatch. Does second patch clang-pass-endian-to-gcc.patch has chances
to be accepted?

Thanks.

clang-ppc-endian-switch.patch (1.25 KB)

clang-pass-endian-to-gcc.patch (920 Bytes)