Re: [PATCH v9 00/16] Add support for Clang LTO

Kees Cook
2020-12-11T21:09:34Z

On Fri, Dec 11, 2020 at 10:46:17AM -0800, Sami Tolvanen wrote:
> This patch series adds support for building the kernel with Clang's
> Link Time Optimization (LTO). In addition to performance, the primary
> motivation for LTO is to allow Clang's Control-Flow Integrity (CFI)
> to be used in the kernel. Google has shipped millions of Pixel
> devices running three major kernel versions with LTO+CFI since 2018.
>
> Most of the patches are build system changes for handling LLVM
> bitcode, which Clang produces with LTO instead of ELF object files,
> postponing ELF processing until a later stage, and ensuring initcall
> ordering.
>
> Note that arm64 support depends on Will's memory ordering patches
> [1]. I will post x86_64 patches separately after we have fixed the
> remaining objtool warnings [2][3].
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/lto
> [2] https://lore.kernel.org/lkml/20201120040424.a3wctajzft4ufoiw@treble/
> [3] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=objtool-vmlinux
>
> You can also pull this series from
>
> https://github.com/samitolvanen/linux.git lto-v9
>
> ---
> Changes in v9:
>
> - Added HAS_LTO_CLANG dependencies to LLVM=1 and LLVM_IAS=1 to avoid
> issues with mismatched toolchains.
>
> - Dropped the .mod patch as Masahiro landed a better solution to
> the split line issue in commit 7d32358be8ac ("kbuild: avoid split
> lines in .mod files").
>
> - Updated CC_FLAGS_LTO to use -fvisibility=hidden to avoid weak symbol
> visibility issues with ThinLTO on x86.
>
> - Changed LTO_CLANG_FULL to depend on !COMPILE_TEST to prevent
> timeouts in automated testing.
>
> - Added a dependency to CPU_LITTLE_ENDIAN to ARCH_SUPPORTS_LTO_CLANG
> in arch/arm64/Kconfig.
>
> - Added a default symbol list to fix an issue with TRIM_UNUSED_KSYMS.

This continues to look good to me. I'd like to see it in -next ASAP so
we can continue to find any little needed tweaks. Since it works in the
general case, we can add on top of this series once it's in -next.

Masahiro, let me know if you'd rather I not carry this in -next. AFAICT,
the bulk of the changes in the build system continue to be confined to
the LTO-only cases, so it should not be disruptive to anyone doing
non-LTO builds.

--
Kees Cook