Skip to content

Evolutionary-Networking-Designs/CMLFS

 
 

Repository files navigation

CMLFS - Clang Musl Linux From Scratch

CMLFS can either mean "Clang-built Musl Linux from Scratch" or "Clang MLFS". It started as a hobby to see if a Linux system can be built with clang as primary toolchain and GCC as secondary (for packages that cannot be built with clang). This is based on Linux From Scratch (www.linuxfromscratch.org) and my previous work MLFS (https://github.com/dslm4515/Musl-LFS).

Specification

  • C Runtime Library (system libc): Musl
  • Default C Compiler: clang (LLVM)
  • Default C++ compiler: clang++ (LLVM)
  • Default linker: lld (LLVM)
  • Default binary tools: (LLVM)
  • Secondary C Compiler: GCC
  • Secondary C++ compiler: GCC
  • Secondary binary tools: GNU Binutils
  • Secondary linker(s): bfd, gold
  • C++ standard library: libcxx (LLVM)
  • C++ ABI library: libcxxabi (LLVM)
  • Unwinding Library: libunwind (LLVM)
  • Init system: skarnet's S6 & S6-rc
  • Device manager: Udev
  • TLS Implementaion: LibreSSL
  • System Shell: Bash
  • System Gettext: gettext-tiny

Supported Architectures

  • AMD64/x86_64: Toolchains and final system build sucessfully (musl & glibc hosts) .
  • i686: Pending
  • AARCH64/ARM64: Pending
  • ARMV7L: Pending

Goals

  • Build a toolchain (llvmtools) with LLVM+stage1_clang but without GCC
  • Build final root filesystem with LLVM
  • Set default linker as lld(LLVM)
  • Set default C++ standard library as libcxx(LLVM)
  • Set default C++ ABI library as libcxxabi(LLVM)
  • Set default stack unwinding library as libunwind(LLVM)
  • Eliminate dependacy on GCC's libgcc_s
  • Build GCC as a secondary systen compiler.
  • Build toolchain (llvmtools) with GCC as secondary compiler
  • Merge cross-tools build with cgnutools
  • Build successfully on a Glibc host
  • Reduce LLVM size & build time for cgnutools and llvmtools
  • Build on aarch64

Host System Requirements

  • CMake
  • Ninja/Samurai
  • wget/cURL

Required Base Development tools (may refer to LFS)

  • bash 3.2 (/bin/sh should be a symbolic or hard link to bash)
  • binutils 2.25
  • bison 2.7 (/usr/bin/yacc should be a link to bison or small script that executes bison)
  • bzip2 1.0.4
  • coreutils 6.9
  • diffutils 2.8.1
  • findutils 4.2.31
  • gawk 4.0.1 (/usr/bin/awk should be a link to gawk)
  • GCC 6.2 *including the C++ compiler, g++
  • Glibc 2.11 / Musl Libc 1.20
  • Grep 2.5.1a
  • gzip 1.3.12
  • linux kernel 3.2 (not sure if it matters, as most distros are running 4.x/5.x kernels
  • m4 1.4.10
  • make 4.0
  • patch 2.5.4
  • Python 3.4
  • sed 4.1.5
  • tar 1.22
  • texinfo 4.7
  • xz 5.0.0
* (if hostdistro is MLFS/LFS, then all development packages are installed)

Current Method

Build or use 'cross-tools' from Musl-LFS to cross-compile stage0 clang. This stage0 clang will still link to libgcc_s but will later be used to build a stage1 clang free of libbgcc_s. The goal is to build clang+friends with clang and not GCC.

  1. Build `cgnutools` with host's GCC
  2. Build a stage0 clang with GCC libraries with `cgnutools`: build clang via llvm source with clang+lld unpacked in `llvm/tools` and libunwind, libcxxabi & libcxx in `lvm/projects`.
  3. Build individually in LLVM source tree libunwind, libcxxabi and libcxx with stage0 clang and install in `llvmtools`.
  4. Build a new stage1 clang with stage0 clang. This new stage1 clang will not have GCC libraries. This will install in `llvmtools`.
  5. Using stage1 clang, build toolchain (llvmtools) for use in chroot
  6. Build final root filesystem in chroot with stage1 clang and toolchain (llvmtools)

Issues

  • Clang requires `execinfo.h` - Added libexecinfo to build
  • Diskboot.img of grub is not correctly built with clang. Grub requires GCC and patching.
  • Cannot build cgnutools with host's LLVM/Clang. Has to be complied with Host's GCC or previously built cross-tools toolchain.

Change log

  • 2.0.0: Upgraded to LLVM-12.0.0. Upgraded GCC to 10.3.1-x Replace ninja with samurai. Replace zlib with zlib-ng. Patched elfutils to build libelf under clang. No longer using /llvmtools/gnu and /opt/gnu.
  • 1.2.0: Incomplete: LLVM=11.0.0, Install GCC & Binutils in /llvmtools & /usr instead of /llvmtools/gnu and /opt/gnu
  • 1.1.0: Sucessfully merged cross-tools and cgnutools to include GCC & binutils.
  • 1.0.0: Sucessfully built on x86_64. GCC built as secondary compiler in /opt/gnu
  • 0.1.3: Configure Stage1 clang correctly with x86_64-pc-linux-musl.cfg.
  • 0.1.2: Use stage0 to build a stage1 clang...Stage1 clang will be used in chroot. Stage1 clang fails to compile
  • 0.1.1: Build stage0 clang by building clang, lld, compiler-rt, libunwind, libcxxabi, libcxx together in llvm source tree. Stage0 builds binaries with host's dynamic linker in /lib
  • 0.1.0: Build cross-tools with GCC to build stage 1 clang... first build libunwind, libcxxabi & libcxx - stage1 Clang broken
  • 0.0.0: First attempt, modeled afer Genshen's repo: Stage 2 clang fails to build.

Projects of Interest

About

Clang-Built Musl Linux From Scratch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 54.0%
  • C 42.4%
  • Roff 3.5%
  • Vim Script 0.1%