|
| 1 | +# Greenforce Clang |
| 2 | + |
| 3 | +## Host compatibility |
| 4 | + |
| 5 | +This toolchain is built on Ubuntu 20.04, which uses glibc 2.31. Compatibility with older distributions cannot be guaranteed. Other libc implementations (such as musl) are not supported. |
| 6 | + |
| 7 | +## Building Linux |
| 8 | + |
| 9 | +Make sure you have this toolchain in your `PATH`: |
| 10 | + |
| 11 | +```bash |
| 12 | +export PATH="$HOME/toolchains/clang-llvm/bin:$PATH" |
| 13 | +``` |
| 14 | + |
| 15 | +For an AArch64 cross-compilation setup, you must set the following variables. Some of them can be environment variables, but some must be passed directly to `make` as a command-line argument. It is recommended to pass **all** of them as `make` arguments to avoid confusing errors: |
| 16 | + |
| 17 | +- `CC=clang` (must be passed directly to `make`) |
| 18 | +- `CROSS_COMPILE=aarch64-linux-gnu-` |
| 19 | +- If your kernel has a 32-bit vDSO: `CROSS_COMPILE_ARM32=arm-linux-gnueabi-` |
| 20 | + |
| 21 | +Optionally, you can also choose to use as many LLVM tools as possible to reduce reliance on binutils. All of these must be passed directly to `make`: |
| 22 | + |
| 23 | +- `AR=llvm-ar` |
| 24 | +- `NM=llvm-nm` |
| 25 | +- `OBJCOPY=llvm-objcopy` |
| 26 | +- `OBJDUMP=llvm-objdump` |
| 27 | +- `STRIP=llvm-strip` |
| 28 | + |
| 29 | +Note, however, that additional kernel patches may be required for these LLVM tools to work. It is also possible to replace the binutils linkers (`lf.bfd` and `ld.gold`) with `lld` and use Clang's integrated assembler for inline assembly in C code, but that will require many more kernel patches and it is currently impossible to use the integrated assembler for *all* assembly code in the kernel. |
| 30 | + |
| 31 | +Android kernels older than 4.14 will require patches for compiling with any Clang toolchain to work; those patches are out of the scope of this project. See [android-kernel-clang](https://github.com/nathanchance/android-kernel-clang) for more information. |
| 32 | + |
| 33 | +Android kernels 4.19 and newer use the upstream variable `CROSS_COMPILE_COMPAT`. When building these kernels, replace `CROSS_COMPILE_ARM32` in your commands and scripts with `CROSS_COMPILE_COMPAT`. |
| 34 | + |
| 35 | +### Differences from other toolchains |
| 36 | + |
| 37 | +Greenforce Clang has been designed to be easy-to-use compared to other toolchains, such as [AOSP Clang](https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/). The differences are as follows: |
| 38 | + |
| 39 | +- `CLANG_TRIPLE` does not need to be set because we don't use AOSP binutils. |
| 40 | +- `LD_LIBRARY_PATH` does not need to be set because we set library load paths in the toolchain. |
| 41 | +- No separate GCC/binutils toolchains are necessary; all tools are bundled. |
| 42 | + |
| 43 | +#### Additional patches |
| 44 | + |
| 45 | +To use full Clang LTO with Greenforce Clang, you have to cherry-pick [ANDROID: generate_initcall_order.pl: Use two dash long options for llvm-nm](https://android.googlesource.com/kernel/common.git/+/240f2f8f42f57b46788379e0072836cb2cb40c8c) otherwise your kernel will not boot. |
0 commit comments