musllvm

musl and LLVM cross-toolchain build system
git clone https://git.daat.foo/musllvm.git
Log | Files | Refs | README | LICENSE

commit ec3a09b6c0fc1101959d3a6e81f41627bcf768bd
parent b3264a212ed1b7bbecd87417f5eb5e52f3eb9399
Author: cowmonk <cowmonk@based.pt>
Date:   Mon, 19 Oct 2026 17:03:26 -0700

builtins bootstrap can find libunwind headers

Diffstat:
Mpatches/README.md | 3++-
Mscripts/build.sh | 1+
Mtests/test_driver.py | 35+++++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/patches/README.md b/patches/README.md @@ -14,7 +14,8 @@ For LLVM 23.1.3: Its context was updated for LLVM 23; the change matches Chimera's patch. * 0002 removes musl's large file macros before LLVM declares matching names. * 0011 builds the C exception personality with LLVM's unwind headers during - the compiler-rt bootstrap. + the compiler-rt bootstrap. The builtins configuration adds libunwind's + source include directory so unwind.h can find its nested headers. The Clang configuration and CMake settings cover Chimera's hardening, libatomic, library layout and typeinfo defaults. The build also uses diff --git a/scripts/build.sh b/scripts/build.sh @@ -150,6 +150,7 @@ builtins() if ! done_stage builtins; then target_cmake -S "$LLVM_SOURCE/compiler-rt" -B "$BUILD_DIR/builtins" \ -DLLVM_CMAKE_DIR="$LLVM_CMAKE_DIR" \ + -DCMAKE_C_STANDARD_INCLUDE_DIRECTORIES="$LLVM_SOURCE/libunwind/include" \ -DCMAKE_INSTALL_PREFIX="$RESOURCE_DIR" -DCOMPILER_RT_INSTALL_PATH="$RESOURCE_DIR" \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \ -DCOMPILER_RT_BUILD_BUILTINS=ON -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=ON \ diff --git a/tests/test_driver.py b/tests/test_driver.py @@ -142,6 +142,16 @@ class DriverTests(unittest.TestCase): info = tarfile.TarInfo(component + "-test/" + relative) info.size = 7 stream.addfile(info, io.BytesIO(b"fixture")) + if component == "llvm": + headers = { + "unwind.h": b"#include <__libunwind_config.h>\n#include <unwind_itanium.h>\n", + "__libunwind_config.h": b"#define UNWIND_CONFIG_FIXTURE 1\n", + "unwind_itanium.h": b"#define UNWIND_ITANIUM_FIXTURE 1\n", + } + for name, content in headers.items(): + info = tarfile.TarInfo(component + "-test/libunwind/include/" + name) + info.size = len(content) + stream.addfile(info, io.BytesIO(content)) digest = hashlib.sha256(archive.read_bytes()).hexdigest() manifest.append(f"{component} {archive.name} {digest} https://example.invalid/{archive.name}\n") (self.root / "sources.list").write_text("".join(manifest)) @@ -256,6 +266,31 @@ class DriverTests(unittest.TestCase): self.assertEqual(os.readlink(prefix / "libexec/clang"), "../host/bin/clang") self.assertTrue((prefix / "bin/x86_64-linux-musl-c++").exists()) + def test_builtins_find_libunwind_headers_before_installation(self): + for arch in ("x86_64", "aarch64"): + for mode in ("system", "source"): + with self.subTest(arch=arch, mode=mode): + name = arch + "-" + mode + prefix = self.root / "build" / name + work = self.root / "build/work" / name + self.run_make("builtins", "ARCH=" + arch, "LLVM_MODE=" + mode, + "PREFIX=" + str(prefix), "BUILD_DIR=" + str(work), + "TARGET_CFLAGS=-Os") + self.assertFalse((prefix / "sysroot/usr/include/unwind.h").exists()) + options = json.loads((work / "builtins/fixture-config.json").read_text()) + directories = [option.split("=", 1)[1] for option in options + if option.startswith("-DCMAKE_C_STANDARD_INCLUDE_DIRECTORIES=")] + self.assertEqual(len(directories), 1) + include = Path(directories[0]) + self.assertEqual(include, self.root / "build/src/llvm-test/libunwind/include") + for line in (include / "unwind.h").read_text().splitlines(): + header = line.removeprefix("#include <").removesuffix(">") + self.assertTrue((include / header).is_file(), header) + flags = next(option for option in options if option.startswith("-DCMAKE_C_FLAGS=")) + self.assertIn("-Os", flags) + self.assertIn("--gcc-toolchain=", flags) + self.assertIn("-resource-dir=", flags) + def test_source_patches_apply_once_in_order_and_are_installed(self): self.source_patch("10-second.patch", "first", "second") self.source_patch("00-first.patch", "fixture", "first")