[llvm-dev] Building an LLVM cross-compiler

Chris Bieneman via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 6 14:38:02 PST 2020


You’ve hit on one of the odd historical messes in LLVM. Compiler-RT can’t really be treated as a monolithic set of libraries when you are bootstrapping. In order to even configure the LLVM sanitizer runtimes you need libc and many other OS interfaces, so when bootstrapping you need to build the compiler-rt builtins library separately from the sanitizers.

This can be done either by using the `LLVM_ENABLE_RUNTIMES` CMake option (see DistributionExample-stage2.cmake in clang/cmake/caches), or by treating compiler-rt/lib/builtins as the top-level CMake file.

I would strongly suggest that you start with one of the CMake cache files under clang/cmake/caches as an example because setting up the CMake options to build a toolchain that can cross-compile is sadly quite complicated.

-Chris

> On Nov 6, 2020, at 4:13 PM, Cág via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> 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
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list