[PATCH v2 3/4] objtool/LoongArch: Fix unreachable instruction warnings about entry points

Tiezhu Yang posted 4 patches 2 weeks, 1 day ago
There is a newer version of this series
[PATCH v2 3/4] objtool/LoongArch: Fix unreachable instruction warnings about entry points
Posted by Tiezhu Yang 2 weeks, 1 day ago
When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist the
following objtool warnings:

  vmlinux.o: warning: objtool: kernel_entry+0x0: unreachable instruction
  vmlinux.o: warning: objtool: smpboot_entry+0x0: unreachable instruction

kernel_entry() and smpboot_entry() are in arch/loongarch/kernel/head.S,
there is "OBJECT_FILES_NON_STANDARD_head.o := y" to skip objtool checking
for head.o, but the STACK_FRAME_NON_STANDARD macro does not work for link
time validation of vmlinux.o according to objtool documentation, just give
a proper unwind hint to fix the warnings.

By the way, ASM_BUG() can be removed due to unnecessary, otherwise there
are following warnings:

  kernel_entry+0xf4: start_kernel() missing __noreturn
  in .c/.h or NORETURN() in noreturns.h

  smpboot_entry+0x68: start_secondary() missing __noreturn
  in .c/.h or NORETURN() in noreturns.h

This is because the previous instructions of kernel_entry+0xf4 and
smpboot_entry+0x68 are the 'bl' instructions, start_kernel() and
start_secondary() are the respective call destination symbols which
are noreturn functions, then the 'bl' instructions are already marked
as dead end in annotate_call_site().

For now, it is time to remove "OBJECT_FILES_NON_STANDARD_head.o := y"
in arch/loongarch/kernel/Makefile.

Link: https://lore.kernel.org/lkml/20250814083651.GR4067720@noisy.programming.kicks-ass.net/
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/kernel/Makefile | 2 --
 arch/loongarch/kernel/head.S   | 6 ++----
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile
index 6f5a4574a911..4302c5b0a201 100644
--- a/arch/loongarch/kernel/Makefile
+++ b/arch/loongarch/kernel/Makefile
@@ -3,8 +3,6 @@
 # Makefile for the Linux/LoongArch kernel.
 #
 
-OBJECT_FILES_NON_STANDARD_head.o := y
-
 always-$(KBUILD_BUILTIN)	:= vmlinux.lds
 
 obj-y		+= head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
index 6ce999586757..c62dab32a06b 100644
--- a/arch/loongarch/kernel/head.S
+++ b/arch/loongarch/kernel/head.S
@@ -43,6 +43,7 @@ SYM_DATA(kernel_fsize, .long _kernel_fsize);
 	.align 12
 
 SYM_CODE_START(kernel_entry)			# kernel entry point
+	UNWIND_HINT_END_OF_STACK
 
 	/* Config direct window and set PG */
 	SETUP_DMWINS	t0
@@ -110,8 +111,6 @@ SYM_CODE_START(kernel_entry)			# kernel entry point
 #endif
 
 	bl		start_kernel
-	ASM_BUG()
-
 SYM_CODE_END(kernel_entry)
 
 #ifdef CONFIG_SMP
@@ -121,6 +120,7 @@ SYM_CODE_END(kernel_entry)
  * function after setting up the stack and tp registers.
  */
 SYM_CODE_START(smpboot_entry)
+	UNWIND_HINT_END_OF_STACK
 
 	SETUP_DMWINS	t0
 	JUMP_VIRT_ADDR	t0, t1
@@ -143,8 +143,6 @@ SYM_CODE_START(smpboot_entry)
 	ld.d		tp, t0, CPU_BOOT_TINFO
 
 	bl		start_secondary
-	ASM_BUG()
-
 SYM_CODE_END(smpboot_entry)
 
 #endif /* CONFIG_SMP */
-- 
2.42.0
Re: [PATCH v2 3/4] objtool/LoongArch: Fix unreachable instruction warnings about entry points
Posted by Huacai Chen 2 weeks, 1 day ago
Hi, Tiezhu,

