Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/dslm4515/CMLFS

Clang-Built Musl Linux From Scratch
https://github.com/dslm4515/CMLFS

clang lfs llvm musl musl-libc

Last synced: 5 days ago
JSON representation

Clang-Built Musl Linux From Scratch

Lists

README

        

# 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). Big thanks to [Chimera-Linux](https://chimera-linux.org) that had patches that fixed a lot of issues.

## DISCLAIMER

Use at you own risk. This builds a Unix-like system that may not be stable enough as a 'daily driver' for most users. Security-hardening of the built system is beyound the scope of this project. This repo started as means to backup and archive my work.

## Getting Started

The master branch may be unstable when I am working on upgrading CMLFS.

To build this project, pick a branch other than master OR choose a tag. Each branch & tag are based on the LLVM version.
As of this writing, llvm-15.0.6 is stable. Older branches maybe incomplete or unstable (may not compile).

When I have time later, I will write a more thorough introduction for users new to CMLFS.

## Specification


  • C Runtime Library (system libc): Musl

  • Default C Compiler: clang (LLVM)

  • Default C++ compiler: clang++ (LLVM)

  • Default linker: lld (LLVM)

  • Default binary tools: elftoolchain

  • Secondary C Compiler: GCC

  • Secondary C++ compiler: GCC

  • Secondary binary tools: GNU Binutils & LLVM

  • 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

  • Secondary TLS Implementaion: OpenSSL

  • System Shell: Bash

  • System Gettext: gettext-tiny

  • Curses Library: netbsd-curses

## Supported Architectures


  • AMD64/x86_64: Toolchains and final system build sucessfully (musl & glibc hosts) .

  • i686: Pending

  • AARCH64/ARM64: Pending

  • ARMV7L: Pending

## Goals


  • [x] Build a toolchain (llvmtools) with LLVM+stage1_clang but without GCC

  • [x] Build final root filesystem with LLVM

  • [x] Set default linker as lld(LLVM)

  • [x] Set default C++ standard library as libcxx(LLVM)

  • [x] Set default C++ ABI library as libcxxabi(LLVM)

  • [x] Set default stack unwinding library as libunwind(LLVM)

  • [x] Eliminate dependacy on GCC's libgcc_s

  • [x] Build GCC as a secondary systen compiler.

  • [x] Build toolchain (llvmtools) with GCC as secondary compiler

  • [x] Merge cross-tools build with cgnutools

  • [x] Build successfully on a Glibc host

  • [x] Build final system without GCC

  • [x] Replace binutils with elftoolchain

  • [ ] Reduce LLVM size & build time for cgnutools and llvmtools

  • [ ] Create initramfs with busybox & mdev

  • [ ] 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 'cross-tools' with [Mussel](https://github.com/firasuke/mussel) to cross-compile a stage0 LLVM+clang. This stage0 clang will still link to `libgcc_s` [in cgnutools] 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.

* Some packages can be built once to be used by the toolchain [llvmtools] and the final system, but will be built twice to make it easy to implement a package managment system [which is outside the scope of this project].


  1. Bootstrap build of cgnutools with mussel

  2. Use mussel-built toolchain (cgnutools) to build stage0 LLVM+clang

  3. Use cgnutools to build stage1 LLVM+clang with sysroot at llvmtools with stage0 LLVM+clang

  4. Build enough of llvmtools to enter a chroot with stage1 LLVM+clang

  5. Build the rest of llvmtools under chroot

  6. Build final system with llvmtools

## Issues


  • Test for C++11/14 fails when testing stage0 & stage1 LLVM's. Not sure what issue this will cause or if test needs to be revised..

  • Coreutils will not build for llvmtools under 32-bit x86 (i386/i586/i686)

  • Ninja for llvmtools fails to compile with python3. For now use cmake instead of python3

## Change log


  • 4.0.0: Upgraded to LLVM 17.0.5

  • 3.0.0: Upgraded to LLVM-15.0.6. cgnutools is now bootstrapped with mussel. Replaced binutils with elftoolchain. Most of llvmtools will be build under chroot to avoid contamination from host.

  • 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


  • [Mussel](https://github.com/firasuke/mussel)

  • [Musl Linux From Scratch](https://github.com/dslm4515/Musl-LFS) - Based on LFS, but uses Musl instead of Glibc

  • [Beyond MLFS](https://github.com/dslm4515/BMLFS) - The Musl version of LFS's BLFS

  • [MLFS-S6-Bootscripts](https://github.com/dslm4515/MLFS-S6-Bootscripts) - Boot scripts for CMLFS/MLFS/LFS using skarnet's S6+S6-rc init system

  • [MLFS-Pkgtool](https://github.com/dslm4515/MLFS-pkgtool) - Musl LFS with Slackware's pkgtools

  • [Genshen's docker-clang-toolchain](https://github.com/genshen/docker-clang-toolchain)

  • [Build a freestanding libc++](https://blogs.gentoo.org/gsoc2016-native-clang/2016/05/05/build-a-freestanding-libcxx/)