[llvm-dev] Trying to create a pure LLVM toolchain on musl based distribution

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 25 13:24:44 PDT 2019


On 3/25/19 8:52 AM, David Demelier via llvm-dev wrote:
> Hello,
> 
> I'm trying to create a pure LLVM toolchain (that will not depend on GNU
> and produce GNU-free code too) on a musl based distribution.
> 
> # LLVM
> # compiler-rt
> # libc++
> # libc++abi
> # libunwind
> # clang

David,

You may be interested to know that Zig (https://ziglang.org/) ships with
such a toolchain already. It cross compiles components (musl, libunwind,
etc) for the target lazily from source, and supports these libc targets:

  aarch64_be-linux-gnu
  aarch64_be-linux-musl
  aarch64-linux-gnu
  aarch64-linux-musleabi
  armeb-linux-gnueabi
  armeb-linux-gnueabihf
  armeb-linux-musleabi
  armeb-linux-musleabihf
  arm-linux-gnueabi
  arm-linux-gnueabihf
  arm-linux-musleabi
  arm-linux-musleabihf
  i386-linux-gnu
  i386-linux-musl
  mips64el-linux-gnuabi64
  mips64el-linux-gnuabin32
  mips64el-linux-musl
  mips64-linux-gnuabi64
  mips64-linux-gnuabin32
  mips64-linux-musl
  mipsel-linux-gnu
  mipsel-linux-musl
  mips-linux-gnu
  mips-linux-musl
  powerpc64le-linux-gnu
  powerpc64le-linux-musl
  powerpc64-linux-gnu
  powerpc64-linux-musl
  powerpc-linux-gnu
  powerpc-linux-musl
  riscv32-linux-musl
  riscv64-linux-gnu
  riscv64-linux-musl
  s390x-linux-gnu
  s390x-linux-musl
  sparc-linux-gnu
  sparcv9-linux-gnu
  x86_64-linux-gnu
  x86_64-linux-gnux32
  x86_64-linux-musl

Here's an example of using Zig to compile hello-world.c for
aarch64-linux-gnu:

andy at xps ~/m/z/hello> cat hello.c
#include <stdio.h>

int main(int argc, char **argv) {
    printf("what up dawg\n");
    return 0;
}
andy at xps ~/m/z/hello> zig build-exe --c-source hello.c --library c
-target aarch64v8-linux-gnu
andy at xps ~/m/z/hello> file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV),
dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for
GNU/Linux 2.0.0, with debug_info, not stripped

And now for x86_64-linux-musl:

andy at xps ~/m/z/hello> zig build-exe --c-source hello.c --library c
-target x86_64-linux-musl
andy at xps ~/m/z/hello> ./hello
what up dawg
andy at xps ~/m/z/hello> ldd ./hello
	not a dynamic executable

This works on any OS including Windows and macOS since it has no system
dependencies.

This feature is new and not well tested yet, but if it piques your
interest, you can play with this functionality using pre-built binaries
available on https://ziglang.org/download/ or you can build Zig master
branch from source.

Regards,
Andrew

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190325/64be6724/attachment.sig>


More information about the llvm-dev mailing list