From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>,
Nathan Chancellor <nathan@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>, WANG Rui <wangrui@loongson.cn>,
rust-for-linux@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v1 1/2] LoongArch: Make LTO case independent in Makefile
Date: Sat, 20 Sep 2025 18:22:11 +0800 [thread overview]
Message-ID: <7eafa4a6-55bf-2fcb-19ef-b18bd51bfd39@loongson.cn> (raw)
In-Reply-To: <c9c4c0e6-946d-95de-9c03-a4b8e1636b81@loongson.cn>
On 9/20/25 17:19, Tiezhu Yang wrote:
> On 9/20/25 16:23, Huacai Chen wrote:
>> On Sat, Sep 20, 2025 at 2:15 PM Nathan Chancellor <nathan@kernel.org>
>> wrote:
>>>
>>> Hi Tiezhu,
>>>
>>> On Tue, Sep 09, 2025 at 05:27:06PM +0800, Tiezhu Yang wrote:
>>>> LTO is not only used for Clang, it maybe used for Rust, make LTO
>>>> case out
>>>> of CONFIG_CC_HAS_ANNOTATE_TABLEJUMP in Makefile.
>>>>
>>>> This is preparation for later patch, no function changes.
>>>>
>>>> Suggested-by: WANG Rui <wangrui@loongson.cn>
>>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>>> ---
>>>> arch/loongarch/Makefile | 10 +++++-----
>>>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
>>>> index a3a9759414f4..9d80af7f75c8 100644
>>>> --- a/arch/loongarch/Makefile
>>>> +++ b/arch/loongarch/Makefile
>>>> @@ -102,16 +102,16 @@ KBUILD_CFLAGS += $(call
>>>> cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)
>>>>
>>>> ifdef CONFIG_OBJTOOL
>>>> ifdef CONFIG_CC_HAS_ANNOTATE_TABLEJUMP
>>>> +KBUILD_CFLAGS += -mannotate-tablejump
>>>> +else
>>>> +KBUILD_CFLAGS += -fno-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
>>>> # be passed via '-mllvm' to ld.lld.
>>>> -KBUILD_CFLAGS += -mannotate-tablejump
>>>> -ifdef CONFIG_LTO_CLANG
>>>> KBUILD_LDFLAGS += -mllvm
>>>> --loongarch-annotate-tablejump
>>>> endif
>>>> -else
>>>> -KBUILD_CFLAGS += -fno-jump-tables # keep
>>>> compatibility with older compilers
>>>> -endif
>>>> endif
>>>>
>>>> KBUILD_RUSTFLAGS +=
>>>> --target=loongarch64-unknown-none-softfloat -Ccode-model=small
>>>> --
>>>> 2.42.0
>>>>
>>>
>>> This change is now in -next as commit b15212824a01 ("LoongArch: Make LTO
>>> case independent in Makefile"), where it breaks the build for clang-18,
>>> as '--loongarch-annotate-tablejump' is unimplemented there but there is
>>> no version check before using it.
>>>
>>> $ make -skj"$(nproc)" ARCH=loongarch LLVM=1 mrproper defconfig
>>>
>>> $ scripts/config -d LTO_NONE -e LTO_CLANG_THIN
>>>
>>> $ make -skj"$(nproc)" ARCH=loongarch LLVM=1 olddefconfig vmlinuz.efi
>>> ld.lld: error: -mllvm: ld.lld: Unknown command line argument
>>> '--loongarch-annotate-tablejump'.
>>> ...
>>>
>>> $ scripts/config -s CC_HAS_ANNOTATE_TABLEJUMP
>>> undef
>> Hmm, maybe we need this?
>> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
>> index ae419e32f22e..fcfa793f9bb0 100644
>> --- a/arch/loongarch/Makefile
>> +++ b/arch/loongarch/Makefile
>> @@ -115,7 +115,7 @@ 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 += -mllvm
>> --loongarch-annotate-tablejump
>> +KBUILD_LDFLAGS += $(call ld-option,-mllvm
>> --loongarch-annotate-tablejump)
>> endif
>> endif
>
> 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
Update the minimal llvm version or change Makefile to compat various
llvm versions, which one do you prefer? Pease let me know.
Thanks,
Tiezhu
next prev parent reply other threads:[~2025-09-20 10:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 9:27 [PATCH v1 0/2] Fix objtool warnings with RUST on LoongArch Tiezhu Yang
2025-09-09 9:27 ` [PATCH v1 1/2] LoongArch: Make LTO case independent in Makefile Tiezhu Yang
2025-09-20 6:15 ` Nathan Chancellor
2025-09-20 8:23 ` Huacai Chen
2025-09-20 9:19 ` Tiezhu Yang
2025-09-20 10:22 ` Tiezhu Yang [this message]
2025-09-20 11:41 ` Huacai Chen
2025-09-20 12:52 ` Tiezhu Yang
2025-09-23 1:10 ` Nathan Chancellor
2025-09-23 3:13 ` Tiezhu Yang
2025-09-09 9:27 ` [PATCH v1 2/2] LoongArch: Handle jump tables option for RUST Tiezhu Yang
2025-09-09 10:16 ` Miguel Ojeda
2025-09-09 18:06 ` Matthew Maurer
2025-09-09 20:14 ` Miguel Ojeda
2025-09-18 9:15 ` [PATCH v1 0/2] Fix objtool warnings with RUST on LoongArch Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7eafa4a6-55bf-2fcb-19ef-b18bd51bfd39@loongson.cn \
--to=yangtiezhu@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wangrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox