Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

🧰 Toolchains I've used to compile kernels for various devices

← Back to the main guide

Everything here is from my own builds. "Tested on" means I actually booted it.

Tip

You don't need to download any of these by hand. The build scripts fetch the right one into ~/toolchains on the first run. This page is for people building without a script, or who want to know what their script is pulling.

To unpack one manually:

tar -xvf filename.tar.xz   # or filename.tar.gz

Do I need a GCC cross compiler too?

This is the thing that confuses people the most, so, short answer:

Your source What you need
4.9 up to 5.4, stock or OEM Clang and a GCC cross compiler
4.9 up to 5.4, AOSP or LineageOS Usually Clang only, with LLVM=1
5.10 and newer Clang only, with LLVM=1

On the old stock trees the build system still calls GCC tools like aarch64-linux-gnu-ld to assemble and link, even though Clang compiles the C code. From 5.10 onward LLVM=1 points every tool at the LLVM equivalent, so no GCC cross compiler is downloaded or used at all.

The middle row is the one people miss. AOSP and LineageOS backport the newer LLVM support into their old trees, so a 4.14 LineageOS kernel usually builds with Clang alone even though a 4.14 stock kernel from the same era does not. That is why there are two scripts for 4.14. If LLVM=1 fails on your tree, it was not patched, so use the stock script instead.

1. Linux 4.9

What build_4.9.sh uses: proton-12 and linaro-aarch64-7.5

Also works: clang-r416183b

  • Tested on 4.9.227.

  • This one ships its own aarch64-linux-gnu- binaries, so point both variables inside it:

    CROSS_COMPILE=/path/to/clang-r416183b/bin/aarch64-linux-gnu-
    CC=/path/to/clang-r416183b/bin/clang

2. Linux 4.14

What build_4.14.sh uses (common 4.14, for devices like realme): clang-r383902b and arm-gnu-toolchain-14.2.rel1

What build_4.14_aosp.sh uses (AOSP and LineageOS sources): neutron-clang

  • Tested on Linux 4.14.355.
  • Clang only. These trees carry the newer LLVM support, so no GCC is needed.
  • Nothing special about this one, it is just what I had set up at the time. Any reasonably recent Clang should build these trees.
  • Usage: build.sh from android_kernel_aosp_exynos9820

Samsung with Knox: clang-4639204-cfp-jopp and gcc-cfp-jopp-only

Samsung without Knox: clang-4639204 and aarch64-linux-android-4.9

  • Tested on Linux 4.14.113 (Galaxy M21).

3. Linux 4.19

What build_4.19.sh uses: clang-r353983c and arm-gnu-toolchain-14.2.rel1

Also works: clang-r383902 and the same ARM GNU toolchain

4. Linux 5.4 (qGKI)

What build_5.4.sh and build_qGKI.sh use: llvm-arm-toolchain-ship-10.0.9 and arm-gnu-toolchain-14.2.rel1

Note

This Snapdragon toolchain is the one that needs libtinfo.so.5, which no current distro ships. The build scripts work around it for you.

5. Linux 5.10

What build_5.10.sh uses: clang-r416183b

  • Tested on Linux 5.10.198.
  • Clang only. The script still passes CROSS_COMPILE=aarch64-linux-gnu-, but that is only a target triple for Clang, not a path to any GCC.
  • Usage: build_kernel.sh from android_kernel_s23fe

6. Linux 5.15

What build_5.15.sh uses: clang-r450784e

  • Tested on Linux 5.15.123 to 5.15.149.
  • Clang only, no CROSS_COMPILE at all. 5.15 works out its own target.

7. Linux 6.1 and newer (other GKI 2.0 kernels)

What build_6.1.sh uses: clang-r510928

  • Clang only, no CROSS_COMPILE.
  • This same toolchain builds 5.15 too, so if you only want to keep one Clang around for the modern kernels, keep this one.

Note

There is no rule that says you must use a particular Clang here. Any recent AOSP Clang works on 6.1 and newer, and so do the community builds. I use the AOSP ones because Google builds them for exactly these kernels.

Additional notes

  • On MediaTek kernels from the 4.9 to 5.4 era, use the ARM GNU toolchain alongside a proper Clang to make the kernel boot :)

  • The other MediaTek gotcha, on any version, is that they usually cannot boot a raw Image. Build Image.gz instead. In the build scripts that is KERNEL_IMAGE="Image.gz".

  • Since March 21, 2025 the scripts for 4.9 up to 5.4 use the ARM GNU toolchain as their CROSS_COMPILE. Reference: build_kernel.sh from android_kernel_a042f


← Back to the main guide