SlideShare a Scribd company logo
1 of 25
Download to read offline
2023/02/03 Chimera Linux @ FOSDEM 2024 1
Building a Linux distro with LLVM
2023/02/03 Chimera Linux @ FOSDEM 2024 2
Introduction
●
General-purpose Linux distribution
●
Particular focus on desktop/workstations
●
Robustness, security hardening, good defaults
●
Lightweight and transparent
●
Pragmatic and versatile
2023/02/03 Chimera Linux @ FOSDEM 2024 3
Overview
●
LLVM as system toolchain
●
FreeBSD as core userland
●
Musl as libc
●
Apk-tools as package manager
●
Binary packaging, clean source build infra
2023/02/03 Chimera Linux @ FOSDEM 2024 4
Overview
●
Bootstrappable
●
Can cross-compile (official repos are native)
●
Supports many architectures:
– Aarch64, ppc64le, ppc64, riscv64, x86_64
●
System-wide LTO, UBSan, CFI, ...
2023/02/03 Chimera Linux @ FOSDEM 2024 5
Getting started
●
Early 2021
●
Cbuild: source package build system
●
Template: describes one individual piece of software
●
Host system: Void Linux, architecture: ppc64le
●
Sandbox: runs its own build environment
2023/02/03 Chimera Linux @ FOSDEM 2024 6
Bootstrap process
●
4 stages
●
Stage 0: use outside toolchain
●
Stage 1: use packages from stage 0 (containerized)
●
Stage 2: enable LTO and remaining build options
●
Stage 3: clean rebuild (with stage 2 packages)
2023/02/03 Chimera Linux @ FOSDEM 2024 7
Build environment
●
Bare minimum packages needed to build self
●
Libc, compiler, core userland, package manager
●
Build dependencies for software being packaged
●
Overall a small Chimera container
●
Running unprivileged (Linux user namespaces)
2023/02/03 Chimera Linux @ FOSDEM 2024 8
Why use LLVM?
●
More modern compiler design
●
Security: state of the art sanitizers (e.g. CFI)
●
Easier to build and bootstrap, simpler cross-build
●
Thin LTO, better performance
●
Often less buggy
2023/02/03 Chimera Linux @ FOSDEM 2024 9
Why not use LLVM?
●
Very occasionally worse compatibility
●
Fewer architectures supported
●
Some of the supported ones are less maintained
●
Takes longer to build (bigger, idiomatic C++)
●
Very rarely worse performance
2023/02/03 Chimera Linux @ FOSDEM 2024 10
Toolchain structure: typical
●
A C library (usually glibc or musl)
●
GNU Binutils: assembler, linker, ELF utilities
●
GCC: C/C++ compiler, core runtime (crt+libgcc), C++
standard library, possibly other languages
●
One build of binutils+gcc per target
2023/02/03 Chimera Linux @ FOSDEM 2024 11
Userland ABI: typical
●
Part statically linked – builtins (libgcc.a), early crt
●
Unwinder + dynamic builtins: libgcc_s.so.1
●
C++ standard library: libstdc++.so.6
●
Base C++ ABI: libstdc++.so.6 or libsupc++
●
CRT is part libc, part GCC
2023/02/03 Chimera Linux @ FOSDEM 2024 12
Toolchain structure: LLVM
●
LLVM: compiler, linker, assembler, binutils, all-in-one
●
The only separate component is libc (glibc/musl)
●
One compiler for all native and cross targets
●
Only the runtime and target libraries are per-target
●
Simplified bringup
2023/02/03 Chimera Linux @ FOSDEM 2024 13
Userland ABI: native LLVM
●
Not used in most distros (LLVM uses GCC’s env)
●
Builtins are static (libclang_rt.builtins.a) - compiler_rt
●
Unwinder: libunwind.so.1
●
C++ library and base ABI: libc++.so.1, libc++abi.so.1
●
Standalone (no GCC dependency)
2023/02/03 Chimera Linux @ FOSDEM 2024 14
ABI compatibility
●
Libunwind ABI matches most of libgcc_s
●
Builtins can be compiled into a makeshift libgcc_s
●
Libc++ stdlib ABI is different (won’t run GCC programs)
●
However, libc++ and libstdc++ can live in one process
– In theory (need libstdc++ using libc++’s ABI library)
2023/02/03 Chimera Linux @ FOSDEM 2024 15
Choosing a libc
●
Glibc: could not build with Clang until recently
– Still incompatible with native LLVM: dlopens libgcc_s.so.1
●
Musl: builds and just works as-is
●
There are others but generally domain-specific (e.g.
embedded) or somehow worse than the other two
2023/02/03 Chimera Linux @ FOSDEM 2024 16
The allocator
●
LLVM comes with yet another thing: Scudo
●
The memory allocator used in Android, hardened
●
Modular design: can mix and match components,
configure them, or even provide custom ones
●
Very unassuming (no mandatory ELF TLS, etc.)
2023/02/03 Chimera Linux @ FOSDEM 2024 17
The allocator
●
Musl allocator: bad performance in threaded programs
●
Replaced with Scudo: e.g. 3x faster lld LTO link perf
●
No ELF TLS within libc: custom TSD registry
– Plugs directly into the pthread structure, manual mmap
●
Unfortunately very high virt mem usage :(
2023/02/03 Chimera Linux @ FOSDEM 2024 18
Cross-compilation
●
Cbuild can cross-compile
●
Cross targets need cross runtimes
●
Includes compiler-rt, musl, libunwind, libc++(abi)
●
Slightly tricky bootstrap
●
Installed into sysroot
2023/02/03 Chimera Linux @ FOSDEM 2024 19
Bootstrapping cross runtimes
●
Build compiler-rt builtins+crtbegin/end first
– Force static libs (avoid conftests) and disable sanitizers
– Requires libc headers, so give it some (musl in temp place)
●
Build and install libc (needs only the above)
●
Build and install libunwind and libc++(abi)
2023/02/03 Chimera Linux @ FOSDEM 2024 20
Bootstrapping cross runtimes
●
Libunwind and libc++ can (should) be done all at once
– Still needs explicit -nostdlib in CXXFLAGS (don’t have one)
●
Now compile the rest of compiler-rt
– This is mainly sanitizers
●
Once in sysroot, this is the full cross runtime
2023/02/03 Chimera Linux @ FOSDEM 2024 21
Practical experiences
●
Makes system-wide LTO possible
– Far lower resource usage and near universal compatibility
●
Security hardening
– We deploy a subset of UBSan (signed overflows are
crashes...)
– Partial CFI; breaks too many projects to deploy universally
2023/02/03 Chimera Linux @ FOSDEM 2024 22
Practical experiences
●
Toolchain patching is in line with GCC
– Still heavier than I would like… (~30 patches)
●
On Linux, often geared towards GCC-style environment
– Upstream should consider dogfooding more
●
The build system can be an impenetrable mess
2023/02/03 Chimera Linux @ FOSDEM 2024 23
Practical experiences
●
Major release updates can be daunting
– Every release breaks some third party software
– Usually for a good reason (legacy C misfeatures…)
– Still causes an unfortunate amount of fallout
●
Community is good and helpful
2023/02/03 Chimera Linux @ FOSDEM 2024 24
Conclusion
●
Generally a great toolchain
●
Some pain points, but generally practical
●
Can build just about any Linux software
– Given GCC’s history, an amazing feat
●
Should not be reduced to “that GCC drop-in”
2023/02/03 Chimera Linux @ FOSDEM 2024 25
Thanks for listening!
●
https://chimera-linux.org
●
https://github.com/chimera-linux
●
https://floss.social/@chimera_linux
●
#chimera-linux @ OFTC (irc.oftc.net)
●
#chimera-linux:matrix.org

More Related Content

Similar to Building a Linux distro with LLVM

Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois TigeotPorting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeoteurobsdcon
 
Rootless Containers
Rootless ContainersRootless Containers
Rootless ContainersAkihiro Suda
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkAnne Nicolas
 
Introducing Container Technology to TSUBAME3.0 Supercomputer
Introducing Container Technology to TSUBAME3.0 SupercomputerIntroducing Container Technology to TSUBAME3.0 Supercomputer
Introducing Container Technology to TSUBAME3.0 SupercomputerAkihiro Nomura
 
Leveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IVLeveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IVOpersys inc.
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMSherif Mousa
 
The internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesThe internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesAkihiro Suda
 
Bsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessionsBsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessionsScott Tsai
 
Linuxcon Barcelon 2012: LXC Best Practices
Linuxcon Barcelon 2012: LXC Best PracticesLinuxcon Barcelon 2012: LXC Best Practices
Linuxcon Barcelon 2012: LXC Best Practiceschristophm
 
Security of Linux containers in the cloud
Security of Linux containers in the cloudSecurity of Linux containers in the cloud
Security of Linux containers in the cloudDobrica Pavlinušić
 
Android Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and ResourcesAndroid Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and ResourcesOpersys inc.
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Jérôme Petazzoni
 
Navigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariMetosin Oy
 
Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Opersys inc.
 
The State of Rootless Containers
The State of Rootless ContainersThe State of Rootless Containers
The State of Rootless ContainersAkihiro Suda
 
Comparing Next-Generation Container Image Building Tools
 Comparing Next-Generation Container Image Building Tools Comparing Next-Generation Container Image Building Tools
Comparing Next-Generation Container Image Building ToolsAkihiro Suda
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded LinuxTushar B Kute
 
LibCT: one lib to rule them all -- Andrey Vagin
LibCT: one lib to rule them all -- Andrey VaginLibCT: one lib to rule them all -- Andrey Vagin
LibCT: one lib to rule them all -- Andrey VaginOpenVZ
 

Similar to Building a Linux distro with LLVM (20)

Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois TigeotPorting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
 
Rootless Containers
Rootless ContainersRootless Containers
Rootless Containers
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
Armbian linux
Armbian linuxArmbian linux
Armbian linux
 
Exploring Docker Security
Exploring Docker SecurityExploring Docker Security
Exploring Docker Security
 
Introducing Container Technology to TSUBAME3.0 Supercomputer
Introducing Container Technology to TSUBAME3.0 SupercomputerIntroducing Container Technology to TSUBAME3.0 Supercomputer
Introducing Container Technology to TSUBAME3.0 Supercomputer
 
Leveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IVLeveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IV
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
The internals and the latest trends of container runtimes
The internals and the latest trends of container runtimesThe internals and the latest trends of container runtimes
The internals and the latest trends of container runtimes
 
Bsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessionsBsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessions
 
Linuxcon Barcelon 2012: LXC Best Practices
Linuxcon Barcelon 2012: LXC Best PracticesLinuxcon Barcelon 2012: LXC Best Practices
Linuxcon Barcelon 2012: LXC Best Practices
 
Security of Linux containers in the cloud
Security of Linux containers in the cloudSecurity of Linux containers in the cloud
Security of Linux containers in the cloud
 
Android Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and ResourcesAndroid Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and Resources
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!
 
Navigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
 
Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3
 
The State of Rootless Containers
The State of Rootless ContainersThe State of Rootless Containers
The State of Rootless Containers
 
Comparing Next-Generation Container Image Building Tools
 Comparing Next-Generation Container Image Building Tools Comparing Next-Generation Container Image Building Tools
Comparing Next-Generation Container Image Building Tools
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded Linux
 
LibCT: one lib to rule them all -- Andrey Vagin
LibCT: one lib to rule them all -- Andrey VaginLibCT: one lib to rule them all -- Andrey Vagin
LibCT: one lib to rule them all -- Andrey Vagin
 

More from Igalia

Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JITIgalia
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!Igalia
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerIgalia
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in MesaIgalia
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIgalia
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsIgalia
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesIgalia
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSIgalia
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webIgalia
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersIgalia
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...Igalia
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on RaspberryIgalia
 
Enable hardware acceleration for GL applications without glamor on Xorg modes...
Enable hardware acceleration for GL applications without glamor on Xorg modes...Enable hardware acceleration for GL applications without glamor on Xorg modes...
Enable hardware acceleration for GL applications without glamor on Xorg modes...Igalia
 
Async page flip in DRM atomic API
Async page flip in DRM  atomic APIAsync page flip in DRM  atomic API
Async page flip in DRM atomic APIIgalia
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepIgalia
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESMIgalia
 
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...Igalia
 
Freedreno on Android – XDC 2023
Freedreno on Android          – XDC 2023Freedreno on Android          – XDC 2023
Freedreno on Android – XDC 2023Igalia
 
On-going challenges in the Raspberry Pi driver stack – XDC 2023
On-going challenges in the Raspberry Pi driver stack – XDC 2023On-going challenges in the Raspberry Pi driver stack – XDC 2023
On-going challenges in the Raspberry Pi driver stack – XDC 2023Igalia
 
Status Update of the VKMS DRM driver – XDC 2023
Status Update of the VKMS DRM driver – XDC 2023Status Update of the VKMS DRM driver – XDC 2023
Status Update of the VKMS DRM driver – XDC 2023Igalia
 

More from Igalia (20)

Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shaders
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
 
Enable hardware acceleration for GL applications without glamor on Xorg modes...
Enable hardware acceleration for GL applications without glamor on Xorg modes...Enable hardware acceleration for GL applications without glamor on Xorg modes...
Enable hardware acceleration for GL applications without glamor on Xorg modes...
 
Async page flip in DRM atomic API
Async page flip in DRM  atomic APIAsync page flip in DRM  atomic API
Async page flip in DRM atomic API
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESM
 
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
The rainbow treasure map: Advanced color management on Linux with AMD/Steam D...
 
Freedreno on Android – XDC 2023
Freedreno on Android          – XDC 2023Freedreno on Android          – XDC 2023
Freedreno on Android – XDC 2023
 
On-going challenges in the Raspberry Pi driver stack – XDC 2023
On-going challenges in the Raspberry Pi driver stack – XDC 2023On-going challenges in the Raspberry Pi driver stack – XDC 2023
On-going challenges in the Raspberry Pi driver stack – XDC 2023
 
Status Update of the VKMS DRM driver – XDC 2023
Status Update of the VKMS DRM driver – XDC 2023Status Update of the VKMS DRM driver – XDC 2023
Status Update of the VKMS DRM driver – XDC 2023
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Building a Linux distro with LLVM

  • 1. 2023/02/03 Chimera Linux @ FOSDEM 2024 1 Building a Linux distro with LLVM
  • 2. 2023/02/03 Chimera Linux @ FOSDEM 2024 2 Introduction ● General-purpose Linux distribution ● Particular focus on desktop/workstations ● Robustness, security hardening, good defaults ● Lightweight and transparent ● Pragmatic and versatile
  • 3. 2023/02/03 Chimera Linux @ FOSDEM 2024 3 Overview ● LLVM as system toolchain ● FreeBSD as core userland ● Musl as libc ● Apk-tools as package manager ● Binary packaging, clean source build infra
  • 4. 2023/02/03 Chimera Linux @ FOSDEM 2024 4 Overview ● Bootstrappable ● Can cross-compile (official repos are native) ● Supports many architectures: – Aarch64, ppc64le, ppc64, riscv64, x86_64 ● System-wide LTO, UBSan, CFI, ...
  • 5. 2023/02/03 Chimera Linux @ FOSDEM 2024 5 Getting started ● Early 2021 ● Cbuild: source package build system ● Template: describes one individual piece of software ● Host system: Void Linux, architecture: ppc64le ● Sandbox: runs its own build environment
  • 6. 2023/02/03 Chimera Linux @ FOSDEM 2024 6 Bootstrap process ● 4 stages ● Stage 0: use outside toolchain ● Stage 1: use packages from stage 0 (containerized) ● Stage 2: enable LTO and remaining build options ● Stage 3: clean rebuild (with stage 2 packages)
  • 7. 2023/02/03 Chimera Linux @ FOSDEM 2024 7 Build environment ● Bare minimum packages needed to build self ● Libc, compiler, core userland, package manager ● Build dependencies for software being packaged ● Overall a small Chimera container ● Running unprivileged (Linux user namespaces)
  • 8. 2023/02/03 Chimera Linux @ FOSDEM 2024 8 Why use LLVM? ● More modern compiler design ● Security: state of the art sanitizers (e.g. CFI) ● Easier to build and bootstrap, simpler cross-build ● Thin LTO, better performance ● Often less buggy
  • 9. 2023/02/03 Chimera Linux @ FOSDEM 2024 9 Why not use LLVM? ● Very occasionally worse compatibility ● Fewer architectures supported ● Some of the supported ones are less maintained ● Takes longer to build (bigger, idiomatic C++) ● Very rarely worse performance
  • 10. 2023/02/03 Chimera Linux @ FOSDEM 2024 10 Toolchain structure: typical ● A C library (usually glibc or musl) ● GNU Binutils: assembler, linker, ELF utilities ● GCC: C/C++ compiler, core runtime (crt+libgcc), C++ standard library, possibly other languages ● One build of binutils+gcc per target
  • 11. 2023/02/03 Chimera Linux @ FOSDEM 2024 11 Userland ABI: typical ● Part statically linked – builtins (libgcc.a), early crt ● Unwinder + dynamic builtins: libgcc_s.so.1 ● C++ standard library: libstdc++.so.6 ● Base C++ ABI: libstdc++.so.6 or libsupc++ ● CRT is part libc, part GCC
  • 12. 2023/02/03 Chimera Linux @ FOSDEM 2024 12 Toolchain structure: LLVM ● LLVM: compiler, linker, assembler, binutils, all-in-one ● The only separate component is libc (glibc/musl) ● One compiler for all native and cross targets ● Only the runtime and target libraries are per-target ● Simplified bringup
  • 13. 2023/02/03 Chimera Linux @ FOSDEM 2024 13 Userland ABI: native LLVM ● Not used in most distros (LLVM uses GCC’s env) ● Builtins are static (libclang_rt.builtins.a) - compiler_rt ● Unwinder: libunwind.so.1 ● C++ library and base ABI: libc++.so.1, libc++abi.so.1 ● Standalone (no GCC dependency)
  • 14. 2023/02/03 Chimera Linux @ FOSDEM 2024 14 ABI compatibility ● Libunwind ABI matches most of libgcc_s ● Builtins can be compiled into a makeshift libgcc_s ● Libc++ stdlib ABI is different (won’t run GCC programs) ● However, libc++ and libstdc++ can live in one process – In theory (need libstdc++ using libc++’s ABI library)
  • 15. 2023/02/03 Chimera Linux @ FOSDEM 2024 15 Choosing a libc ● Glibc: could not build with Clang until recently – Still incompatible with native LLVM: dlopens libgcc_s.so.1 ● Musl: builds and just works as-is ● There are others but generally domain-specific (e.g. embedded) or somehow worse than the other two
  • 16. 2023/02/03 Chimera Linux @ FOSDEM 2024 16 The allocator ● LLVM comes with yet another thing: Scudo ● The memory allocator used in Android, hardened ● Modular design: can mix and match components, configure them, or even provide custom ones ● Very unassuming (no mandatory ELF TLS, etc.)
  • 17. 2023/02/03 Chimera Linux @ FOSDEM 2024 17 The allocator ● Musl allocator: bad performance in threaded programs ● Replaced with Scudo: e.g. 3x faster lld LTO link perf ● No ELF TLS within libc: custom TSD registry – Plugs directly into the pthread structure, manual mmap ● Unfortunately very high virt mem usage :(
  • 18. 2023/02/03 Chimera Linux @ FOSDEM 2024 18 Cross-compilation ● Cbuild can cross-compile ● Cross targets need cross runtimes ● Includes compiler-rt, musl, libunwind, libc++(abi) ● Slightly tricky bootstrap ● Installed into sysroot
  • 19. 2023/02/03 Chimera Linux @ FOSDEM 2024 19 Bootstrapping cross runtimes ● Build compiler-rt builtins+crtbegin/end first – Force static libs (avoid conftests) and disable sanitizers – Requires libc headers, so give it some (musl in temp place) ● Build and install libc (needs only the above) ● Build and install libunwind and libc++(abi)
  • 20. 2023/02/03 Chimera Linux @ FOSDEM 2024 20 Bootstrapping cross runtimes ● Libunwind and libc++ can (should) be done all at once – Still needs explicit -nostdlib in CXXFLAGS (don’t have one) ● Now compile the rest of compiler-rt – This is mainly sanitizers ● Once in sysroot, this is the full cross runtime
  • 21. 2023/02/03 Chimera Linux @ FOSDEM 2024 21 Practical experiences ● Makes system-wide LTO possible – Far lower resource usage and near universal compatibility ● Security hardening – We deploy a subset of UBSan (signed overflows are crashes...) – Partial CFI; breaks too many projects to deploy universally
  • 22. 2023/02/03 Chimera Linux @ FOSDEM 2024 22 Practical experiences ● Toolchain patching is in line with GCC – Still heavier than I would like… (~30 patches) ● On Linux, often geared towards GCC-style environment – Upstream should consider dogfooding more ● The build system can be an impenetrable mess
  • 23. 2023/02/03 Chimera Linux @ FOSDEM 2024 23 Practical experiences ● Major release updates can be daunting – Every release breaks some third party software – Usually for a good reason (legacy C misfeatures…) – Still causes an unfortunate amount of fallout ● Community is good and helpful
  • 24. 2023/02/03 Chimera Linux @ FOSDEM 2024 24 Conclusion ● Generally a great toolchain ● Some pain points, but generally practical ● Can build just about any Linux software – Given GCC’s history, an amazing feat ● Should not be reduced to “that GCC drop-in”
  • 25. 2023/02/03 Chimera Linux @ FOSDEM 2024 25 Thanks for listening! ● https://chimera-linux.org ● https://github.com/chimera-linux ● https://floss.social/@chimera_linux ● #chimera-linux @ OFTC (irc.oftc.net) ● #chimera-linux:matrix.org