From: Sami Tolvanen <samitolvanen@google.com>
To: Masahiro Yamada <masahiroy@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Will Deacon <will@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
clang-built-linux@googlegroups.com,
kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org,
Sami Tolvanen <samitolvanen@google.com>
Subject: [PATCH v7 00/17] Add support for Clang LTO
Date: Wed, 18 Nov 2020 14:07:14 -0800 [thread overview]
Message-ID: <20201118220731.925424-1-samitolvanen@google.com> (raw)
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 v7 brings back arm64 support as Will has now staged the
prerequisite memory ordering patches [1], and drops x86_64 while we work
on fixing the remaining objtool warnings [2].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/lto
[2] https://lore.kernel.org/lkml/20201114004911.aip52eimk6c2uxd4@treble/
You can also pull this series from
https://github.com/samitolvanen/linux.git lto-v7
---
Changes in v7:
- Rebased to master again.
- Added back arm64 patches as the prerequisites are now staged,
and dropped x86_64 support until the remaining objtool issues
are resolved.
- Dropped ifdefs from module.lds.S.
Changes in v6:
- Added the missing --mcount flag to patch 5.
- Dropped the arm64 patches from this series and will repost them
later.
Changes in v5:
- Rebased on top of tip/master.
- Changed the command line for objtool to use --vmlinux --duplicate
to disable warnings about retpoline thunks and to fix .orc_unwind
generation for vmlinux.o.
- Added --noinstr flag to objtool, so we can use --vmlinux without
also enabling noinstr validation.
- Disabled objtool's unreachable instruction warnings with LTO to
disable false positives for the int3 padding in vmlinux.o.
- Added ANNOTATE_RETPOLINE_SAFE annotations to the indirect jumps
in x86 assembly code to fix objtool warnings with retpoline.
- Fixed modpost warnings about missing version information with
CONFIG_MODVERSIONS.
- Included Makefile.lib into Makefile.modpost for ld_flags. Thanks
to Sedat for pointing this out.
- Updated the help text for ThinLTO to better explain the trade-offs.
- Updated commit messages with better explanations.
Changes in v4:
- Fixed a typo in Makefile.lib to correctly pass --no-fp to objtool.
- Moved ftrace configs related to generating __mcount_loc to Kconfig,
so they are available also in Makefile.modfinal.
- Dropped two prerequisite patches that were merged to Linus' tree.
Changes in v3:
- Added a separate patch to remove the unused DISABLE_LTO treewide,
as filtering out CC_FLAGS_LTO instead is preferred.
- Updated the Kconfig help to explain why LTO is behind a choice
and disabled by default.
- Dropped CC_FLAGS_LTO_CLANG, compiler-specific LTO flags are now
appended directly to CC_FLAGS_LTO.
- Updated $(AR) flags as KBUILD_ARFLAGS was removed earlier.
- Fixed ThinLTO cache handling for external module builds.
- Rebased on top of Masahiro's patch for preprocessing modules.lds,
and moved the contents of module-lto.lds to modules.lds.S.
- Moved objtool_args to Makefile.lib to avoid duplication of the
command line parameters in Makefile.modfinal.
- Clarified in the commit message for the initcall ordering patch
that the initcall order remains the same as without LTO.
- Changed link-vmlinux.sh to use jobserver-exec to control the
number of jobs started by generate_initcall_ordering.pl.
- Dropped the x86/relocs patch to whitelist L4_PAGE_OFFSET as it's
no longer needed with ToT kernel.
- Disabled LTO for arch/x86/power/cpu.c to work around a Clang bug
with stack protector attributes.
Changes in v2:
- Fixed -Wmissing-prototypes warnings with W=1.
- Dropped cc-option from -fsplit-lto-unit and added .thinlto-cache
scrubbing to make distclean.
- Added a comment about Clang >=11 being required.
- Added a patch to disable LTO for the arm64 KVM nVHE code.
- Disabled objtool's noinstr validation with LTO unless enabled.
- Included Peter's proposed objtool mcount patch in the series
and replaced recordmcount with the objtool pass to avoid
whitelisting relocations that are not calls.
- Updated several commit messages with better explanations.
Sami Tolvanen (17):
tracing: move function tracer options to Kconfig
kbuild: add support for Clang LTO
kbuild: lto: fix module versioning
kbuild: lto: limit inlining
kbuild: lto: merge module sections
kbuild: lto: remove duplicate dependencies from .mod files
init: lto: ensure initcall ordering
init: lto: fix PREL32 relocations
PCI: Fix PREL32 relocations for LTO
modpost: lto: strip .lto from module names
scripts/mod: disable LTO for empty.c
efi/libstub: disable LTO
drivers/misc/lkdtm: disable LTO for rodata.o
arm64: vdso: disable LTO
KVM: arm64: disable LTO for the nVHE directory
arm64: disable recordmcount with DYNAMIC_FTRACE_WITH_REGS
arm64: allow LTO_CLANG and THINLTO to be selected
.gitignore | 1 +
Makefile | 45 +++--
arch/Kconfig | 74 +++++++
arch/arm64/Kconfig | 4 +
arch/arm64/kernel/vdso/Makefile | 3 +-
arch/arm64/kvm/hyp/nvhe/Makefile | 4 +-
drivers/firmware/efi/libstub/Makefile | 2 +
drivers/misc/lkdtm/Makefile | 1 +
include/asm-generic/vmlinux.lds.h | 11 +-
include/linux/init.h | 79 +++++++-
include/linux/pci.h | 19 +-
kernel/trace/Kconfig | 16 ++
scripts/Makefile.build | 50 ++++-
scripts/Makefile.lib | 6 +-
scripts/Makefile.modfinal | 9 +-
scripts/Makefile.modpost | 25 ++-
scripts/generate_initcall_order.pl | 270 ++++++++++++++++++++++++++
scripts/link-vmlinux.sh | 70 ++++++-
scripts/mod/Makefile | 1 +
scripts/mod/modpost.c | 16 +-
scripts/mod/modpost.h | 9 +
scripts/mod/sumversion.c | 6 +-
scripts/module.lds.S | 24 +++
23 files changed, 677 insertions(+), 68 deletions(-)
create mode 100755 scripts/generate_initcall_order.pl
base-commit: 0fa8ee0d9ab95c9350b8b84574824d9a384a9f7d
--
2.29.2.299.gdc1121823c-goog
next reply other threads:[~2020-11-18 22:07 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 22:07 Sami Tolvanen [this message]
2020-11-18 22:07 ` [PATCH v7 01/17] tracing: move function tracer options to Kconfig Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 02/17] kbuild: add support for Clang LTO Sami Tolvanen
2020-11-18 23:48 ` Nick Desaulniers
2020-11-20 16:23 ` Sami Tolvanen
2020-11-20 19:47 ` Kees Cook
2020-11-20 20:29 ` Nathan Chancellor
2020-11-20 20:43 ` Kees Cook
2020-11-20 20:58 ` Sami Tolvanen
2020-11-20 23:59 ` Kees Cook
2020-11-21 1:46 ` Sami Tolvanen
2020-11-21 20:11 ` Kees Cook
2020-11-18 22:07 ` [PATCH v7 03/17] kbuild: lto: fix module versioning Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 04/17] kbuild: lto: limit inlining Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 05/17] kbuild: lto: merge module sections Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 06/17] kbuild: lto: remove duplicate dependencies from .mod files Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 07/17] init: lto: ensure initcall ordering Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 08/17] init: lto: fix PREL32 relocations Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 09/17] PCI: Fix PREL32 relocations for LTO Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 10/17] modpost: lto: strip .lto from module names Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 11/17] scripts/mod: disable LTO for empty.c Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 12/17] efi/libstub: disable LTO Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 13/17] drivers/misc/lkdtm: disable LTO for rodata.o Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 14/17] arm64: vdso: disable LTO Sami Tolvanen
2020-11-30 11:52 ` Will Deacon
2020-11-30 23:44 ` Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 15/17] KVM: arm64: disable LTO for the nVHE directory Sami Tolvanen
2020-11-23 10:21 ` David Brazdil
2020-11-23 18:34 ` Sami Tolvanen
2020-11-18 22:07 ` [PATCH v7 16/17] arm64: disable recordmcount with DYNAMIC_FTRACE_WITH_REGS Sami Tolvanen
2020-11-30 11:59 ` Will Deacon
2020-11-18 22:07 ` [PATCH v7 17/17] arm64: allow LTO_CLANG and THINLTO to be selected Sami Tolvanen
2020-11-30 12:00 ` Will Deacon
2020-11-18 23:42 ` [PATCH v7 00/17] Add support for Clang LTO Nick Desaulniers
2020-11-20 10:29 ` Ard Biesheuvel
2020-11-20 20:19 ` Nick Desaulniers
2020-11-20 23:30 ` Ard Biesheuvel
2020-11-20 23:53 ` Nick Desaulniers
2020-11-21 7:35 ` Ard Biesheuvel
2020-11-21 11:40 ` Marc Zyngier
2020-11-21 3:14 ` Nathan Chancellor
2020-11-20 4:04 ` Josh Poimboeuf
2020-11-20 20:25 ` Sami Tolvanen
2020-11-30 12:01 ` Will Deacon
2020-12-01 17:31 ` Kees Cook
2020-12-01 19:51 ` Nick Desaulniers
2020-12-01 21:38 ` Sami Tolvanen
2020-12-02 2:42 ` Masahiro Yamada
2020-12-02 5:46 ` Sami Tolvanen
2020-12-02 18:54 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201118220731.925424-1-samitolvanen@google.com \
--to=samitolvanen@google.com \
--cc=clang-built-linux@googlegroups.com \
--cc=gregkh@linuxfoundation.org \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=ndesaulniers@google.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).