All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch
@ 2025-08-12 13:27 Tiezhu Yang
  2025-08-12 13:27 ` [PATCH 1/2] objtool/LoongArch: Get table size correctly if LTO is enabled Tiezhu Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tiezhu Yang @ 2025-08-12 13:27 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen, Nathan Chancellor
  Cc: loongarch, linux-kernel

The patch #1 should be a preparation for patch #2, that is to say,
the patch #2 is dependent on the patch #1, otherwise there is build
error if LTO is enabled after only applying patch #2.

With this series, most of warnings have been silenced, only remains
the following warning by now, it needs more analysis:

  vmlinux.o: warning: objtool: __efistub_efi_boot_kernel() falls through
  to next function __efistub_exit_boot_func()

How to reproduce:

  $ make ARCH=loongarch LLVM=1 clean defconfig
  $ scripts/config -d LTO_NONE -e LTO_CLANG_THIN
  $ make ARCH=loongarch LLVM=1 olddefconfig all

Tiezhu Yang (2):
  objtool/LoongArch: Get table size correctly if LTO is enabled
  LoongArch: Pass annotate-tablejump option if LTO is enabled

 arch/loongarch/Makefile                |  6 ++++++
 tools/objtool/arch/loongarch/special.c | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] objtool/LoongArch: Get table size correctly if LTO is enabled
  2025-08-12 13:27 [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Tiezhu Yang
@ 2025-08-12 13:27 ` Tiezhu Yang
  2025-08-12 13:27 ` [PATCH 2/2] LoongArch: Pass annotate-tablejump option " Tiezhu Yang
  2025-08-14 23:01 ` [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Nathan Chancellor
  2 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2025-08-12 13:27 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen, Nathan Chancellor
  Cc: loongarch, linux-kernel

When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist
many objtool warnings "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.

It needs to do something on the LLVM side to make sure that there is
the relocation section '.rela.discard.tablejump_annotate' if LTO is
enabled, but in order to maintain compatibility for the current LLVM
compiler, this can be done in the kernel Makefile for now. Ensure it
is aware of linker with LTO, '--loongarch-annotate-tablejump' needs
to be passed via '-mllvm' to ld.lld.

Before doing the above changes, it should handle the special case of
the relocation section '.rela.discard.tablejump_annotate' to get the
correct table size first, otherwise there are many objtool warnings
and errors if LTO is enabled.

There are many different rodata for each function if LTO is enabled,
it is necessary to enhance get_rodata_table_size_by_table_annotate().

Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/loongarch/20250731175655.GA1455142@ax162/
Fixes: b95f852d3af2 ("objtool/LoongArch: Add support for switch table")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/arch/loongarch/special.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/special.c
index e39f86d97002..a80b75f7b061 100644
--- a/tools/objtool/arch/loongarch/special.c
+++ b/tools/objtool/arch/loongarch/special.c
@@ -27,6 +27,7 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
 	struct table_info *next_table;
 	unsigned long tmp_insn_offset;
 	unsigned long tmp_rodata_offset;
+	bool is_valid_list = false;
 
 	rsec = find_section_by_name(file->elf, ".rela.discard.tablejump_annotate");
 	if (!rsec)
@@ -35,6 +36,12 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
 	INIT_LIST_HEAD(&table_list);
 
 	for_each_reloc(rsec, reloc) {
+		if (reloc->sym->sec->rodata)
+			continue;
+
+		if (strcmp(insn->sec->name, reloc->sym->sec->name))
+			continue;
+
 		orig_table = malloc(sizeof(struct table_info));
 		if (!orig_table) {
 			WARN("malloc failed");
@@ -49,6 +56,22 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
 
 		if (reloc_idx(reloc) + 1 == sec_num_entries(rsec))
 			break;
+
+		if (strcmp(insn->sec->name, (reloc + 1)->sym->sec->name)) {
+			list_for_each_entry(orig_table, &table_list, jump_info) {
+				if (orig_table->insn_offset == insn->offset) {
+					is_valid_list = true;
+					break;
+				}
+			}
+
+			if (!is_valid_list) {
+				list_del_init(&table_list);
+				continue;
+			}
+
+			break;
+		}
 	}
 
 	list_for_each_entry(orig_table, &table_list, jump_info) {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] LoongArch: Pass annotate-tablejump option if LTO is enabled
  2025-08-12 13:27 [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Tiezhu Yang
  2025-08-12 13:27 ` [PATCH 1/2] objtool/LoongArch: Get table size correctly if LTO is enabled Tiezhu Yang
@ 2025-08-12 13:27 ` Tiezhu Yang
  2025-08-14 23:01 ` [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Nathan Chancellor
  2 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2025-08-12 13:27 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen, Nathan Chancellor
  Cc: loongarch, linux-kernel

When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist
many objtool warnings "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.

It needs to do something on the LLVM side to make sure that there is
the relocation section '.rela.discard.tablejump_annotate' if LTO is
enabled, but in order to maintain compatibility for the current LLVM
compiler, this can be done in the kernel Makefile for now. Ensure it
is aware of linker with LTO, '--loongarch-annotate-tablejump' needs
to be passed via '-mllvm' to ld.lld.

Note that it should also pass the compiler option -mannotate-tablejump
rather than only pass '-mllvm --loongarch-annotate-tablejump' to ld.lld
if LTO is enabled, otherwise there are no jump info for some table jump
instructions.

Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/loongarch/20250731175655.GA1455142@ax162/
Fixes: e20ab7d454ee ("LoongArch: Enable jump table for objtool")
Co-developed-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index b0703a4e02a2..6cdbcbbe730e 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -103,6 +103,12 @@ 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
+# 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' needs to be
+# passed via '-mllvm' to ld.lld.
+ifdef CONFIG_LTO_CLANG
+KBUILD_LDFLAGS			+= -mllvm --loongarch-annotate-tablejump
+endif
 else
 KBUILD_CFLAGS			+= -fno-jump-tables # keep compatibility with older compilers
 endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch
  2025-08-12 13:27 [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Tiezhu Yang
  2025-08-12 13:27 ` [PATCH 1/2] objtool/LoongArch: Get table size correctly if LTO is enabled Tiezhu Yang
  2025-08-12 13:27 ` [PATCH 2/2] LoongArch: Pass annotate-tablejump option " Tiezhu Yang
@ 2025-08-14 23:01 ` Nathan Chancellor
  2025-08-16 14:59   ` Huacai Chen
  2 siblings, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2025-08-14 23:01 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Josh Poimboeuf, Peter Zijlstra, Huacai Chen, loongarch,
	linux-kernel

On Tue, Aug 12, 2025 at 09:27:14PM +0800, Tiezhu Yang wrote:
> The patch #1 should be a preparation for patch #2, that is to say,
> the patch #2 is dependent on the patch #1, otherwise there is build
> error if LTO is enabled after only applying patch #2.

Thanks, these two patches do indeed resolve most of the warnings that I
see.

Tested-by: Nathan Chancellor <nathan@kernel.org>

> With this series, most of warnings have been silenced, only remains
> the following warning by now, it needs more analysis:
> 
>   vmlinux.o: warning: objtool: __efistub_efi_boot_kernel() falls through
>   to next function __efistub_exit_boot_func()

Yes, I do see this one too. Odd, as efi_boot_kernel() ends in a
__noreturn function...

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch
  2025-08-14 23:01 ` [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Nathan Chancellor
@ 2025-08-16 14:59   ` Huacai Chen
  2025-08-18  3:48     ` Tiezhu Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Huacai Chen @ 2025-08-16 14:59 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, loongarch,
	linux-kernel

On Fri, Aug 15, 2025 at 7:01 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Tue, Aug 12, 2025 at 09:27:14PM +0800, Tiezhu Yang wrote:
> > The patch #1 should be a preparation for patch #2, that is to say,
> > the patch #2 is dependent on the patch #1, otherwise there is build
> > error if LTO is enabled after only applying patch #2.
>
> Thanks, these two patches do indeed resolve most of the warnings that I
> see.
>
> Tested-by: Nathan Chancellor <nathan@kernel.org>
>
> > With this series, most of warnings have been silenced, only remains
> > the following warning by now, it needs more analysis:
> >
> >   vmlinux.o: warning: objtool: __efistub_efi_boot_kernel() falls through
> >   to next function __efistub_exit_boot_func()
>
> Yes, I do see this one too. Odd, as efi_boot_kernel() ends in a
> __noreturn function...
But this one only exists for LTO?

Huacai

>
> Cheers,
> Nathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch
  2025-08-16 14:59   ` Huacai Chen
@ 2025-08-18  3:48     ` Tiezhu Yang
  0 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2025-08-18  3:48 UTC (permalink / raw)
  To: Huacai Chen, Nathan Chancellor
  Cc: Josh Poimboeuf, Peter Zijlstra, loongarch, linux-kernel

On 2025/8/16 下午10:59, Huacai Chen wrote:
> On Fri, Aug 15, 2025 at 7:01 AM Nathan Chancellor <nathan@kernel.org> wrote:
>>
>> On Tue, Aug 12, 2025 at 09:27:14PM +0800, Tiezhu Yang wrote:
>>> The patch #1 should be a preparation for patch #2, that is to say,
>>> the patch #2 is dependent on the patch #1, otherwise there is build
>>> error if LTO is enabled after only applying patch #2.
>>
>> Thanks, these two patches do indeed resolve most of the warnings that I
>> see.
>>
>> Tested-by: Nathan Chancellor <nathan@kernel.org>
>>
>>> With this series, most of warnings have been silenced, only remains
>>> the following warning by now, it needs more analysis:
>>>
>>>    vmlinux.o: warning: objtool: __efistub_efi_boot_kernel() falls through
>>>    to next function __efistub_exit_boot_func()
>>
>> Yes, I do see this one too. Odd, as efi_boot_kernel() ends in a
>> __noreturn function...
> But this one only exists for LTO?

Yes, this is true.

I have fixed this warning and the other new warnings locally,
will do more testing before sending patches.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-18  3:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 13:27 [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Tiezhu Yang
2025-08-12 13:27 ` [PATCH 1/2] objtool/LoongArch: Get table size correctly if LTO is enabled Tiezhu Yang
2025-08-12 13:27 ` [PATCH 2/2] LoongArch: Pass annotate-tablejump option " Tiezhu Yang
2025-08-14 23:01 ` [PATCH 0/2] Fix objtool warnings if LTO is enabled for LoongArch Nathan Chancellor
2025-08-16 14:59   ` Huacai Chen
2025-08-18  3:48     ` Tiezhu Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.