15 Jan, 2021

1 commit


17 Dec, 2020

2 commits

  • With LTO, LLVM bitcode won't be compiled into native code until
    modpost_link, or modfinal for modules. This change postpones calls
    to objtool until after these steps, and moves objtool_args to
    Makefile.lib, so the arguments can be reused in Makefile.modfinal.

    As we didn't have objects to process earlier, we use --duplicate
    when processing vmlinux.o. This change also disables unreachable
    instruction warnings with LTO to avoid warnings about the int3
    padding between functions.

    Bug: 145210207
    Change-Id: I72615f7062d218bf612a5d929f2efb75a18538dd
    Link: https://lore.kernel.org/lkml/20201013003203.4168817-12-samitolvanen@google.com/
    Signed-off-by: Sami Tolvanen
    Reviewed-by: Kees Cook

    Sami Tolvanen
     
  • This change adds build system support for Clang's Link Time
    Optimization (LTO). With -flto, instead of ELF object files, Clang
    produces LLVM bitcode, which is compiled into native code at link
    time, allowing the final binary to be optimized globally. For more
    details, see:

    https://llvm.org/docs/LinkTimeOptimization.html

    The Kconfig option CONFIG_LTO_CLANG is implemented as a choice,
    which defaults to LTO being disabled. To use LTO, the architecture
    must select ARCH_SUPPORTS_LTO_CLANG and support:

    - compiling with Clang,
    - compiling all assembly code with Clang's integrated assembler,
    - and linking with LLD.

    While using CONFIG_LTO_CLANG_FULL results in the best runtime
    performance, the compilation is not scalable in time or
    memory. CONFIG_LTO_CLANG_THIN enables ThinLTO, which allows
    parallel optimization and faster incremental builds. ThinLTO is
    used by default if the architecture also selects
    ARCH_SUPPORTS_LTO_CLANG_THIN:

    https://clang.llvm.org/docs/ThinLTO.html

    To enable LTO, LLVM tools must be used to handle bitcode files, by
    passing LLVM=1 and LLVM_IAS=1 options to make:

    $ make LLVM=1 LLVM_IAS=1 defconfig
    $ scripts/config -e LTO_CLANG_THIN
    $ make LLVM=1 LLVM_IAS=1

    To prepare for LTO support with other compilers, common parts are
    gated behind the CONFIG_LTO option, and LTO can be disabled for
    specific files by filtering out CC_FLAGS_LTO.

    Bug: 145210207
    Change-Id: I85eb4523ea787e4f9884e12ed6301f876d0d888e
    Link: https://lore.kernel.org/lkml/20201211184633.3213045-1-samitolvanen@google.com/
    Signed-off-by: Sami Tolvanen
    Reviewed-by: Kees Cook

    Sami Tolvanen
     

24 Sep, 2020

1 commit

  • There was a request to preprocess the module linker script like we
    do for the vmlinux one. (https://lkml.org/lkml/2020/8/21/512)

    The difference between vmlinux.lds and module.lds is that the latter
    is needed for external module builds, thus must be cleaned up by
    'make mrproper' instead of 'make clean'. Also, it must be created
    by 'make modules_prepare'.

    You cannot put it in arch/$(SRCARCH)/kernel/, which is cleaned up by
    'make clean'. I moved arch/$(SRCARCH)/kernel/module.lds to
    arch/$(SRCARCH)/include/asm/module.lds.h, which is included from
    scripts/module.lds.S.

    scripts/module.lds is fine because 'make clean' keeps all the
    build artifacts under scripts/.

    You can add arch-specific sections in .

    Signed-off-by: Masahiro Yamada
    Tested-by: Jessica Yu
    Acked-by: Will Deacon
    Acked-by: Geert Uytterhoeven
    Acked-by: Palmer Dabbelt
    Reviewed-by: Kees Cook
    Acked-by: Jessica Yu

    Masahiro Yamada
     

22 Aug, 2019

2 commits