[llvm-dev] Building an LLVM cross-compiler

Cág via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 6 14:12:55 PST 2020


Hi everyone,

I recently sent a message that may or may not have made it to the list,
on problems building an LLVM cross-compiler.  Now the issue seems clear
to me and is irrelevant at this point, I would like to discuss the general
issue.

Suppose you have a host system, a Linux distribution on an x86_64 machine,
and want to build a cross-compiler for aarch64 (or any platform supported
by LLVM, other than an AMD-/Intel-based machine) to cross compile a Linux
distribution.

The process, in my opinion, should go like this:
1. Get the sources (llvm, lld, compiler-rt, libunwind, libcxx...).
2. Build an LLVM cross-compiler toolchain using native distribution's
compiler (i.e. build an x86_64 clang executable that targets aarch64).
3. Cross-compile libc and other libraries/dependencies to run the
userland.
4. Cross-compile the userland.

With LLVM it doesn't work:
1. You got the sources.
2. Built clang targetting, among others or only, aarch64/mips/etc.
3. Clang requires compiler-rt but you need to cross-compile compiler-rt
for the target platform. *You don't have a cross-compiler*.

It stops after that.  To build compiler-rt you need C headers, libc
runtimes, *and libclang_rt.a*.  You can't cross-compile libc because you
don't have compiler-rt because you don't have libc.  Chicken or egg.

I.e. you need a cross-compiler to build a cross-compiler.

So, how do you build an LLVM-based cross-compiler?

I hope I am wrong in my assumptions and if it's so, please forgive me.
I also hope I made it clear.

Thanks for taking time and have a nice weekend!

-- 
caóc


More information about the llvm-dev mailing list