On Wed, Sep 17, 2025 at 9:10 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist the
> following objtool warnings:
>
>   vmlinux.o: warning: objtool: kernel_entry+0x0: unreachable instruction
>   vmlinux.o: warning: objtool: smpboot_entry+0x0: unreachable instruction
>
> kernel_entry() and smpboot_entry() are in arch/loongarch/kernel/head.S,
> there is "OBJECT_FILES_NON_STANDARD_head.o := y" to skip objtool checking
> for head.o, but the STACK_FRAME_NON_STANDARD macro does not work for link
> time validation of vmlinux.o according to objtool documentation, just give
> a proper unwind hint to fix the warnings.
>
> By the way, ASM_BUG() can be removed due to unnecessary, otherwise there
> are following warnings:
>
>   kernel_entry+0xf4: start_kernel() missing __noreturn
>   in .c/.h or NORETURN() in noreturns.h
>
>   smpboot_entry+0x68: start_secondary() missing __noreturn
>   in .c/.h or NORETURN() in noreturns.h
>
> This is because the previous instructions of kernel_entry+0xf4 and
> smpboot_entry+0x68 are the 'bl' instructions, start_kernel() and
> start_secondary() are the respective call destination symbols which
> are noreturn functions, then the 'bl' instructions are already marked
> as dead end in annotate_call_site().
>
> For now, it is time to remove "OBJECT_FILES_NON_STANDARD_head.o := y"
> in arch/loongarch/kernel/Makefile.
>
> Link: https://lore.kernel.org/lkml/20250814083651.GR4067720@noisy.programming.kicks-ass.net/
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  arch/loongarch/kernel/Makefile | 2 --
>  arch/loongarch/kernel/head.S   | 6 ++----
>  2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile
> index 6f5a4574a911..4302c5b0a201 100644
> --- a/arch/loongarch/kernel/Makefile
> +++ b/arch/loongarch/kernel/Makefile
> @@ -3,8 +3,6 @@
>  # Makefile for the Linux/LoongArch kernel.
>  #
>
> -OBJECT_FILES_NON_STANDARD_head.o := y
This line should be kept, othewise we get:

arch/loongarch/kernel/head.o: warning: objtool: kernel_entry+0xf4:
start_kernel() missing __noreturn in .c/.h or NORETURN() in
noreturns.h

even without LTO. This is a regression, we can only remove it after
the above warning be fixed.

Huacai
> -
>  always-$(KBUILD_BUILTIN)       := vmlinux.lds
>
>  obj-y          += head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
> diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
> index 6ce999586757..c62dab32a06b 100644
> --- a/arch/loongarch/kernel/head.S
> +++ b/arch/loongarch/kernel/head.S
> @@ -43,6 +43,7 @@ SYM_DATA(kernel_fsize, .long _kernel_fsize);
>         .align 12
>
>  SYM_CODE_START(kernel_entry)                   # kernel entry point
> +       UNWIND_HINT_END_OF_STACK
>
>         /* Config direct window and set PG */
>         SETUP_DMWINS    t0
> @@ -110,8 +111,6 @@ SYM_CODE_START(kernel_entry)                        # kernel entry point
>  #endif
>
>         bl              start_kernel
> -       ASM_BUG()
> -
>  SYM_CODE_END(kernel_entry)
>
>  #ifdef CONFIG_SMP
> @@ -121,6 +120,7 @@ SYM_CODE_END(kernel_entry)
>   * function after setting up the stack and tp registers.
>   */
>  SYM_CODE_START(smpboot_entry)
> +       UNWIND_HINT_END_OF_STACK
>
>         SETUP_DMWINS    t0
>         JUMP_VIRT_ADDR  t0, t1
> @@ -143,8 +143,6 @@ SYM_CODE_START(smpboot_entry)
>         ld.d            tp, t0, CPU_BOOT_TINFO
>
>         bl              start_secondary
> -       ASM_BUG()
> -
>  SYM_CODE_END(smpboot_entry)
>
>  #endif /* CONFIG_SMP */
> --
> 2.42.0
>
Re: [PATCH v2 3/4] objtool/LoongArch: Fix unreachable instruction warnings about entry points
Posted by Tiezhu Yang 2 weeks, 1 day ago
On 2025/9/17 下午3:07, Huacai Chen wrote:
> Hi, Tiezhu,
> 
> On Wed, Sep 17, 2025 at 9:10 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>> When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist the
>> following objtool warnings:
>>
>>    vmlinux.o: warning: objtool: kernel_entry+0x0: unreachable instruction
>>    vmlinux.o: warning: objtool: smpboot_entry+0x0: unreachable instruction
>>
>> kernel_entry() and smpboot_entry() are in arch/loongarch/kernel/head.S,
>> there is "OBJECT_FILES_NON_STANDARD_head.o := y" to skip objtool checking
>> for head.o, but the STACK_FRAME_NON_STANDARD macro does not work for link
>> time validation of vmlinux.o according to objtool documentation, just give
>> a proper unwind hint to fix the warnings.
>>
>> By the way, ASM_BUG() can be removed due to unnecessary, otherwise there
>> are following warnings:
>>
>>    kernel_entry+0xf4: start_kernel() missing __noreturn
>>    in .c/.h or NORETURN() in noreturns.h
>>
>>    smpboot_entry+0x68: start_secondary() missing __noreturn
>>    in .c/.h or NORETURN() in noreturns.h
>>
>> This is because the previous instructions of kernel_entry+0xf4 and
>> smpboot_entry+0x68 are the 'bl' instructions, start_kernel() and
>> start_secondary() are the respective call destination symbols which
>> are noreturn functions, then the 'bl' instructions are already marked
>> as dead end in annotate_call_site().
>>
>> For now, it is time to remove "OBJECT_FILES_NON_STANDARD_head.o := y"
>> in arch/loongarch/kernel/Makefile.

