Skip to content

Commit b1de8fd

Browse files
twd2knagaitsev
authored andcommitted
RISC-V: build: Allow LTO to be selected
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. Disable LTO for arch/riscv/kernel/pi, as llvm-objcopy expects an ELF object file when manipulating the files in that subfolder, rather than LLVM bitcode. [1] llvm/llvm-project#50505, resolved by LLVM commit e63455d5e0e5 ("[MC] Use local MCSubtargetInfo in writeNops") [2] ClangBuiltLinux#1942 [3] llvm/llvm-project#59350 [4] llvm/llvm-project#65090 Tested-by: Wende Tan <[email protected]> Signed-off-by: Wende Tan <[email protected]> Co-developed-by: Nathan Chancellor <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1d8731a commit b1de8fd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

arch/riscv/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ config RISCV
3838
select ARCH_SUPPORTS_ATOMIC_RMW
3939
select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
4040
select ARCH_SUPPORTS_HUGETLBFS if MMU
41+
# LLD >= 14: https://github.com/llvm/llvm-project/issues/50505
42+
select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000
43+
select ARCH_SUPPORTS_LTO_CLANG_THIN if LLD_VERSION >= 140000
4144
select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
4245
select ARCH_USE_MEMTEST
4346
select ARCH_USE_QUEUED_RWLOCKS

arch/riscv/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ ifndef CONFIG_AS_IS_LLVM
4848
KBUILD_CFLAGS += -Wa,-mno-relax
4949
KBUILD_AFLAGS += -Wa,-mno-relax
5050
endif
51+
# LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
52+
# Ensure it is aware of linker relaxation with LTO, otherwise relocations may
53+
# be incorrect: https://github.com/llvm/llvm-project/issues/65090
54+
else ifeq ($(CONFIG_LTO_CLANG),y)
55+
KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
5156
endif
5257
endif
5358

0 commit comments

Comments
 (0)