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

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEIgalia
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesIgalia
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceIgalia
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfIgalia
 
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
 

More from Igalia (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
 
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
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 

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