[llvm-dev] Building an LLVM cross-compiler

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 10 23:18:38 PST 2020


You could try using zig for this. Here's an example build script of zig 
cross compiling llvm, lld, clang, and finally itself:

https://github.com/ziglang/zig-bootstrap

You can see the build script is not too complicated. The main trick is 
using CC and CXX to use `zig cc` and `zig c++` as drop-in replacements 
for a C and C++ compiler, respectively.

I wrote some more details about this here:
https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html

On 11/6/20 3:12 PM, Cág via llvm-dev 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!
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x7C5F548F728501A9.asc
Type: application/pgp-keys
Size: 3127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201111/bc642273/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201111/bc642273/attachment.sig>


More information about the llvm-dev mailing list