From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A89161C687 for ; Tue, 17 Dec 2024 01:09:11 +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=1734397754; cv=none; b=Dh9oa0CXId5LI0/zmvMwKI1qxi8ejEZU+0FZm8bDJ+AwvMQyfgFTZ/vHWiDxo6MuUf4cV4e66VICuesO7HgfvcA5wPiv9bPwef+fsJDgmgdYiMwuZ/kyIHLhBiCzsWOK7NcHXTi0zjbNajflV/VjnJmZugvQB+tkPhuHKZ96Zpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397754; c=relaxed/simple; bh=Ne6/TC/nupmtNSrpc7iFsVbWm9wIs+HkhWkyxpKiwbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j0MwnPwu0QG99Lqnp2QOePAdKr3iUNMh8OUV/0Bfr64Bv9LSNufXSPWV4Qg5idoeZCaBs0DNwRvBwKFD5fJ2i12QNgwouk8fcGhBIvvVltZSeKFK/XmM9xSIB3Jedxc5woiwGJgWJVS6Qvm99jhQUa/md8XEYfHT3WIlMM4awuY= 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 _____8CxCeE1z2BnEZdXAA--.39950S3; Tue, 17 Dec 2024 09:09:09 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S3; Tue, 17 Dec 2024 09:09:08 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/9] objtool: Handle various symbol types of rodata Date: Tue, 17 Dec 2024 09:08:57 +0800 Message-ID: <20241217010905.13054-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJFWDKF47Ww48JF18Gw1Dtwc_yoW5WrWDpF sxG3y5Kr4YvryxWwn7ta9YgFy3Gw4kWF17Jr4DKr1rZ3sFvr1rKFW2kr1ak3WDGrn2va17 XryY9ry3CF4DA3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8EoGPUUUUU== Content-Type: text/plain; charset="utf-8" In the relocation section ".rela.rodata" of each .o file compiled with LoongArch toolchain, there are various symbol types such as STT_NOTYPE, STT_OBJECT, STT_FUNC in addition to the usual STT_SECTION, it needs to use reloc symbol offset instead of reloc addend to find the destination instruction in find_jump_table() and add_jump_table(). For the most part, an absolute relocation type is used for rodata. In the case of STT_SECTION, reloc->sym->offset is always zero, and for the other symbol types, reloc_addend(reloc) is always zero, thus it can use a simple statement "reloc->sym->offset + reloc_addend(reloc)" to obtain the symbol offset for various symbol types. Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e92c5564d9ca..f64435ad3514 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1953,6 +1953,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, unsigned int prev_offset =3D 0; struct reloc *reloc =3D table; struct alternative *alt; + unsigned long sym_offset; =20 /* * Each @reloc is a switch table relocation which points to the target @@ -1970,12 +1971,13 @@ static int add_jump_table(struct objtool_file *file= , struct instruction *insn, if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) break; =20 + sym_offset =3D reloc->sym->offset + reloc_addend(reloc); + /* Detect function pointers from contiguous objects: */ - if (reloc->sym->sec =3D=3D pfunc->sec && - reloc_addend(reloc) =3D=3D pfunc->offset) + if (reloc->sym->sec =3D=3D pfunc->sec && sym_offset =3D=3D pfunc->offset) break; =20 - dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + dest_insn =3D find_insn(file, reloc->sym->sec, sym_offset); if (!dest_insn) break; =20 @@ -2013,6 +2015,7 @@ static void find_jump_table(struct objtool_file *file= , struct symbol *func, struct reloc *table_reloc; struct instruction *dest_insn, *orig_insn =3D insn; unsigned long table_size; + unsigned long sym_offset; =20 /* * Backward search using the @first_jump_src links, these help avoid @@ -2036,7 +2039,10 @@ static void find_jump_table(struct objtool_file *fil= e, struct symbol *func, table_reloc =3D arch_find_switch_table(file, insn, &table_size); if (!table_reloc) continue; - dest_insn =3D find_insn(file, table_reloc->sym->sec, reloc_addend(table_= reloc)); + + sym_offset =3D table_reloc->sym->offset + reloc_addend(table_reloc); + + dest_insn =3D find_insn(file, table_reloc->sym->sec, sym_offset); if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) continue; =20 --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB3441E505 for ; Tue, 17 Dec 2024 01:09:11 +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=1734397755; cv=none; b=nrO5V/cnJffsWiZoiwsX7T4iekhA0RB07DMM9TPuhH1SNSzgZjzR8O3v7x5DFOFkCZnTBs4OaYcoY+V7WccJlUlHQBAw7SnMituikWZKe6acHzrkCIuVfvIoiPn2ACjWrV/vs7g35vPqQTo28PhjAbNmOo8mXU0pDaZrftm1eJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397755; c=relaxed/simple; bh=H2cVipSU0t1QDSrSgrjUYf7IFdVRIWlo06hayQCJNeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IZA921ghKumpjP5GgiLJ9qkvmqgd7++GOMG7RCpj4IJvnh+RxO8sUzW7eg6C4sSwU+LEyS0jKWTh2IZ+WgKLoNYariCIwjhRGfo6pG/ljzJlosen5AOsCeIGW0QDPeVoa6P6t/d03oHLoXdz0TJsHHlcJdUzGPLVs/gbdurHmzI= 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 _____8AxaeE2z2BnGJdXAA--.39348S3; Tue, 17 Dec 2024 09:09:10 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S4; Tue, 17 Dec 2024 09:09:09 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 2/9] objtool: Handle different entry size of rodata Date: Tue, 17 Dec 2024 09:08:58 +0800 Message-ID: <20241217010905.13054-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4DWw1DJrW3AFy8AFy7Jwc_yoW5KFyUpF srA3yfGr1jgryfJwnxt3W8Wa98Gas7WryIgFZrtry8ZrW7XrnxJr4IvFy5tF10vw4FgayS gFsYgF1UJF4qywcCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0epB3UUUUU== Content-Type: text/plain; charset="utf-8" In the most cases, the entry size of rodata is 8 bytes because the relocation type is 64 bit. There are also 32 bit relocation types, the entry size of rodata should be 4 bytes in this case. Add an arch-specific function arch_reloc_size() to assign the entry size of rodata for x86, powerpc and LoongArch. Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/arch/loongarch/decode.c | 11 +++++++++++ tools/objtool/arch/powerpc/decode.c | 15 +++++++++++++++ tools/objtool/arch/x86/decode.c | 13 +++++++++++++ tools/objtool/check.c | 2 +- tools/objtool/include/objtool/arch.h | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 69b66994f2a1..b64205b89f6b 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -363,3 +363,14 @@ void arch_initial_func_cfi_state(struct cfi_init_state= *state) state->cfa.base =3D CFI_SP; state->cfa.offset =3D 0; } + +unsigned int arch_reloc_size(struct reloc *reloc) +{ + switch (reloc_type(reloc)) { + case R_LARCH_32: + case R_LARCH_32_PCREL: + return 4; + default: + return 8; + } +} diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 53b55690f320..3c95dd74fca0 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -106,3 +106,18 @@ void arch_initial_func_cfi_state(struct cfi_init_state= *state) state->regs[CFI_RA].base =3D CFI_CFA; state->regs[CFI_RA].offset =3D 0; } + +unsigned int arch_reloc_size(struct reloc *reloc) +{ + switch (reloc_type(reloc)) { + case R_PPC_REL32: + case R_PPC64_REL32: + case R_PPC_ADDR32: + case R_PPC_UADDR32: + case R_PPC_PLT32: + case R_PPC_PLTREL32: + return 4; + default: + return 8; + } +} diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index fe1362c34564..fb9691a34d92 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -852,3 +852,16 @@ bool arch_is_embedded_insn(struct symbol *sym) return !strcmp(sym->name, "retbleed_return_thunk") || !strcmp(sym->name, "srso_safe_ret"); } + +unsigned int arch_reloc_size(struct reloc *reloc) +{ + switch (reloc_type(reloc)) { + case R_X86_64_32: + case R_X86_64_32S: + case R_X86_64_PC32: + case R_X86_64_PLT32: + return 4; + default: + return 8; + } +} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f64435ad3514..d8668ae0f599 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1968,7 +1968,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, break; =20 /* Make sure the table entries are consecutive: */ - if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) + if (prev_offset && reloc_offset(reloc) !=3D prev_offset + arch_reloc_siz= e(reloc)) break; =20 sym_offset =3D reloc->sym->offset + reloc_addend(reloc); diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index d63b46a19f39..396f7c6c81c0 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -97,4 +97,6 @@ int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); =20 +unsigned int arch_reloc_size(struct reloc *reloc); + #endif /* _ARCH_H */ --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30FAE224D6 for ; Tue, 17 Dec 2024 01:09:13 +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=1734397756; cv=none; b=pmug4rSL0Von9tUwL62yircIXxBOgXwMwqmFzpJcM14H+YtQFRZxdKONjrd5xeIDo/az4KF5aNcoxkHRpzSPrqpZ54ByqhZAHMHYWLBiG521OEWRU+rpYL0K04L9SXFGKVXOLT0n96lIR5JbokoeAZoYjM+XS3VfBIIHuxNdz40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397756; c=relaxed/simple; bh=5IPJJWeAlO39eq8FDSJb7baUxMjFQGsbCAUC8y4lQws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lk7/+JAw+cmKmyCu273mLhTLtpC49DXnbOoSyUBBKgboTdaWpOyABJi0PvbRZRxobpUtQ2JwIpzzG57Gf4XuYtmwvpxWaTzvmS2biAfzUI79NuMsTzF2FLdKP2i814InShL8OsdJPTLZqDSikruErHZORlMo015+JqeLVmVQHbc= 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 _____8Dx_644z2BnJJdXAA--.1144S3; Tue, 17 Dec 2024 09:09:12 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S5; Tue, 17 Dec 2024 09:09:10 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/9] objtool: Handle PC relative relocation type Date: Tue, 17 Dec 2024 09:08:59 +0800 Message-ID: <20241217010905.13054-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZr48Ww13Xw15uryfGFyrKrX_yoW7Jw45pF srC398Kr4Yqr1xWw42ya1kWrW5Gan7Wry2qryDtryrZrZFqw15tFWxAFZ8Ka1UXwsYgFWx ZFnYgw17AF4qv3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8EoGPUUUUU== Content-Type: text/plain; charset="utf-8" For the most part, an absolute relocation type is used for rodata. In the case of STT_SECTION, reloc->sym->offset is always zero, for the other symbol types, reloc_addend(reloc) is always zero, thus it can use a simple statement "reloc->sym->offset + reloc_addend(reloc)" to obtain the symbol offset for various symbol types. When compiling on LoongArch, there exist PC relative relocation types for rodata, it needs to calculate the symbol offset with "S + A - PC" according to the spec of "ELF for the LoongArch Architecture". If there is only one jump table in the rodata, the "PC" is the entry address which is equal with the value of reloc_offset(reloc), at this time, reloc_offset(table) is 0. If there are many jump tables in the rodata, the "PC" is the offset of the jump table's base address which is equal with the value of reloc_offset(reloc) - reloc_offset(table). So for LoongArch, if the relocation type is PC relative, it can use a statement "reloc_offset(reloc) - reloc_offset(table)" to get the "PC" value when calculating the symbol offset with "S + A - PC" for one or many jump tables in the rodata. Add an arch-specific function arch_jump_table_sym_offset() to assign the symbol offset, for the most part that is an absolute relocation, the default value is "reloc->sym->offset + reloc_addend(reloc)" in the weak definition, it can be overridden by each architecture that has different requirements. Link: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/arch/loongarch/decode.c | 17 +++++++++++++---- tools/objtool/arch/loongarch/include/arch/elf.h | 7 +++++++ tools/objtool/check.c | 7 ++++++- tools/objtool/include/objtool/arch.h | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index b64205b89f6b..02e490555966 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -5,10 +5,7 @@ #include #include #include - -#ifndef EM_LOONGARCH -#define EM_LOONGARCH 258 -#endif +#include =20 int arch_ftrace_match(char *name) { @@ -374,3 +371,15 @@ unsigned int arch_reloc_size(struct reloc *reloc) return 8; } } + +unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table) +{ + switch (reloc_type(reloc)) { + case R_LARCH_32_PCREL: + case R_LARCH_64_PCREL: + return reloc->sym->offset + reloc_addend(reloc) - + (reloc_offset(reloc) - reloc_offset(table)); + default: + return reloc->sym->offset + reloc_addend(reloc); + } +} diff --git a/tools/objtool/arch/loongarch/include/arch/elf.h b/tools/objtoo= l/arch/loongarch/include/arch/elf.h index 9623d663220e..ec79062c9554 100644 --- a/tools/objtool/arch/loongarch/include/arch/elf.h +++ b/tools/objtool/arch/loongarch/include/arch/elf.h @@ -18,6 +18,13 @@ #ifndef R_LARCH_32_PCREL #define R_LARCH_32_PCREL 99 #endif +#ifndef R_LARCH_64_PCREL +#define R_LARCH_64_PCREL 109 +#endif + +#ifndef EM_LOONGARCH +#define EM_LOONGARCH 258 +#endif =20 #define R_NONE R_LARCH_NONE #define R_ABS32 R_LARCH_32 diff --git a/tools/objtool/check.c b/tools/objtool/check.c index d8668ae0f599..cff7416b207e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1943,6 +1943,11 @@ static int add_special_section_alts(struct objtool_f= ile *file) return ret; } =20 +__weak unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struc= t reloc *table) +{ + return reloc->sym->offset + reloc_addend(reloc); +} + static int add_jump_table(struct objtool_file *file, struct instruction *i= nsn, struct reloc *next_table) { @@ -1971,7 +1976,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, if (prev_offset && reloc_offset(reloc) !=3D prev_offset + arch_reloc_siz= e(reloc)) break; =20 - sym_offset =3D reloc->sym->offset + reloc_addend(reloc); + sym_offset =3D arch_jump_table_sym_offset(reloc, table); =20 /* Detect function pointers from contiguous objects: */ if (reloc->sym->sec =3D=3D pfunc->sec && sym_offset =3D=3D pfunc->offset) diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 396f7c6c81c0..089a1acc48a8 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -98,5 +98,6 @@ int arch_rewrite_retpolines(struct objtool_file *file); bool arch_pc_relative_reloc(struct reloc *reloc); =20 unsigned int arch_reloc_size(struct reloc *reloc); +unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table); =20 #endif /* _ARCH_H */ --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32A1722EE4 for ; Tue, 17 Dec 2024 01:09:13 +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=1734397756; cv=none; b=A9Ef9AoB7qwyI8t+4ddHp6Uz7vN404vugAySQ1P/rI22fvKQdDoG6pJFuMgpHfUtMuBTUKxqCkVkp1wVXczdGDdVU2oQ2+cIeTn37tN7va1TxNvWF8I3begND4CLswHtqidufVDdoPTIlUF/AT4gq7Eh1kwDNIOAa7fc/xRNKm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397756; c=relaxed/simple; bh=qmFXzkmiOcive4vzwGchnxkxJY85d6lRYkqb01roVRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YuaIqA4jfwXqYoRnjF6NW2TUTWtzIkcOuyrzAtSkFhZOpcOX0zodPGsfzc2Sfjjm3yiq8wznK6V1T8Agdsnoi2Kn6bv2fgIdb+iTYr15QYKdId/ZFaV6LyQNCckTJiCGTsL44cyhec/4NqLbkLnB/5VMX6wuAbzUmmGLHyzO6bI= 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 _____8DxG+I4z2BnJpdXAA--.39668S3; Tue, 17 Dec 2024 09:09:12 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S6; Tue, 17 Dec 2024 09:09:11 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 4/9] objtool: Handle unreachable entry of rodata Date: Tue, 17 Dec 2024 09:09:00 +0800 Message-ID: <20241217010905.13054-5-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj9xXoW7JFWfCFW8ZF15GF48Kw4DAwc_yoWDtwc_Aa 40grn7Jrs8XF4Iy3W0krs5WFy0kan5Wr47Xw17GF1Yga43J3yDuF92kFnIyF9Y9rWSyFsx u3s3Ar1fCwnF9osvyTuYvTs0mTUanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUbfkYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5 McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4ApnDUUUU Content-Type: text/plain; charset="utf-8" When compiling with Clang on LoongArch, there exists unreachable entry of rodata which points to a position after the function return instruction, this is generated by compiler to fill the non-existent switch case, just skip the entry when parsing the relocation section of rodata. Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index cff7416b207e..654cffcf9512 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1986,9 +1986,10 @@ static int add_jump_table(struct objtool_file *file,= struct instruction *insn, if (!dest_insn) break; =20 - /* Make sure the destination is in the same function: */ - if (!insn_func(dest_insn) || insn_func(dest_insn)->pfunc !=3D pfunc) - break; + if (!insn_func(dest_insn) || insn_func(dest_insn)->pfunc !=3D pfunc) { + prev_offset =3D reloc_offset(reloc); + continue; + } =20 alt =3D malloc(sizeof(*alt)); if (!alt) { --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C77BE1384BF for ; Tue, 17 Dec 2024 01:09:16 +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=1734397759; cv=none; b=YEE4kwynpwwbpQlsfP4L+ZKn3fP3LzBHNot+tDS2etq4ad3S5eNU9VQ7nf9uTEIM86yoL3/E8gONp+7BTUHXsOQUOFSrWoOeB7ctxSxIz7NeDKHOlTX66T4hbsypBrLhcDWlBgXCcjDc/7WlE5OV+jpdqn/0BnhdpIPxzSIRP28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397759; c=relaxed/simple; bh=lFIV0tp5kTgIjQqFoy4l3pEQtpR+NFoU2d6a4ga6vfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eFa0BMrYYrP6fqe8IrUyugt/BZXRPB3kpG62yiVycJaIhhYuM6WL8WZKeCf6MFFYLnW4KA0hBEMEtv6ic3yGz9vxvYLSA67s3b+fJVbXcladYeqgXXRf6vfKZA5CS64OTSVRSRuw1GKs6BLW0elnL0rb26QxIcpauns4X13U+XQ= 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 _____8AxbeI7z2BnMJdXAA--.39266S3; Tue, 17 Dec 2024 09:09:15 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S7; Tue, 17 Dec 2024 09:09:12 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 5/9] objtool/LoongArch: Add support for switch table Date: Tue, 17 Dec 2024 09:09:01 +0800 Message-ID: <20241217010905.13054-6-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S7 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3GF1DXF4rur4xuw43Cw43XFc_yoWxZw43pF y3C3s8trWYqFyrWr47tF4I9rW3Aw4kWry7Gr9xG34rA343tryFqayavasIkas5GrZ8Ar4I qrW5Kr1xCF4kAFXCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0epB3UUUUU== Content-Type: text/plain; charset="utf-8" The objtool program need to analysis the control flow of each object file generated by compiler toolchain, it needs to know all the locations that a branch instruction may jump into, if a jump table is used, objtool has to correlate the jump instruction with the table. On x86 (which is the only port supported by objtool before LoongArch), there is a relocation type on the jump instruction and directly points to the table. But on LoongArch, the relocation is on another kind of instruction prior to the jump instruction, and also with scheduling it is not very easy to tell the offset of that instruction from the jump instruction. Furthermore, because LoongArch has -fsection-anchors (often enabled at -O1 or above) the relocation may actually points to a section anchor instead of the table itself. The good news is that after continuous analysis and discussion, at last a GCC patch "LoongArch: Add support to annotate tablejump" and a Clang patch "[LoongArch] Add options for annotate tablejump" have been merged into the upstream mainline, the compiler changes make life much easier for switch table support of objtool on LoongArch. By now, there is an additional section ".discard.tablejump_annotate" to store the jump info as pairs of addresses, each pair contains the address of jump instruction and the address of jump table. In order to find switch table, it is easy to parse the relocation section ".rela.discard.tablejump_annotate" to get table_sec and table_offset, the rest process is somehow like x86. Additionally, it needs to get each table size. When compiling on LoongArch, there are unsorted table offsets of rodata if there exist many jump tables, it will get the wrong table end and find the wrong table jump destination instructions in add_jump_table(). Sort the rodata table offset by parsing ".rela.discard.tablejump_annotate" and then get each table size of rodata corresponded with each table jump instruction, it is used to check the table end and will break the process when parsing ".rela.rodata" to avoid getting the wrong jump destination instructions. Link: https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommit;h=3D0ee028f55640 Link: https://github.com/llvm/llvm-project/commit/4c2c17756739 Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/arch/loongarch/special.c | 131 ++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index 87230ed570fd..4fa6877d5b2b 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include #include +#include =20 bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, @@ -8,9 +10,136 @@ bool arch_support_alt_relocation(struct special_alt *spe= cial_alt, return false; } =20 +struct table_info { + struct list_head jump_info; + unsigned long insn_offset; + unsigned long rodata_offset; +}; + +static void get_rodata_table_size_by_table_annotate(struct objtool_file *f= ile, + struct instruction *insn, + unsigned long *table_size) +{ + struct section *rsec; + struct reloc *reloc; + struct list_head table_list; + struct table_info *orig_table; + struct table_info *next_table; + unsigned long tmp_insn_offset; + unsigned long tmp_rodata_offset; + + rsec =3D find_section_by_name(file->elf, ".rela.discard.tablejump_annotat= e"); + if (!rsec) + return; + + INIT_LIST_HEAD(&table_list); + + for_each_reloc(rsec, reloc) { + orig_table =3D malloc(sizeof(struct table_info)); + if (!orig_table) { + WARN("malloc failed"); + return; + } + + orig_table->insn_offset =3D reloc->sym->offset + reloc_addend(reloc); + reloc++; + orig_table->rodata_offset =3D reloc->sym->offset + reloc_addend(reloc); + + list_add_tail(&orig_table->jump_info, &table_list); + + if (reloc_idx(reloc) + 1 =3D=3D sec_num_entries(rsec)) + break; + } + + list_for_each_entry(orig_table, &table_list, jump_info) { + next_table =3D list_next_entry(orig_table, jump_info); + list_for_each_entry_from(next_table, &table_list, jump_info) { + if (next_table->rodata_offset < orig_table->rodata_offset) { + tmp_insn_offset =3D next_table->insn_offset; + tmp_rodata_offset =3D next_table->rodata_offset; + next_table->insn_offset =3D orig_table->insn_offset; + next_table->rodata_offset =3D orig_table->rodata_offset; + orig_table->insn_offset =3D tmp_insn_offset; + orig_table->rodata_offset =3D tmp_rodata_offset; + } + } + } + + list_for_each_entry(orig_table, &table_list, jump_info) { + if (insn->offset =3D=3D orig_table->insn_offset) { + next_table =3D list_next_entry(orig_table, jump_info); + if (&next_table->jump_info =3D=3D &table_list) { + *table_size =3D 0; + return; + } + + while (next_table->rodata_offset =3D=3D orig_table->rodata_offset) { + next_table =3D list_next_entry(next_table, jump_info); + if (&next_table->jump_info =3D=3D &table_list) { + *table_size =3D 0; + return; + } + } + + *table_size =3D next_table->rodata_offset - orig_table->rodata_offset; + } + } +} + +static struct reloc *find_reloc_by_table_annotate(struct objtool_file *fil= e, + struct instruction *insn, + unsigned long *table_size) +{ + struct section *rsec; + struct reloc *reloc; + unsigned long offset; + + rsec =3D find_section_by_name(file->elf, ".rela.discard.tablejump_annotat= e"); + if (!rsec) + return NULL; + + for_each_reloc(rsec, reloc) { + if (reloc->sym->sec->rodata) + continue; + + if (strcmp(insn->sec->name, reloc->sym->sec->name)) + continue; + + offset =3D reloc->sym->offset + reloc_addend(reloc); + if (insn->offset =3D=3D offset) { + get_rodata_table_size_by_table_annotate(file, insn, table_size); + reloc++; + return reloc; + } + } + + return NULL; +} + struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, unsigned long *table_size) { - return NULL; + struct reloc *annotate_reloc; + struct reloc *rodata_reloc; + struct section *table_sec; + unsigned long table_offset; + + annotate_reloc =3D find_reloc_by_table_annotate(file, insn, table_size); + if (!annotate_reloc) + return NULL; + + table_sec =3D annotate_reloc->sym->sec; + table_offset =3D annotate_reloc->sym->offset + reloc_addend(annotate_relo= c); + + /* + * Each table entry has a rela associated with it. The rela + * should reference text in the same function as the original + * instruction. + */ + rodata_reloc =3D find_reloc_by_dest(file->elf, table_sec, table_offset); + if (!rodata_reloc) + return NULL; + + return rodata_reloc; } --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91D0013D8B4 for ; Tue, 17 Dec 2024 01:09:17 +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=1734397759; cv=none; b=ZbfyLifCpttv4X5GJyXilTn1oDLvXOiS+Wj/7CwsrIiHAaS/NceCV494teKuaK7v0QBjViMWlbReqN0u9Ep6PEauE6fiIZJPwx0OzwSwvdI+uqqWzzN0PdmER5Wti3NlK0afW8uPo+k2mj8eQcDIYAy8PhOX9gxlnXDg+YZM7nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397759; c=relaxed/simple; bh=VNhZx1RSKoKpE+uds6M9R6tlg953Re2Ndu7s2C/UrQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bBi4waKX0+AZiQut25yBgdL8XeTgMdB4wLZckcjcETZq5ibhfc5g0F0hZPUpxM9OE/DptKZml9LYIA8H75pzl9nqcbMBq+d/IRo/tGPxqeplx6qUmnJ+KYzuu0Yu+ItNz5CeiFRoN17UR13dbp8p5d6asRemKRiHKCHB5u9Jgks= 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 _____8BxIK88z2BnO5dXAA--.15964S3; Tue, 17 Dec 2024 09:09:16 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S8; Tue, 17 Dec 2024 09:09:15 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 6/9] objtool/LoongArch: Add support for goto table Date: Tue, 17 Dec 2024 09:09:02 +0800 Message-ID: <20241217010905.13054-7-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4rWw18Wr1fWr43Zw43Jwc_yoWrXFy5pF W3C345Kr45ZrWSgr47tay09ryaya1IgFy7JrW7t34fAw43Xr1FyF1SvF9IyFWrCrZ5Jr4I qrs5Kr18CF4DAacCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0c Ia020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Wrv_ ZF1lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jqRRiUUUUU= Content-Type: text/plain; charset="utf-8" The objtool program need to analysis the control flow of each object file generated by compiler toolchain, it needs to know all the locations that a branch instruction may jump into, if a jump table is used, objtool has to correlate the jump instruction with the table. On x86 (which is the only port supported by objtool before LoongArch), there is a relocation type on the jump instruction and directly points to the table. But on LoongArch, the relocation is on another kind of instruction prior to the jump instruction, and also with scheduling it is not very easy to tell the offset of that instruction from the jump instruction. Furthermore, because LoongArch has -fsection-anchors (often enabled at -O1 or above) the relocation may actually points to a section anchor instead of the table itself. For the jump table of switch cases, a GCC patch "LoongArch: Add support to annotate tablejump" and a Clang patch "[LoongArch] Add options for annotate tablejump" have been merged into the upstream mainline, it can parse the additional section ".discard.tablejump_annotate" which stores the jump info as pairs of addresses, each pair contains the address of jump instruction and the address of jump table. For the jump table of computed gotos, it is indeed not easy to implement in the compiler, especially if there is more than one computed goto in a function such as ___bpf_prog_run(). objdump kernel/bpf/core.o shows that there are many table jump instructions in ___bpf_prog_run(), but there are no relocations on the table jump instructions and to the table directly on LoongArch. Without the help of compiler, in order to figure out the address of goto table for the special case of ___bpf_prog_run(), since the instruction sequence is relatively single and stable, it makes sense to add a helper find_reloc_of_rodata_c_jump_table() to find the relocation which points to the section ".rodata..c_jump_table". If find_reloc_by_table_annotate() failed, it means there is no relocation info of switch table address in ".rela.discard.tablejump_annotate", then objtool may find the relocation info of goto table ".rodata..c_jump_table" with find_reloc_of_rodata_c_jump_table(). Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- tools/objtool/arch/loongarch/special.c | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index 4fa6877d5b2b..27c6473608f3 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -116,6 +116,30 @@ static struct reloc *find_reloc_by_table_annotate(stru= ct objtool_file *file, return NULL; } =20 +static struct reloc *find_reloc_of_rodata_c_jump_table(struct section *sec, + unsigned long offset, + unsigned long *table_size) +{ + struct section *rsec; + struct reloc *reloc; + + rsec =3D sec->rsec; + if (!rsec) + return NULL; + + for_each_reloc(rsec, reloc) { + if (reloc_offset(reloc) > offset) + break; + + if (!strncmp(reloc->sym->sec->name, ".rodata..c_jump_table", 21)) { + *table_size =3D 0; + return reloc; + } + } + + return NULL; +} + struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, unsigned long *table_size) @@ -126,8 +150,12 @@ struct reloc *arch_find_switch_table(struct objtool_fi= le *file, unsigned long table_offset; =20 annotate_reloc =3D find_reloc_by_table_annotate(file, insn, table_size); - if (!annotate_reloc) - return NULL; + if (!annotate_reloc) { + annotate_reloc =3D find_reloc_of_rodata_c_jump_table( + insn->sec, insn->offset, table_size); + if (!annotate_reloc) + return NULL; + } =20 table_sec =3D annotate_reloc->sym->sec; table_offset =3D annotate_reloc->sym->offset + reloc_addend(annotate_relo= c); --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E880288B1 for ; Tue, 17 Dec 2024 01:09:19 +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=1734397762; cv=none; b=MvfvMWWjmXi5k5Y6f10LFzN7wkwXMtwhsEWZWwE0LQ0Xg4VQnvgzAXl8paSLcc7menKe5yRyc2YEXqHymV/04ORN7rBZWu/CJzSbZjR8vfYO31VtV4ldbEd2TgVsTnjYq9JPQUnsBVDGVHhOpebfourUkLjcDZXbdvjduX37yrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397762; c=relaxed/simple; bh=B3KZMIw95MBg61/d6zZGkkqFyUQXS571JeCHkftd3nY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NUrv3UXeWE/Zef+Hwv3O92mnDb40Qt4zqVC+cxC4NjqZUI5rXf/WTG+XC4bOBjG6ynivshI7YUQcTkQl72/5yZgQjFYEmLr9WfVSlMFEzAcgGxz2pv4zAiz/NR4C2P+5ujpqRpRGcTNrqnoLND2UMkY9cp5fvubXFRL/fV3+SSQ= 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 _____8CxSOE+z2BnQ5dXAA--.39578S3; Tue, 17 Dec 2024 09:09:18 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S9; Tue, 17 Dec 2024 09:09:16 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 7/9] LoongArch: Enable jump table for objtool Date: Tue, 17 Dec 2024 09:09:03 +0800 Message-ID: <20241217010905.13054-8-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S9 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7uFWDWF4fuF1fAw1xCr1xJFc_yoW8WrW3pw s7Zr4kKr4kWF1ktrZrJ3ySgr98JrnrKr43ZF42ga48ArW7Z3yUZr48ta9rXF15AwsxJrWI qFWfKasIvFWUJ3XCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26rWY 6Fy7McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU36RRDUUUU Content-Type: text/plain; charset="utf-8" For now, it is time to remove -fno-jump-tables to enable jump table for objtool if the compiler has -mannotate-tablejump, otherwise it is better to remain -fno-jump-tables to keep compatibility with older compilers. Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- arch/loongarch/Kconfig | 3 +++ arch/loongarch/Makefile | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index dae3a9104ca6..66980d847f4e 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -287,6 +287,9 @@ config AS_HAS_LBT_EXTENSION config AS_HAS_LVZ_EXTENSION def_bool $(as-instr,hvcl 0) =20 +config CC_HAS_ANNOTATE_TABLEJUMP + def_bool $(cc-option,-mannotate-tablejump) + menu "Kernel type and options" =20 source "kernel/Kconfig.hz" diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 567bd122a9ee..0304eabbe606 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -101,7 +101,11 @@ KBUILD_AFLAGS +=3D $(call cc-option,-mthin-add-sub) = $(call cc-option,-Wa$(comma) KBUILD_CFLAGS +=3D $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa= $(comma)-mthin-add-sub) =20 ifdef CONFIG_OBJTOOL -KBUILD_CFLAGS +=3D -fno-jump-tables +ifdef CONFIG_CC_HAS_ANNOTATE_TABLEJUMP +KBUILD_CFLAGS +=3D -mannotate-tablejump +else +KBUILD_CFLAGS +=3D -fno-jump-tables # keep compatibility with older comp= ilers +endif endif =20 KBUILD_RUSTFLAGS +=3D --target=3Dloongarch64-unknown-none-softfloat -Ccod= e-model=3Dsmall --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0770F146D55 for ; Tue, 17 Dec 2024 01:09:20 +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=1734397763; cv=none; b=GIxRvJlztYmnJ8JaYEA8MitkNwyn4h/U67/T6cU+QiD0LoSJdglX7I/U49oYYi98iNO73WEW98U2hXeqn+SbGV80z+QViNFa+eGJjrJ+s1/mB4G01GdcZw8eIEFn4s0qZ0yPX+9NrY0D5bJ8JDkvGcZKvnUBm6N5wWH9rn1yp+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734397763; c=relaxed/simple; bh=ZtOhJE1cTY/xHXj1EAXPWLuV43L7x8hjDPN8Z46WR28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rTumahCKpsgEBR4cKSvJXcbfaIN7xUSqL/LJZCZQP6FqCZIfZ7dzfJtScTUEGE2ArX2+95XZqGNNjnKn1nScBHz6zUNnDexzCJ8BF41/mUsj96Mid2rEjQwP5rqrmtD3tIOHEPLq6teopVFUuWeL4ttrSZn4rj6xoSrlWrh4e5c= 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 _____8BxuuA_z2BnS5dXAA--.41412S3; Tue, 17 Dec 2024 09:09:19 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMDxPEcyz2BnXNeFAA--.16436S10; Tue, 17 Dec 2024 09:09:18 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 8/9] LoongArch: Convert unreachable() to BUG() Date: Tue, 17 Dec 2024 09:09:04 +0800 Message-ID: <20241217010905.13054-9-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMDxPEcyz2BnXNeFAA--.16436S10 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj9xXoWrZr4rZFW3JF13tryfWryrKrX_yoWkCwcEyr yxJw1UGrWrZFZrAw1Utr4rWryFq3WrKFWY9wn7Zay5A3W5t348t3y5tas8Ar1ktFWkGrZ5 t39YvFZYkw1xKosvyTuYvTs0mTUanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUbSxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0c Ia020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Wrv_ ZF1lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU3ID7DUUUU Content-Type: text/plain; charset="utf-8" When compiling on LoongArch, there exists the following objtool warning in arch/loongarch/kernel/machine_kexec.o: kexec_reboot() falls through to next function crash_shutdown_secondary() Avoid unreachable() as it can (and will in the absence of UBSAN) generate fallthrough code. Use BUG() so we get a "break BRK_BUG" trap (with unreachable annotation). Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- arch/loongarch/kernel/machine_kexec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/= machine_kexec.c index 8ae641dc53bb..f9381800e291 100644 --- a/arch/loongarch/kernel/machine_kexec.c +++ b/arch/loongarch/kernel/machine_kexec.c @@ -126,14 +126,14 @@ void kexec_reboot(void) /* All secondary cpus go to kexec_smp_wait */ if (smp_processor_id() > 0) { relocated_kexec_smp_wait(NULL); - unreachable(); + BUG(); } #endif =20 do_kexec =3D (void *)reboot_code_buffer; do_kexec(efi_boot, cmdline_ptr, systable_ptr, start_addr, first_ind_entry= ); =20 - unreachable(); + BUG(); } =20 =20 --=20 2.42.0 From nobody Wed Dec 17 21:41:08 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39E1F13C689 for ; Tue, 17 Dec 2024 01:50:16 +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=1734400220; cv=none; b=XKlBGjo+v3wiUdAakXY45Sgvr/MUA25CSjShuKqJIKF3sGvbOXlXqJnTs0wcS7b8KrFt1N/5iGPlviH2tjMCIlEzxlIFhIuNK7K/q3PKhuN0dLbasZaOFV437Zw+EZYTgQA0TJh8/9tC1Pw4jGsR29J8qk/V2sqZ90X8kqb7mQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734400220; c=relaxed/simple; bh=6zwDsHOUh1VbxgGD9EGwxbLyhq8N4xqmUgzklPxvcCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fnawou1Zkrqbu8p5pu/G1lclQ+XYWc4YXaC5ekiWi+AQHasOeJldyXvykcuHSOrYkkFo3o32+q+yAmrB308MkwkAEsU4f13m7YK68byEEkS6Cpj8kxYIj6mytPlLcxgM09e3lmT9jl8gU+FWuQS74qC9FTIpMd2vnat+/GBqjc0= 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 _____8DxGeDQ2GBnrpxXAA--.39627S3; Tue, 17 Dec 2024 09:50:08 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMCxbUfO2GBn8+KFAA--.16146S2; Tue, 17 Dec 2024 09:50:07 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 9/9] drm/amd/display: Mark dc_fixpt_from_fraction() noinline Date: Tue, 17 Dec 2024 09:50:06 +0800 Message-ID: <20241217015006.30305-1-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241217010905.13054-1-yangtiezhu@loongson.cn> References: <20241217010905.13054-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: qMiowMCxbUfO2GBn8+KFAA--.16146S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7ZF17KFWruF4DAw1DtrWDGFX_yoW8JFW3pF 43JFy5Wa1kJF1xKFZxJa45uFW3Ca95XrW0gr1UAws5Aa47A3WvgFZxt3WDGFW2kF4Yyr4I vF4DKay7KFn2yrcCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBIb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8siSPUUUUU== Content-Type: text/plain; charset="utf-8" When compiling with Clang on LoongArch, there exists the following objtool warning in drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.o: dc_fixpt_recip() falls through to next function dc_fixpt_sinc() This is because dc_fixpt_from_fraction() is inlined in dc_fixpt_recip() by Clang, given dc_fixpt_from_fraction() is not a simple function, just mark it noinline to avoid the above issue. Signed-off-by: Tiezhu Yang Acked-by: Josh Poimboeuf --- drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c b/drivers/g= pu/drm/amd/display/dc/basics/fixpt31_32.c index 88d3f9d7dd55..b40c6a21460d 100644 --- a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c +++ b/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c @@ -68,7 +68,7 @@ static inline unsigned long long complete_integer_divisio= n_u64( #define GET_FRACTIONAL_PART(x) \ (FRACTIONAL_PART_MASK & (x)) =20 -struct fixed31_32 dc_fixpt_from_fraction(long long numerator, long long de= nominator) +noinline struct fixed31_32 dc_fixpt_from_fraction(long long numerator, lon= g long denominator) { struct fixed31_32 res; =20 --=20 2.42.0