[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAhV-H5wW_04NHQ7z+SCPb6-T5Hc__n+x=ykg-u9vn4b4GXuww@mail.gmail.com>
Date: Tue, 26 Aug 2025 16:32:46 +0800
From: Huacai Chen <chenhuacai@...nel.org>
To: Tiezhu Yang <yangtiezhu@...ngson.cn>
Cc: Josh Poimboeuf <jpoimboe@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
Nathan Chancellor <nathan@...nel.org>, loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH 1/2] objtool/LoongArch: Fix fall through warning about efi_boot_kernel()
On Tue, Aug 26, 2025 at 2:46 PM Tiezhu Yang <yangtiezhu@...ngson.cn> wrote:
>
> When compiling with LLVM and CONFIG_LTO_CLANG is set, there exists
> the following objtool warning:
>
> vmlinux.o: warning: objtool: __efistub_efi_boot_kernel()
> falls through to next function __efistub_exit_boot_func()
>
> This is because efi_boot_kernel() doesn't end with a return instruction
> or an unconditional jump, then objtool has determined that the function
> can fall through into the next function.
>
> Actually, efi_boot_kernel()'s last instruction is "jirl $ra, $a3, 0", it
> is a call to a noreturn function pointer real_kernel_entry() which points
> to the symbol kernel_entry() in arch/loongarch/kernel/head.S.
>
> drivers/firmware/efi/libstub/loongarch.c:
>
> typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
> unsigned long systab);
>
> efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
> unsigned long kernel_addr, char *cmdline_ptr)
> {
> kernel_entry_t real_kernel_entry;
> ...
> real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image);
>
> real_kernel_entry(true, (unsigned long)cmdline_ptr,
> (unsigned long)efi_system_table);
> }
>
> According to the description of tools/objtool/Documentation/objtool.txt,
> in order to silence this warning, at the beginning just add the noreturn
> real_kernel_entry() to objtool's hard-coded global_noreturns array, but
> there is no effect, because it is not a valid symbol.
>
> There exists an alternative way to silence this warning, the first thing
> is to remove the attribute __noreturn for real_kernel_entry(), otherwise
> the compiler can not generate instructions after that, and then just add
> "while (1);" at the end of efi_boot_kernel(), so that efi_boot_kernel()
> ends with an unconditional jump instruction "b".
>
> Note that at the end of efi_boot_kernel(), using unreachable() has no
> effect because it can still generate fall-through code, using BUG() is
> not proper because it will generate the following ld.lld warning:
>
> vmlinux.o:(.init__bug_table) is being placed in '.init__bug_table'
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
> ---
> drivers/firmware/efi/libstub/loongarch.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
> index 3782d0a187d1..e309fd78fca7 100644
> --- a/drivers/firmware/efi/libstub/loongarch.c
> +++ b/drivers/firmware/efi/libstub/loongarch.c
> @@ -10,7 +10,7 @@
> #include "efistub.h"
> #include "loongarch-stub.h"
>
> -typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
> +typedef void (*kernel_entry_t)(bool efi, unsigned long cmdline,
> unsigned long systab);
>From my point of view this is incorrect, this function is indeed a
noreturn function, and this modification makes LoongArch different to
other architectures.
Maybe it is better to let objtool ignore the whole
drivers/firmware/efi/libstub directory. Because efistub is discarded
at runtime so it is useless for stack unwinder.
Huacai
>
> efi_status_t check_platform_features(void)
> @@ -81,4 +81,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
>
> real_kernel_entry(true, (unsigned long)cmdline_ptr,
> (unsigned long)efi_system_table);
> +
> + /* We should never get here */
> + while (1);
> }
> --
> 2.42.0
>
Powered by blists - more mailing lists