From nobody Fri Oct 3 10:13:37 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E339E2F28F0; Wed, 3 Sep 2025 09:53:31 +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=1756893214; cv=none; b=SXV+YZsykN2HVa+5gdBbxW1YVwzuaimgBFzbqFl2RIIoy1Dc2m5S7u98guNYYuzvYc9vIMBbqu7t3mChWgdFrJYIR/O/PpASOA6psUC5JDERGVMlT8xchzxD/vdCyQlXvo5JUd+vAkqY+tI12C6rCgp6iiWsj6+TliA9IfrA36g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756893214; c=relaxed/simple; bh=PuAfWmWmu4+nzyctL9OZNVJZoNyu+8EySupeLi2tGKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L9NuQIHMr0XlxBhkyqUtnoYqOkhx0uLUJPxU/i6/ID6kdQN/Xxp3Qcd6fuobexj3OAqPYEuA9IkagRz0lzi8h6tQeUkJRpHNJLXnD4uLm3CZ0dr0j4UCJDK9671Wq46UM9BVfqfDATa+vcwefMOQtG/m7L+1Dp2dJY/1eGGC0fM= 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 _____8Bx1tAUELho8i0GAA--.12914S3; Wed, 03 Sep 2025 17:53:24 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowJAxfcEMELhom_16AA--.5842S5; Wed, 03 Sep 2025 17:53:24 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Miguel Ojeda Cc: WANG Rui , rust-for-linux@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] LoongArch: Handle table jump option for RUST Date: Wed, 3 Sep 2025 17:53:15 +0800 Message-ID: <20250903095315.15057-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20250903095315.15057-1-yangtiezhu@loongson.cn> References: <20250903095315.15057-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: qMiowJAxfcEMELhom_16AA--.5842S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZF4rtrW5uF4fJrWrZr1DurX_yoW5ZF1xpw nru3s5tr4rGFn7t39xJayUWr4rJrnxtw13XFs7G348Aay7X34UZrs2y3srXFy8AwnxW3yS qryrK3y3KFWDC3XCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv67AK xVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUcCD7UUUUU Content-Type: text/plain; charset="utf-8" When compiling with LLVM and CONFIG_RUST is set, there exist objtool warnings "sibling call from callable instruction with modified stack frame" in rust/core.o and rust/kernel.o. 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. If the rustc has the option "-Cllvm-args=3D--loongarch-annotate-tablejump", pass the option to enable jump table for objtool, otherwise it is better to remain -Zno-jump-tables to keep compatibility with older rustc. How to test: (1) Please install rustc 1.78.0 (without annotate-tablejump option) or 1.87.0 (with annotate-tablejump option), do not use the latest version for now, otherwise there may be build error: --> rust/kernel/lib.rs:331:13 | 331 | loc.file_with_nul() | ^^^^^^^^^^^^^ method not found in `&'a Location<'a>` error: aborting due to 1 previous error (2) Execute the following command: $ rustup component add rust-src $ make LLVM=3D1 rustavailable $ make ARCH=3Dloongarch LLVM=3D1 clean defconfig $ scripts/config -d MODVERSIONS \ -e RUST -e SAMPLES -e SAMPLES_RUST \ -e SAMPLE_RUST_CONFIGFS -e SAMPLE_RUST_MINIMAL \ -e SAMPLE_RUST_MISC_DEVICE -e SAMPLE_RUST_PRINT \ -e SAMPLE_RUST_DMA -e SAMPLE_RUST_DRIVER_PCI \ -e SAMPLE_RUST_DRIVER_PLATFORM -e SAMPLE_RUST_DRIVER_FAUX \ -e SAMPLE_RUST_DRIVER_AUXILIARY -e SAMPLE_RUST_HOSTPROGS $ make ARCH=3Dloongarch LLVM=3D1 olddefconfig all Suggested-by: WANG Rui Signed-off-by: Tiezhu Yang --- arch/loongarch/Kconfig | 4 ++++ arch/loongarch/Makefile | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index f0abc38c40ac..57933a717e92 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -298,6 +298,10 @@ config AS_HAS_LVZ_EXTENSION config CC_HAS_ANNOTATE_TABLEJUMP def_bool $(cc-option,-mannotate-tablejump) =20 +config RUSTC_HAS_ANNOTATE_TABLEJUMP + depends on RUST + def_bool $(rustc-option,-Cllvm-args=3D--loongarch-annotate-tablejump) + menu "Kernel type and options" =20 source "kernel/Kconfig.hz" diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 9d80af7f75c8..b26d47707031 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -106,6 +106,12 @@ KBUILD_CFLAGS +=3D -mannotate-tablejump else KBUILD_CFLAGS +=3D -fno-jump-tables # keep compatibility with older comp= ilers endif +ifdef CONFIG_RUSTC_HAS_ANNOTATE_TABLEJUMP +# Pass '--loongarch-annotate-tablejump' via '-Cllvm-args' to rustc when RU= ST is enabled. +KBUILD_RUSTFLAGS +=3D -Cllvm-args=3D--loongarch-annotate-tablejump +else +KBUILD_RUSTFLAGS +=3D -Zno-jump-tables # keep compatibility with older co= mpilers +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 --=20 2.42.0