linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/15] Add support for clang LTO
@ 2017-11-03 17:11 Sami Tolvanen
  2017-11-03 17:11 ` [PATCH 01/15] kbuild: add ld-name macro and support for GNU gold Sami Tolvanen
                   ` (19 more replies)
  0 siblings, 20 replies; 63+ messages in thread
From: Sami Tolvanen @ 2017-11-03 17:11 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: Greg Hackmann, Kees Cook, Matthias Kaehlcke, Nick Desaulniers,
	Sami Tolvanen

This series adds build system support for compiling the kernel with clang
Link Time Optimization (LTO), using GNU gold with the LLVMgold plug-in
for linking. Some background for clang's LTO support is available here:

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

With -flto, clang produces LLVM bitcode instead of object files, and
the compilation to native code happens at link time. In addition, clang
cannot use an external assembler for inline assembly when LTO is enabled,
which causes further compatibility issues.

The patches in this series remove intermediate linking steps when LTO is
used, postpone processing done on object files until after the LTO link
step, add workarounds for GNU gold incompatibilities, and address inline
assembly incompatibilities for arm64.

These changes allow arm64 defconfig to be compiled with LTO, but other
architectures are not enabled until compatibility issues have been
addressed. In particular, x86 inline assembly doesn't currently compile
with clang's integrated assembler due to this LLVM bug:

  https://bugs.llvm.org/show_bug.cgi?id=24487

Due to recent bug fixes in the toolchain, it's recommended to use clang
5.0 or later, and GNU gold from binutils 2.27 or later, although older
versions may also work depending on your kernel configuration. Here are
the steps for compiling arm64 defconfig with LTO, assuming LLVMgold.so is
in LD_LIBRARY_PATH and the rest of the toolchain is in PATH:

  $ make ARCH=arm64 defconfig
  $ ./scripts/config -e CLANG_LTO
  $ make ARCH=arm64 oldconfig
  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- CC=clang \
         LD=aarch64-linux-gnu-ld.gold

You can also define LD_FINAL_VMLINUX to use a different linker for
vmlinux_link, which may be necessary for working around GNU gold issues
with KASLR, for example.

Greg Hackmann (1):
  arm64: use -mno-implicit-float instead of -mgeneral-regs-only

Sami Tolvanen (14):
  kbuild: add ld-name macro and support for GNU gold
  kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold
  kbuild: add support for clang LTO
  kbuild: fix dynamic ftrace with clang LTO
  scripts/mod: disable LTO for empty.c
  efi/libstub: disable clang LTO
  arm64: don't pass -maarch64linux to GNU gold
  arm64: keep .altinstructions and .altinstr_replacement
  arm64: disable ARM64_ERRATUM_843419 for clang LTO
  arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS
  arm64: fix mrs_s/msr_s macros for clang LTO
  arm64: crypto: disable LTO for aes-ce-cipher.c
  arm64: select ARCH_SUPPORTS_CLANG_LTO

 .gitignore                            |   2 +
 Makefile                              |  21 ++++++-
 arch/Kconfig                          |  32 ++++++++++
 arch/arm64/Kconfig                    |   6 +-
 arch/arm64/Makefile                   |  17 +++++-
 arch/arm64/crypto/Makefile            |   2 +-
 arch/arm64/include/asm/kvm_hyp.h      |   2 +
 arch/arm64/include/asm/sysreg.h       |  71 ++++++++++++++++------
 arch/arm64/kernel/vmlinux.lds.S       |   4 +-
 drivers/firmware/efi/libstub/Makefile |   3 +-
 include/asm-generic/vmlinux.lds.h     |  10 ++--
 include/linux/compiler-clang.h        |   7 +++
 include/linux/compiler.h              |   4 ++
 kernel/trace/ftrace.c                 |   6 +-
 scripts/Kbuild.include                |   4 ++
 scripts/Makefile.build                |  83 +++++++++++++++++++++++++-
 scripts/Makefile.modpost              |  67 ++++++++++++++++++---
 scripts/link-vmlinux.sh               | 108 ++++++++++++++++++++++++++++++----
 scripts/mod/Makefile                  |   1 +
 scripts/recordmcount.c                |   3 +-
 20 files changed, 397 insertions(+), 56 deletions(-)

-- 
2.15.0.403.gc27cc4dac6-goog

