diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 2b5811b09..40701ce9f 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -295,6 +295,10 @@ config AS_HAS_LVZ_EXTENSION config CC_HAS_ANNOTATE_TABLEJUMP def_bool $(cc-option,-mannotate-tablejump) +config RUSTC_HAS_ANNOTATE_TABLEJUMP + depends on RUST + def_bool $(rustc-option,-Cllvm-args=--loongarch-annotate-tablejump) + if LOONGARCH choice diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 0ab8acb9f..f6e996217 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -107,6 +107,11 @@ KBUILD_CFLAGS += -mannotate-tablejump else KBUILD_CFLAGS += -fno-jump-tables # keep compatibility with older compilers endif +ifdef CONFIG_RUSTC_HAS_ANNOTATE_TABLEJUMP +KBUILD_RUSTFLAGS += -Cllvm-args=--loongarch-annotate-tablejump +else +KBUILD_RUSTFLAGS += -Zno-jump-tables # keep compatibility with older compilers +endif ifdef CONFIG_LTO_CLANG # The annotate-tablejump option can not be passed to LLVM backend when LTO is enabled. # Ensure it is aware of linker with LTO, '--loongarch-annotate-tablejump' also needs to