Message ID | 20231017-riscv-lto-v4-1-e7810b24e805@kernel.org (mailing list archive) |
---|---|
State | Accepted |
Commit | 021d23428bdbae032294e8f4a29cb53cb50ae71c |
Headers | show |
Series | [v4] RISC-V: build: Allow LTO to be selected | expand |
Hello: This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <palmer@rivosinc.com>: On Tue, 17 Oct 2023 15:21:04 -0700 you wrote: > From: Wende Tan <twd2.me@gmail.com> > > Allow LTO to be selected for RISC-V, only when LLD >= 14, since there is > an issue [1] in prior LLD versions that prevents LLD to generate proper > machine code for RISC-V when writing `nop`s. > > To avoid boot failures in QEMU [2], '-mattr=+c' and '-mattr=+relax' > need to be passed via '-mllvm' to ld.lld, as there appears to be an > issue with LLVM's target-features and LTO [3], which can result in > incorrect relocations to branch targets [4]. Once this is fixed in LLVM, > it can be made conditional on affected ld.lld versions. > > [...] Here is the summary with links: - [v4] RISC-V: build: Allow LTO to be selected https://git.kernel.org/riscv/c/021d23428bdb You are awesome, thank you!
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d607ab0f7c6d..523640f7441e 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -46,6 +46,9 @@ config RISCV select ARCH_SUPPORTS_CFI_CLANG select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU select ARCH_SUPPORTS_HUGETLBFS if MMU + # LLD >= 14: https://github.com/llvm/llvm-project/issues/50505 + select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000 + select ARCH_SUPPORTS_LTO_CLANG_THIN if LLD_VERSION >= 140000 select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU select ARCH_SUPPORTS_PER_VMA_LOCK if MMU select ARCH_USE_MEMTEST diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 1329e060c548..709400ceac60 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -52,6 +52,11 @@ ifndef CONFIG_AS_IS_LLVM KBUILD_CFLAGS += -Wa,-mno-relax KBUILD_AFLAGS += -Wa,-mno-relax endif +# LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350 +# Ensure it is aware of linker relaxation with LTO, otherwise relocations may +# be incorrect: https://github.com/llvm/llvm-project/issues/65090 +else ifeq ($(CONFIG_LTO_CLANG),y) + KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax endif endif diff --git a/arch/riscv/kernel/pi/Makefile b/arch/riscv/kernel/pi/Makefile index 07915dc9279e..b75f150b923d 100644 --- a/arch/riscv/kernel/pi/Makefile +++ b/arch/riscv/kernel/pi/Makefile @@ -9,6 +9,9 @@ KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \ -fno-asynchronous-unwind-tables -fno-unwind-tables \ $(call cc-option,-fno-addrsig) +# Disable LTO +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS)) + KBUILD_CFLAGS += -mcmodel=medany CFLAGS_cmdline_early.o += -D__NO_FORTIFY