Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complete and isolated LLVM/musl toolchain

What I'm trying to achieve is to compile an GNU independent and isolated LLVM toolchain using musl as clib.

Recently LLVM 4.0 has been released with lot's of new cool features, including production ready LLD, so also the linking step could be handled by LLVM.

More or less the stack is:

  • clang
  • llvm
  • lld
  • compiler-rt
  • libcxx
  • libcxxabi
  • musl

Following this, it is actually possible to do so without much patching or such (apart from compiling musl), but sadly, there is no good documentation about that.

Any suggestions?

like image 739
Stefano Azzalini Avatar asked Mar 21 '17 06:03

Stefano Azzalini


People also ask

Is it possible to compile LLVM toolchain using musl as Clib?

What I'm trying to achieve is to compile an GNU independent and isolated LLVM toolchain using musl as clib. Recently LLVM 4.0 has been released with lot's of new cool features, including production ready LLD, so also the linking step could be handled by LLVM.

How do I use LLVM with Clang?

LLVM’s compiler runtime library provides a complete set of runtime library functions containing all functions that Clang will implicitly call, in libclang_rt.builtins.<arch>.a. You can instruct Clang to use compiler-rt with the --rtlib=compiler-rt flag.

Is it possible to use LLVM for LLD linking?

Recently LLVM 4.0 has been released with lot's of new cool features, including production ready LLD, so also the linking step could be handled by LLVM. Following this, it is actually possible to do so without much patching or such (apart from compiling musl ), but sadly, there is no good documentation about that. Any suggestions?

What tools are required to assemble a complete toolchain?

In order to assemble a complete toolchain, additional tools and runtime libraries are required. Clang is designed to interoperate with existing tools and libraries for its target platforms, and the LLVM project provides alternatives for a number of these components.


2 Answers

I was solving the same problem with my NGTC (Non-GNU toolchain) project. Please take a look at my build scripts and patches.

I used this toolchain to build a small Linux distro without any code from GNU project: nenuzhnix.

like image 55
CYB3R Avatar answered Sep 30 '22 03:09

CYB3R


There is an example of using Clang + Musl together to compile "Hello World" in C here: https://github.com/njlr/portable-cxx

It only requires wget, tar and make to be installed. Clang and Musl are downloaded as part of the build process.

The key is to disable the usual include paths using -nostdinc and then add the Musl ones using -isystem.

like image 40
sdgfsdh Avatar answered Sep 30 '22 04:09

sdgfsdh