...

>> -OBJECT_FILES_NON_STANDARD_head.o := y
> This line should be kept, othewise we get:
> 
> arch/loongarch/kernel/head.o: warning: objtool: kernel_entry+0xf4:
> start_kernel() missing __noreturn in .c/.h or NORETURN() in
> noreturns.h
> 
> even without LTO. This is a regression, we can only remove it after
> the above warning be fixed.

As said in the commit message, ASM_BUG() needs to be removed
to fix the above warning.

I tested again with GCC and LLVM (with and without LTO),
there is no the warning what you said, please double check.

(1) GCC
make ARCH=loongarch defconfig
make ARCH=loongarch -j8

(2) LLVM without LTO
make ARCH=loongarch LLVM=1 clean defconfig
make ARCH=loongarch LLVM=1 olddefconfig all -j8

(3) LLVM with LTO
make ARCH=loongarch LLVM=1 clean defconfig
scripts/config -d LTO_NONE -e LTO_CLANG_THIN
make ARCH=loongarch LLVM=1 olddefconfig all -j8

Thanks,
Tiezhu

Re: [PATCH v2 3/4] objtool/LoongArch: Fix unreachable instruction warnings about entry points
Posted by Huacai Chen 2 weeks, 1 day ago
On Wed, Sep 17, 2025 at 5:47 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> On 2025/9/17 下午3:07, Huacai Chen wrote:
> > Hi, Tiezhu,
> >
> > On Wed, Sep 17, 2025 at 9:10 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> >>
> >> When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist the
> >> following objtool warnings:
> >>
> >>    vmlinux.o: warning: objtool: kernel_entry+0x0: unreachable instruction
> >>    vmlinux.o: warning: objtool: smpboot_entry+0x0: unreachable instruction
> >>
> >> kernel_entry() and smpboot_entry() are in arch/loongarch/kernel/head.S,
> >> there is "OBJECT_FILES_NON_STANDARD_head.o := y" to skip objtool checking
> >> for head.o, but the STACK_FRAME_NON_STANDARD macro does not work for link
> >> time validation of vmlinux.o according to objtool documentation, just give
> >> a proper unwind hint to fix the warnings.
> >>
> >> By the way, ASM_BUG() can be removed due to unnecessary, otherwise there
> >> are following warnings:
> >>
> >>    kernel_entry+0xf4: start_kernel() missing __noreturn
> >>    in .c/.h or NORETURN() in noreturns.h
> >>
> >>    smpboot_entry+0x68: start_secondary() missing __noreturn
> >>    in .c/.h or NORETURN() in noreturns.h
> >>
> >> This is because the previous instructions of kernel_entry+0xf4 and
> >> smpboot_entry+0x68 are the 'bl' instructions, start_kernel() and
> >> start_secondary() are the respective call destination symbols which
> >> are noreturn functions, then the 'bl' instructions are already marked
> >> as dead end in annotate_call_site().
> >>
> >> For now, it is time to remove "OBJECT_FILES_NON_STANDARD_head.o := y"
> >> in arch/loongarch/kernel/Makefile.
>
> ...
>
> >> -OBJECT_FILES_NON_STANDARD_head.o := y
> > This line should be kept, othewise we get:
> >
> > arch/loongarch/kernel/head.o: warning: objtool: kernel_entry+0xf4:
> > start_kernel() missing __noreturn in .c/.h or NORETURN() in
> > noreturns.h
> >
> > even without LTO. This is a regression, we can only remove it after
> > the above warning be fixed.
>
> As said in the commit message, ASM_BUG() needs to be removed
> to fix the above warning.
>
> I tested again with GCC and LLVM (with and without LTO),
> there is no the warning what you said, please double check.
I'm sorry, I was confused by the similar warnings described in this
patch and the cover letter.

Huacai

>
> (1) GCC
> make ARCH=loongarch defconfig
> make ARCH=loongarch -j8
>
> (2) LLVM without LTO
> make ARCH=loongarch LLVM=1 clean defconfig
> make ARCH=loongarch LLVM=1 olddefconfig all -j8
>
> (3) LLVM with LTO
> make ARCH=loongarch LLVM=1 clean defconfig
> scripts/config -d LTO_NONE -e LTO_CLANG_THIN
> make ARCH=loongarch LLVM=1 olddefconfig all -j8
>
> Thanks,
> Tiezhu
>