Cross compiling with clang

Hello,

I would like to cross compile C code i have to ARM. My host system is a windows machine.

I have found, the rather short, http://clang.llvm.org/docs/CrossCompilation.html guide and it does concisely explain what you need to do when you have a version of clang that is able to cross compile.

But what I could not find is a list, link or reference to where get a version of clang for windows which is able to cross-compile to ARM.

Using the version I got from the downloads site i get:
D:\Playground\xcompile-arm>c:\llvm\bin\clang --version
clang version 3.5.0 (217039)
Target: i686-pc-windows-gnu
Thread model: posix

D:\Playground\xcompile-arm>c:\llvm\bin\clang.exe -target armv7-unknown-none-elf main.c
clang.exe: warning: unknown platform, assuming -mfloat-abi=soft
clang.exe: warning: unknown platform, assuming -mfloat-abi=soft
c:/mingw/bin/…/lib/gcc/mingw32/4.8.1/…/…/…/…/mingw32/bin/ld.exe: C:\Users\uidw8099\AppData\Local\Temp\main-4763a2.o: Relocations in generic ELF (EM: 40)
C:\Users\uidw8099\AppData\Local\Temp\main-4763a2.o: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
clang.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

Second: I’m not able to find which sub-arch a certain processor belongs to: For instance i have a e200z4, which sub-arch does it belong to? Can i read that from the Reference manual?

For the sys part of the triple, if i’m doing bare metal development, should i use None? What exactly does the sys part change when compiling code?

Thank you for your help

Hello again,

as it seems I made a mistake in the previous post.

I stated i was looking vor the correct ARM version but that was wrong.

The e200z4 is a PowerPC architecture, so i’m looking for the correct sub arch.

This is the error I currently get.

D:\Playground\xcompile-arm>c:\llvm\bin\clang.exe -target powerpc-unknown-none-elf main.c
Assembler messages:
Fatal error: invalid listing option `3’
clang.exe: error: assembler command failed with exit code 1 (use -v to see invocation)

Sorry for the confusion i might have caused.

You will need to have a full set of “binary tools” for ARM - or at least a linker, C/C++ library and a debugger that understands ARM.

You can almost certainly build the Clang + LLVM toolchain into something that will work for you, but you will need to do some more work than you have so far, and it may involve some interesting challenges in building tools that work on Windows…

But what I could not find is a list, link or reference to where get a
version of clang for windows which is able to cross-compile to ARM.

Hi Guilherme,

Clang+LLVM is a native cross-compiler. If the appropriate back-end is
bundled, it will produce that target's assembly or, if integrated
assembler is supported, object files. But it will not generate
executables, since we don't distribute (yet) a cross-linker, nor all
targets' libraries. You'll need to source that elsewhere.

D:\Playground\xcompile-arm>c:\llvm\bin\clang.exe -target
armv7-unknown-none-elf main.c
clang.exe: warning: unknown platform, assuming -mfloat-abi=soft
clang.exe: warning: unknown platform, assuming -mfloat-abi=soft

It seems that your binary doesn't have the ARM back-end compiled with
it. I believe we should be a lot better in specifying this, as this
error message is very misleading.

It also seems that the PowerPC back-end was not compiled with your
binary, so you'll need to either find someone that has compiled a
Windows binary that can cross-compile to PPC, or do it yourself.

By default, a standard build of LLVM builds *all* back-ends, so if you
just follow the website's "getting started" guide, you'll get all you
need in the compiler side.

But you'll still need a PPC linker, and probably some PPC static
libraries for bare-metal.

For the sys part of the triple, if i'm doing bare metal development, should
i use None? What exactly does the sys part change when compiling code?

In ARM, "none-eabi" specifies bare-metal, I don't know in PPC. Triples
have a lot of target specific idiosyncrasies, and that's older than
LLVM, so we're just following the legacy. :slight_smile:

cheers,
--renato

> But what I could not find is a list, link or reference to where get a
> version of clang for windows which is able to cross-compile to ARM.

Hi Guilherme,

Clang+LLVM is a native cross-compiler. If the appropriate back-end is
bundled, it will produce that target's assembly or, if integrated
assembler is supported, object files. But it will not generate
executables, since we don't distribute (yet) a cross-linker, nor all
targets' libraries. You'll need to source that elsewhere.

> D:\Playground\xcompile-arm>c:\llvm\bin\clang.exe -target
> armv7-unknown-none-elf main.c
> clang.exe: warning: unknown platform, assuming -mfloat-abi=soft
> clang.exe: warning: unknown platform, assuming -mfloat-abi=soft

It seems that your binary doesn't have the ARM back-end compiled with
it. I believe we should be a lot better in specifying this, as this
error message is very misleading.

It also seems that the PowerPC back-end was not compiled with your
binary, so you'll need to either find someone that has compiled a
Windows binary that can cross-compile to PPC, or do it yourself.

By default, a standard build of LLVM builds *all* back-ends, so if you
just follow the website's "getting started" guide, you'll get all you
need in the compiler side.

So it seems that the provided binary on the llvm site does not have *all*
the backends. I get following error when trying to create an object file.

D:\Playground\xcompile-arm>c:\llvm\bin\clang.exe -target
powerpc-unknown-none-eabi -c main.c
Assembler messages:
Fatal error: invalid listing option `3'
clang.exe: error: assembler command failed with exit code 1 (use -v to see
invocation)

But you'll still need a PPC linker, and probably some PPC static
libraries for bare-metal.

> For the sys part of the triple, if i'm doing bare metal development,
should
> i use None? What exactly does the sys part change when compiling code?

In ARM, "none-eabi" specifies bare-metal, I don't know in PPC. Triples
have a lot of target specific idiosyncrasies, and that's older than
LLVM, so we're just following the legacy. :slight_smile:

cheers,
--renato

How do i find out what the proper triple is? Can somebody help me?

To be honest, unless you have a PPC assembler somewhere and clang's
driver was smart enough to find it, this looks like you're invoking
the host assembler...

Again, horrible error messages... :frowning:

Do you have PPC tools and libraries? The triple shouldn't matter that
much, at least not until you get some executables and try to run them,
but we're not there yet.

cheers,
--renato

There are binary releases of ELLCC that run on Windows and contain ecc (the clang/LLVM based C/C++ compiler), binutils and GDB, and precompiled libraries for the PPC (and ARM, Mips, Microblaze, and x86). There isn't much support for bare metal PPC yet, so you'd have to do some work to get a bare metal program off the ground.
Link to the download page: http://ellcc.org/blog/?page_id=20295

Download either ellcc-i386-w64-mingw32-*.tgz or ellcc-x86_64-w64-mingw32-*.tgz depending on whether you want 32 or 64 bit windows executables.

-Rich