Skip to content

Commit 74f8295

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Handle jump tables options for RUST
When compiling with LLVM and CONFIG_RUST is set, there exist objtool warnings in rust/core.o and rust/kernel.o, like this: rust/core.o: warning: objtool: _RNvXs1_NtNtCs5QSdWC790r4_4core5ascii10ascii_charNtB5_9AsciiCharNtNtB9_3fmt5Debug3fmt+0x54: sibling call from callable instruction with modified stack frame For this special case, the related object file shows that there is no generated relocation section '.rela.discard.tablejump_annotate' for the table jump instruction jirl, thus objtool can not know that what is the actual destination address. If rustc has the option "-Cllvm-args=--loongarch-annotate-tablejump", pass the option to enable jump tables for objtool, otherwise it should pass "-Zno-jump-tables" to keep compatibility with older rustc. How to test: $ rustup component add rust-src $ make LLVM=1 rustavailable $ make ARCH=loongarch LLVM=1 clean defconfig $ scripts/config -d MODVERSIONS \ -e RUST -e SAMPLES -e SAMPLES_RUST \ -e SAMPLE_RUST_CONFIGFS -e SAMPLE_RUST_MINIMAL \ -e SAMPLE_RUST_MISC_DEVICE -e SAMPLE_RUST_PRINT \ -e SAMPLE_RUST_DMA -e SAMPLE_RUST_DRIVER_PCI \ -e SAMPLE_RUST_DRIVER_PLATFORM -e SAMPLE_RUST_DRIVER_FAUX \ -e SAMPLE_RUST_DRIVER_AUXILIARY -e SAMPLE_RUST_HOSTPROGS $ make ARCH=loongarch LLVM=1 olddefconfig all Cc: [email protected] Acked-by: Miguel Ojeda <[email protected]> Reported-by: Miguel Ojeda <[email protected]> Closes: https://lore.kernel.org/rust-for-linux/CANiq72mNeCuPkCDrG2db3w=AX+O-zYrfprisDPmRac_qh65Dmg@mail.gmail.com/ Suggested-by: WANG Rui <[email protected]> Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent b152128 commit 74f8295

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

arch/loongarch/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ config AS_HAS_LVZ_EXTENSION
298298
config CC_HAS_ANNOTATE_TABLEJUMP
299299
def_bool $(cc-option,-mannotate-tablejump)
300300

301+
config RUSTC_HAS_ANNOTATE_TABLEJUMP
302+
depends on RUST
303+
def_bool $(rustc-option,-Cllvm-args=--loongarch-annotate-tablejump)
304+
301305
menu "Kernel type and options"
302306

303307
source "kernel/Kconfig.hz"

arch/loongarch/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ KBUILD_CFLAGS += -mannotate-tablejump
106106
else
107107
KBUILD_CFLAGS += -fno-jump-tables # keep compatibility with older compilers
108108
endif
109+
ifdef CONFIG_RUSTC_HAS_ANNOTATE_TABLEJUMP
110+
KBUILD_RUSTFLAGS += -Cllvm-args=--loongarch-annotate-tablejump
111+
else
112+
KBUILD_RUSTFLAGS += -Zno-jump-tables # keep compatibility with older compilers
113+
endif
109114
ifdef CONFIG_LTO_CLANG
110115
# The annotate-tablejump option can not be passed to LLVM backend when LTO is enabled.
111116
# Ensure it is aware of linker with LTO, '--loongarch-annotate-tablejump' also needs to

0 commit comments

Comments
 (0)