From nobody Fri Oct 3 20:29:59 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F0642641CA for ; Tue, 26 Aug 2025 06:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756190808; cv=none; b=XdM1tuHhfomr6+XwYJCYa8sLa2UD1qBhJr+RGca77Xd7YMO++NYTw1szvvux3LFKMxajXtbiQeFUfGliZf4OE3Y8ZQ9JtWjU/35VIN3GIuPKpPGt/iF2NwRMSYA9ivQbgq8uc4qlkHfsxfpiVdrVRJohVuoWxDByTsmKqtQ8Oek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756190808; c=relaxed/simple; bh=w0qS4kCOp7ylBVCxLD0AVRIRenhm1PIkxviGeN4Ri/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ardZsJs+RU3vzE5quWd/KuWTuFL6xUHB5up2FabU8Z9Rl4O129IE8sRihC1aFrs7DTwBMxAO3LJiWYv22z4OthnfCsfg6vDIzFGiMkZ8PWzyYiv0EzuXa9CUoXO/P1iqEfr2u+s79RSFES3NEA0KzPrJ7DsEpQ5r2a13KlAO0ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxxtBRWK1oJEEDAA--.6033S3; Tue, 26 Aug 2025 14:46:41 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowJBxTMFKWK1o6GppAA--.11160S3; Tue, 26 Aug 2025 14:46:40 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] objtool/LoongArch: Fix fall through warning about efi_boot_kernel() Date: Tue, 26 Aug 2025 14:46:30 +0800 Message-ID: <20250826064631.9617-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250826064631.9617-1-yangtiezhu@loongson.cn> References: <20250826064631.9617-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxTMFKWK1o6GppAA--.11160S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZF4rCF15tF13ury3Ar4rtFc_yoW5Cry7p3 WUCrWUWr4Fyrs7Aa48Jw4Y9ry3Zws7trWagasrXryrZanIqFsIvr4qvrnFvF4kAFWDKw4Y qFy8tr9Iya1DArcCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5 McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUxhiSDUUUU Content-Type: text/plain; charset="utf-8" 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 =3D (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 --- 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/ef= i/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" =20 -typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline, +typedef void (*kernel_entry_t)(bool efi, unsigned long cmdline, unsigned long systab); =20 efi_status_t check_platform_features(void) @@ -81,4 +81,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_ima= ge_t *image, =20 real_kernel_entry(true, (unsigned long)cmdline_ptr, (unsigned long)efi_system_table); + + /* We should never get here */ + while (1); } --=20 2.42.0 From nobody Fri Oct 3 20:29:59 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C921C2BE04D for ; Tue, 26 Aug 2025 06:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756190814; cv=none; b=nn+VvhEU23PKgNlyMk5HVdDmLMSYESdIjV3/NGkGz0QiXFJenunLuRfEnm5sLuumL2bNMCZ2FgOIfyUWfYcF+Lvbp1kCN4BVNZOG/peZgCad+tfSSMl1v1s8nsfgf/vvNoOkRqwP5Y1huVSua8F9m8r13jM1BE3o+UXmyFJHz5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756190814; c=relaxed/simple; bh=dgpl0zeB4KxxDe5G6WIOvE+j+eCf/bjPv2bKqMCmsOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JWKz9WbIOty4E7ozixgys26r4YYaAi0c3x9koiJj4A5SfXatXR8jCxqGq/kLjiUjTSZFr9aZnJaldkIVdhiLdn6D7hqlgbnNjRkew9lgH+SIaH/IlawYUxzCkKaM2fpQVb9UXB9hiklnhA6NYetg/h0kJyqlpIpY8dgiGugAFY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8BxmdFVWK1oKUEDAA--.6381S3; Tue, 26 Aug 2025 14:46:45 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowJBxTMFKWK1o6GppAA--.11160S4; Tue, 26 Aug 2025 14:46:41 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] objtool/LoongArch: Fix unreachable instruction warnings about head.S Date: Tue, 26 Aug 2025 14:46:31 +0800 Message-ID: <20250826064631.9617-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250826064631.9617-1-yangtiezhu@loongson.cn> References: <20250826064631.9617-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxTMFKWK1o6GppAA--.11160S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZF45AFyUKw1fCF17tF4rCrX_yoWrtr4kpF 47CryUAFZ8uFWqvw4UGa1ag3yavan8Xr4qqF1UJa4ft3yq9as2q3Wvyr17JFyqqr4YgF4f Xr4UtrWqk3Wjy3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5 McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUxhiSDUUUU Content-Type: text/plain; charset="utf-8" When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist the following objtool warnings after silencing all of the other warnings: LD vmlinux.o vmlinux.o: warning: objtool: .head.text+0x0: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x18: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x38: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x3c: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x40: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x44: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x54: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x58: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x6c: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x84: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x94: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x9c: unreachable instruction vmlinux.o: warning: objtool: .head.text+0xc4: unreachable instruction vmlinux.o: warning: objtool: .head.text+0xf8: unreachable instruction vmlinux.o: warning: objtool: .head.text+0xfc: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x104: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x10c: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x11c: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x120: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x124: unreachable instruction vmlinux.o: warning: objtool: .head.text+0x144: unreachable instruction vmlinux.o: warning: objtool: kernel_entry+0x0: unreachable instruction vmlinux.o: warning: objtool: smpboot_entry+0x0: unreachable instruction All of the above instructions are in arch/loongarch/kernel/head.S, and there is "OBJECT_FILES_NON_STANDARD_head.o :=3D y" in Makefile to skip objtool checking for head.o, but OBJECT_FILES_NON_STANDARD does not work for link time validation of vmlinux.o according to tools/objtool/Documentation/objtool.txt. Just give a proper unwind hint to silence the above warnings. By the way, the previous instructions of kernel_entry+0xf4 and smpboot_entry+0x68 are the 'bl' instructions, the call destination symbols are start_kernel() and start_secondary() which are noreturn functions, then the 'bl' instructions are marked as dead end in annotate_call_site(), so actually 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 Link: https://lore.kernel.org/lkml/20250814083651.GR4067720@noisy.programmi= ng.kicks-ass.net/ Suggested-by: Peter Zijlstra Signed-off-by: Tiezhu Yang --- arch/loongarch/kernel/head.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S index e3865e92a917..566a1dbf5fa0 100644 --- a/arch/loongarch/kernel/head.S +++ b/arch/loongarch/kernel/head.S @@ -20,6 +20,7 @@ __HEAD =20 _head: + UNWIND_HINT_UNDEFINED .word IMAGE_DOS_SIGNATURE /* "MZ", MS-DOS header */ .org 0x8 .dword _kernel_entry /* Kernel entry point (physical address) */ @@ -30,6 +31,7 @@ _head: .long pe_header - _head /* Offset to the PE header */ =20 pe_header: + UNWIND_HINT_UNDEFINED __EFI_PE_HEADER =20 SYM_DATA(kernel_asize, .long _kernel_asize); @@ -42,6 +44,7 @@ SYM_DATA(kernel_fsize, .long _kernel_fsize); .align 12 =20 SYM_CODE_START(kernel_entry) # kernel entry point + UNWIND_HINT_UNDEFINED =20 /* Config direct window and set PG */ SETUP_DMWINS t0 @@ -109,8 +112,6 @@ SYM_CODE_START(kernel_entry) # kernel entry point #endif =20 bl start_kernel - ASM_BUG() - SYM_CODE_END(kernel_entry) =20 #ifdef CONFIG_SMP @@ -120,6 +121,7 @@ SYM_CODE_END(kernel_entry) * function after setting up the stack and tp registers. */ SYM_CODE_START(smpboot_entry) + UNWIND_HINT_UNDEFINED =20 SETUP_DMWINS t0 JUMP_VIRT_ADDR t0, t1 @@ -142,8 +144,6 @@ SYM_CODE_START(smpboot_entry) ld.d tp, t0, CPU_BOOT_TINFO =20 bl start_secondary - ASM_BUG() - SYM_CODE_END(smpboot_entry) =20 #endif /* CONFIG_SMP */ --=20 2.42.0