[cfe-users] Compiling big-endian code on powerpc64le

Andrei Borzenkov arvidjaar at gmail.com
Mon Jul 6 20:30:54 PDT 2015

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

> > On 01.07.2015, at 05:26, Andrei Borzenkov <arvidjaar at gmail.com> wrote:
> > 
> > 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

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?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-ppc-endian-switch.patch
Type: text/x-patch
Size: 1275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20150707/69be29be/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-pass-endian-to-gcc.patch
Type: text/x-patch
Size: 920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20150707/69be29be/attachment-0001.bin>

More information about the cfe-users mailing list