^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2017-11-09 18:55 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03 17:11 [PATCH 00/15] Add support for clang LTO Sami Tolvanen
2017-11-03 17:11 ` [PATCH 01/15] kbuild: add ld-name macro and support for GNU gold Sami Tolvanen
2017-11-03 18:24   ` Nick Desaulniers
2017-11-03 17:11 ` [PATCH 02/15] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with " Sami Tolvanen
2017-11-03 17:11 ` [PATCH 03/15] kbuild: add support for clang LTO Sami Tolvanen
2017-11-03 17:11 ` [PATCH 04/15] kbuild: fix dynamic ftrace with " Sami Tolvanen
2017-11-03 17:11 ` [PATCH 05/15] scripts/mod: disable LTO for empty.c Sami Tolvanen
2017-11-03 17:11 ` [PATCH 06/15] efi/libstub: disable clang LTO Sami Tolvanen
2017-11-03 20:10   ` Ard Biesheuvel
2017-11-03 17:11 ` [PATCH 06/15] efi/libstub: disable LTO Sami Tolvanen
2017-11-03 17:11 ` [PATCH 07/15] arm64: use -mno-implicit-float instead of -mgeneral-regs-only Sami Tolvanen
2017-11-03 17:50   ` Nick Desaulniers
2017-11-03 18:02   ` Mark Rutland
2017-11-03 18:20     ` Nick Desaulniers
2017-11-03 18:31   ` Mark Rutland
2017-11-03 18:52     ` Mark Rutland
2017-11-03 19:06       ` Kees Cook
2017-11-03 20:18         ` Sami Tolvanen
2017-11-03 17:11 ` [PATCH 08/15] arm64: don't pass -maarch64linux to GNU gold Sami Tolvanen
2017-11-03 20:41   ` Yury Norov
2017-11-06 16:56     ` Sami Tolvanen
2017-11-03 17:11 ` [PATCH 09/15] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
2017-11-03 18:40   ` Nick Desaulniers
2017-11-03 17:11 ` [PATCH 10/15] arm64: disable ARM64_ERRATUM_843419 for clang LTO Sami Tolvanen
2017-11-03 20:13   ` Ard Biesheuvel
2017-11-09 18:54     ` Sami Tolvanen
2017-11-03 17:11 ` [PATCH 11/15] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
2017-11-03 17:11 ` [PATCH 11/15] arm64: fix mrs_s/msr_s macros for clang LTO Sami Tolvanen
2017-11-03 17:11 ` [PATCH 12/15] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
2017-11-03 17:11 ` [PATCH 12/15] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
2017-11-03 17:12 ` [PATCH 13/15] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
2017-11-03 20:09   ` Ard Biesheuvel
2017-11-03 20:29     ` Sami Tolvanen
2017-11-03 17:12 ` [PATCH 13/15] arm64: fix mrs_s/msr_s macros for clang LTO Sami Tolvanen
2017-11-03 17:53   ` Nick Desaulniers
2017-11-03 18:06     ` Mark Rutland
2017-11-03 18:15       ` Nick Desaulniers
2017-11-03 18:38   ` Mark Rutland
2017-11-08  9:25   ` Yury Norov
2017-11-09  0:02     ` Andi Kleen
2017-11-09  4:48       ` Maxim Kuvyrkov
2017-11-09 16:51         ` Sami Tolvanen
2017-11-09 16:50       ` Sami Tolvanen
2017-11-09 16:45     ` Sami Tolvanen
2017-11-03 17:12 ` [PATCH 14/15] arm64: crypto: disable LTO for aes-ce-cipher.c Sami Tolvanen
2017-11-03 20:10   ` Ard Biesheuvel
2017-11-03 17:12 ` [PATCH 15/15] arm64: select ARCH_SUPPORTS_CLANG_LTO Sami Tolvanen
2017-11-03 17:51 ` [PATCH 00/15] Add support for clang LTO Mark Rutland
2017-11-03 18:07   ` Nick Desaulniers
2017-11-03 18:29     ` Mark Rutland
2017-11-03 18:36       ` Nick Desaulniers
2017-11-03 18:49         ` Mark Rutland
2017-11-03 18:07   ` Matthias Kaehlcke
2017-11-03 18:09   ` Mark Rutland
2017-11-03 18:11     ` Nick Desaulniers
2017-11-03 19:26       ` Mark Rutland
2017-11-03 19:56         ` Sami Tolvanen
2017-11-04  2:13           ` Mark Rutland
2017-11-09 10:54             ` AKASHI Takahiro
2017-11-09 11:03               ` Marc Zyngier
2017-11-09 16:31               ` Sami Tolvanen
2017-11-03 20:23         ` Ard Biesheuvel
2017-11-03 18:22   ` Sami Tolvanen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).