Re: [PATCH v1 1/2] LoongArch: Make LTO case independent in Makefile

From: Tiezhu Yang

Date: Sat Sep 20 2025 - 08:54:11 EST


On 9/20/25 19:41, Huacai Chen wrote:
...

We need to handle the other case to use -fno-jump-tables if llvm does
not support -loongarch-annotate-tablejump.

So, it is better to update the minimal version of llvm to 20, which
includes the following two important commits:

[LoongArch] Add options for annotate tablejump
https://github.com/llvm/llvm-project/commit/4c2c17756739

[LoongArch] Avoid indirect branch jumps using the ra register
https://github.com/llvm/llvm-project/commit/21ef17c62645

If you are OK, I will send a patch to modify the following file:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/min-tool-version.sh#n29


and keep arch/loongarch/Makefile as is.

The other way is to keep scripts/min-tool-version.sh as is, and only
modify arch/loongarch/Makefile, something like this (not tested):

config LLD_HAS_ANNOTATE_TABLEJUMP
def_bool LLD_VERSION >= 200000

ifdef CONFIG_LTO_CLANG
ifdef CONFIG_LLD_HAS_ANNOTATE_TABLEJUMP
KBUILD_LDFLAGS += -mllvm --loongarch-annotate-tablejump
else
KBUILD_LDFLAGS += -mllvm --no-jump-tables
endif
So complicated?

I think below is enough, no?
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
# be passed via '-mllvm' to ld.lld.
KBUILD_LDFLAGS += $(call ld-option,-mllvm
--loongarch-annotate-tablejump,-mllvm --no-jump-tables)
endif

I do not know whether this is valid, you can test it with llvm 18
and llvm 20 if you think it is a proper way.

But IIRC, there is objtool warning with llvm 18, I reported to llvm
developer Wang Lei and he fixed it as the following commit:

[LoongArch] Avoid indirect branch jumps using the ra register
https://github.com/llvm/llvm-project/commit/21ef17c62645

Actually, the above commit solved a performance issue of llvm compiler,
so I prefer to update the minimal llvm version to 20 for LoongArch.

Thanks,
Tiezhu