kernel.mk: Support kernels that use LTO

Google added support for LTO + CFI in the Pixel 3 kernel, which requires
not only Clang but a couple of additional binaries, namely llvm-ar and
llvm-dis for IR generation. Google expects these binaries to be in PATH
according to their definitions and the build.config.common file:

https://android.googlesource.com/kernel/msm/+/android-9.0.0_r0.31/Makefile#637
https://android.googlesource.com/kernel/msm/+/android-9.0.0_r0.31/build.config.common

However, kernel.mk does not add the LLVM bin directory to PATH so the
build fails because the binaries can't be found. We could add LLVM_AR
and LLVM_DIS to the make commands like CC and CROSS_COMPILE; however,
adding the bin directory to PATH is a more sustainable solution as
Google might require new binaries in the future.

Additionally, LTO needs access to the LLVMgold library so it needs to be
available in LD_LIBRARY_PATH.

Add a PATH_OVERRIDE variable that will set up PATH and LD_LIBRARY_PATH
with the bin and lib64 folders from the requested LLVM toolchain
respectively when building with Clang. This won't affect kernels that
don't use LTO like Wahoo.

Change-Id: Ib16fa0d3180de2f96accb2f7648b07a017f8f98b
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
1 file changed