[libc-commits] [libc] [libcxx] [libcxxabi] [libc] Readd instructions on building kernel headers from sources (PR #193657)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Apr 23 08:43:09 PDT 2026
================
@@ -139,10 +139,25 @@ headers.
# Use -L to dereference the asm symlink and copy the actual files
cp -R -L /usr/include/asm $SYSROOT/usr/include/
+If you instead want to build the headers from the kernel sources, you can run
+the following commands:
+
+.. code-block:: sh
+
+ # Create the include directory
+ mkdir -p $SYSROOT/usr/include
+
+ git clone --depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git /tmp/linux
+ make LLVM=1 INSTALL_HDR_PATH=$SYSROOT/usr -C /tmp/linux headers_install
+
+The headers can be built to target non-host architectures by adding the
----------------
nickdesaulniers wrote:
> Does this require a cross-compiler set up already, or will any compiler do to compile the headers?
It depends on whether you intend to use clang or GCC.
By specifying `LLVM=1`, you're indicating to KBuild you'd like to use clang, lld, llvm-nm, etc (all the LLVM substitutes for GNU binutils).
By specifying `ARCH`, you're telling KBuild you'd like to cross compile. For LLVM, this means passing `--target=<triple>` to some tools (compiler, maybe linker). For GNU, this means invoking `<triple>-<tool>`.
Assuming you haven't configured off `<arch>` from your build of LLVM, you can cross compile the kernel or its headers easily with one build. For GNU, you usually need an additional command line parameter (`CROSS_COMPILE`) set to `<triple>` that matches the prefixes of your tools.
I spent a few years working on KBuild; the result is that cross compiling the kernel with LLVM is _simpler_ IMO than with GCC+GNU binutils.
https://github.com/llvm/llvm-project/pull/193657
More information about the libc-commits
mailing list