Cross-compiling the ARM toolchain

Hello,

Is there a quick tutorial to build the LLVM toolchain from a Linux or
Mac OS X x86 host for an ARM v4/v5/v6 ELF target?
It this configuration supported, and is it possible to build the Clang
compiler for this host/target combination?

I know about the installation page, but I keep failing to build this
toolchain with LLVM 2.7. Maybe it is not (yet) supported?

Thanks,
Manu

trying this:
clang -march=armv7-a -mcpu=cortex-a9 -ccc-host-triple
arm-none-linux -ccc-gcc-name arm-none-linux-gnueabi-gcc a.c

Hi Liu,

That doesn't work for me.

$ clang -march=armv7-a -mcpu=cortex-a9 -ccc-host-triple arm-none-linux
-ccc-gcc-name arm-none-linux-gnueabi-gcc alias.c
clang: warning: unknown platform, assuming -mfloat-abi=soft
/tmp/cc-0BIpHn.s: Assembler messages:
/tmp/cc-0BIpHn.s:1: Error: unknown pseudo-op: `.syntax'
/tmp/cc-0BIpHn.s:2: Error: unknown pseudo-op: `.cpu'
/tmp/cc-0BIpHn.s:3: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:4: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:5: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:6: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:7: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:8: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/cc-0BIpHn.s:15: Error: no such instruction: `bx lr'
clang: error: assembler command failed with exit code 1 (use -v to see
invocation)

The assembly is fine, but ARM's ELF writer is not, if it's even
getting that far. MC doesn't have ELF yet (right?) and the old ARM ELF
writer had lots of problems, especially on EABI conformity, but that
ASM is pure GNU, so I don't know what's wrong with it.

If you generate assembly and pipe it to GAS then link manually, it
works, but that's far from ideal. I think the long term solution would
be to implement the MC ELF writer for ARM, but you won't get that in
the 2.8.

I'd be curious what this says the invocation for your assembler is - it should be a bug that it's not calling the right assembler if you passed it the right information. What's your arm assembler named?

-eric

Good point. I thought -ccc-gcc-name would guess the assembler from
what I passed, but running with -v I see it's using /usr/bin/as ...

What is the option to tell it to use a specific assembler?
-ccc-as-name or -cc-gas-name?

There isn't one at the moment, ideally it should figure it out, but I haven't looked much into it - it may be that this isn't working yet.

-eric

There isn't one at the moment, ideally it should figure it out, but I haven't looked much into it - it may be that this isn't working yet.

I should say that I'm still a bit confused: Is it possible to build
for ARM CPUs now?
  1/ from which hosts (x86-*-* ?)
  2/ for which targets (arm-*-* ?)
  3/ what are the supported tools for ARM targets:
      a/ llvm-gcc (gcc 4.2)?
      b/ dragonegg (gcc 4.5)?
      c/ clang?

Thanks,
Manu

Maybe I'm misunderstanding your question, but clang/llvm is different from gcc in that all targets are built in. There's no building a specific target version, like you have to do for binutils/gcc.

clang -march=armv7-a -mcpu=cortex-a9 -ccc-host-triple
arm-none-linux -ccc-gcc-name arm-none-linux-gnueabi-gcc a.c

replace tripe with yours

I should say that I'm still a bit confused: Is it possible to build
for ARM CPUs now?

Yes!

1/ from which hosts (x86-*-* ?)

AFAIK, all all supported platforms (x86, x86_64, etc)

2/ for which targets (arm-*-* ?)

Virtually all. As far as I could test, all major architectures
(v4/v5/v6 + v7-A-R-M), although I'm still fighting with some Thumb
code generation. Could be my old gcc/binutils version (that still
doesn't even recognizes cortex-R4). You should check that yours is
really new (at least 2010) if you want v7R support.

3/ what are the supported tools for ARM targets:
a/ llvm-gcc (gcc 4.2)?
b/ dragonegg (gcc 4.5)?
c/ clang?

I haven't tested dragonegg, but clang and llvm-gcc do the job.
llvm-gcc seems to be more in sync with the ARM backend (for obvious
reasons), but it's a nightmare to compile it to the ARM backend. Clang
supports it out of the box.

Please, do have in mind that the code generated is by no means
super-optimized for each specific platform. There are some selected
features (mostly cortex-A*), but most of the code is generic to the
architecture or falls back to v4. So, if you're looking for great
optimizations GCC does for your specific SoC, you might not find it in
LLVM yet.

Virtually all. As far as I could test, all major architectures
(v4/v5/v6 + v7-A-R-M), although I'm still fighting with some Thumb
code generation.

Not a big issue for me: targets are ARMv4 (ARM7) and ARMv5 (ARM9)
"classic" CPUs - in ARM terminology. No cortex.

I haven't tested dragonegg, but clang and llvm-gcc do the job.
llvm-gcc seems to be more in sync with the ARM backend (for obvious
reasons), but it's a nightmare to compile it to the ARM backend. Clang
supports it out of the box.

I've been able to build clang + llvm from the SVN repository.

However my targets (arm-eabi) are relying on the "newlib" standard
library. I'm not sure how to build the llvm-gcc backend so that it
uses this library.
I'm used to build GCC (4.x) toolchains with newlib, but how can I do
the same with llvm-gcc ?
It seems that clang attemps to find the header files from the host
system dir, not from the target system dir, so I guess that I missed
an important option ... somewhere.

I've replaced the "arm-eabi-gcc" calls from my Makefiles with "clang
-ccc-host-triple arm-eabi -ccc-gcc-name arm-eabi-gcc" but clang
probably needs some other options (?)

Thanks,
Emmanuel.

Hello, Emmanuel

I'm used to build GCC (4.x) toolchains with newlib, but how can I do
the same with llvm-gcc ?

Pretty much same way as with gcc. E.g. via --with-newlib, etc.

It seems that clang attemps to find the header files from the host
system dir, not from the target system dir, so I guess that I missed
an important option ... somewhere.

clang is not pretty well suitable from cross-compilation. You can find
several issues on the way.

I'm used to build GCC (4.x) toolchains with newlib, but how can I do
the same with llvm-gcc ?

Pretty much same way as with gcc. E.g. via --with-newlib, etc.

I successfully built llvm+clang, but it seems that the newlib library
files have neither been compiled nor installed.

With GCC (at the time 4.5.2), the build steps are straightforward:
newlib/ and libgloss/ directories should be copied/linked to the top
level directory of the GCC source directory, and the --with-newlib
option switch enabled as a 'configure' parameter.
The library gets built along with GCC, and installed into the GCC
destination folders (libc.a, libm.a, ... as well as the header files)

Is there some specific commands/option switches to build the newlib
library files with llvm+clang ?

Thanks,
Emmanuel

Is there some specific commands/option switches to build the newlib
library files with llvm+clang ?

No.

Is there some specific commands/option switches to build the newlib
library files with llvm+clang ?

No.

Did anyone succeed in building such a toolchain (for arm-eabi)?

Are clang+llvm supposed to build libc/libm libraries, or should I
first build these libraries with a regular GCC and somehow copy them
into the clang+llvm destination folder?

Thanks,
Emmanuel.