Clinging to Clang
Discusses clinging to Clang and evaluates key implications for security practitioners.
Summary
## Overview This talk covers Clang's application to embedded Linux development, explaining what Clang is (a C/C++ front-end using LLVM infrastructure), its design goals, current adoption, and practical integration challenges. The speaker presents work done integrating Clang with the Yocto/OpenEmbedded framework.
## What is Clang Clang is a C/C++ and Objective-C front-end for the LLVM compiler infrastructure, designed to be GCC-compatible while implementing documented and undocumented GCC extensions. Key design goals include IDE-friendliness, BSD licensing (with ongoing discussion about Apache2 relicensing), ISO C/C++ standards compliance, library-based architecture (making it embeddable and pluggable), user-friendly error diagnostics with fix-it hints, and resource efficiency. Clang's diagnostic output significantly improved the industry—GCC subsequently rewrote its diagnostic framework and added color support.
## Clang for Embedded Linux Clang offers an inherent advantage for embedded Linux: it is natively a cross-compiler. Unlike GCC's complex multi-stage bootstrapping (requiring binutils, GCC bootstrap, kernel headers, Libc headers with stubs, then full Libc), Clang's workflow simplifies to: build binutils → build Clang → build headers/libraries → build full Libc. A single Clang binary can target multiple architectures via symlink naming (e.g., `arm_linux_clang`) or the `--target` option, eliminating the need for separate cross-compiler builds.
## Integration with Yocto/OpenEmbedded The meta-clang external layer enables per-package compiler selection using a TOOLCHAIN variable. This hybrid approach allows approximately 80–90% of embedded Linux packages to compile with Clang while using GCC for incompatible packages (primarily Glibc and parts of the Linux kernel). The framework generates SDKs containing both compilers and exports CLANG_CC and CLANK_CXX variables for easy switching. Packages are categorized: some allow compiler choice, others are hard-coded to specific toolchains.
## Performance & Diagnostics WebKit compilation testing showed Clang 3.9 completing in 2297 seconds versus GCC 6.2 in 2838 seconds (approximately 30% improvement). Clang offers superior error pinpointing and fix-it suggestions. The `--fSplit-dwarf` option further accelerates linking by separating debug information.
## Architecture Support Clang supports ARM64, x86, x64, PowerPC, PowerPC64, MIPS, MIPS64, and ColdFire—notably narrower than GCC's extensive architecture list. This limitation may constrain embedded Linux deployments targeting niche architectures.
## LLVM Runtime Components Clang provides complete GNU runtime replacement: - **libc++**: C++ Standard Library implementation, ~50% smaller and ~30% faster than libstdc++, not binary-compatible with libstdc++ - **compiler-rt**: C runtime providing compiler built-ins and libgcc interfaces - **libunwind**: Exception handling and unwinding (HP libunwind-compatible)
The speaker demonstrated building a C++ application with full exception handling using only LLVM components—eliminating libgcc and libstdc++ dependencies entirely.
## Tooling Ecosystem Clang's embeddable library architecture enabled development of powerful tools: - **Clang Static Analyzer**: Produces HTML reports (tested on musl-c library; two upstream fixes resulted) - **clang-format**: Source code reformatting - **clang-tidy**: Style enforcement and coding policy checking - **clang-check**: Syntax validation - **LLVM Sanitizers**: Address Sanitizer, Thread Sanitizer, etc. (partial architecture coverage)
## Limitations & Current Status - Linux kernel compilation incomplete (LLVM Linux project ongoing) - Glibc compilation with Clang in progress - Nested functions unsupported (non-standard GCC extension) - Various GCC-specific attributes and built-ins missing - Some packages incorrectly check `__GNUC__` macro instead of feature detection - Sanitizer support incomplete for PowerPC, MIPS architectures - IDE integration (Eclipse, Qt Creator) still in progress
## Adoption Current users include Debian experimental (~90% of packages compile), FreeBSD (system compiler), OpenMandriva (primary compiler since 3.7), and LLVM Linux project. Pre-built cross-toolchains available from Yocto Project and Linaro.
## Takeaways While Clang cannot yet completely replace GCC for embedded Linux (particularly for Glibc and full kernel compilation), it offers compelling advantages: simplified cross-compilation, faster builds, superior diagnostics, comprehensive LLVM tooling, and flexible runtime replacement. Multiple compilers benefit the ecosystem through competition and improved portability—compiling with both tools reveals hidden errors and platform-specific assumptions.
Related talks
The Linux Foundation·4 min
Nelly Porter
Demonstrates keynote: Welcome and evaluates key implications for security practitioners.
The Linux Foundation·23 min
Andrew Wilkins · Ascend Engineering
Explores QGC: What You Dont Know and evaluates key implications for security practitioners.
The Linux Foundation·30 min
Demonstrates ELC Closing Game and evaluates key implications for security practitioners.


