From nobody Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC71FC2C9 for ; Sat, 7 Dec 2024 01:59:22 +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=1733536765; cv=none; b=flLCVXN+jZo3L2GiPw+kjm+/g490V1li3NspWYYQzcwQyxjO9Ow+FMEf4fg5Vr+J2fE+NF5cN44Ak8RQSVoV4IJjKkFZnzxc8iiKtWE9FfmdXXciThDwxqExG19tXktPu4Cs7rLqOwbEC9SGFpR8ztvbXhwvCZ9feAdsiReCCcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536765; c=relaxed/simple; bh=vrRcUnmIqQ39Jrf3H2bwp/YR0FDuBCkcVRtxA/+Fai4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pGPRY0HD+XfscWgEVtiRwUKtxNrurIX3K6H50tWv5g3cD6JLDtCFdYnyTXW/15EGCbwVfbUIYNO07JusLD4aLGfF8VJhsQ+9PU13bbjWWVZFWAJ/rGHpnsEbSHngC9N4l3MXnR4Vp/Z65jcNghu+6igDCawY02n44LhgwzUMcIw= 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 _____8AxQK35q1NnEq1SAA--.56071S3; Sat, 07 Dec 2024 09:59:21 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S3; Sat, 07 Dec 2024 09:59:20 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 01/10] objtool: Handle various symbol types of rodata Date: Sat, 7 Dec 2024 09:59:06 +0800 Message-ID: <20241207015915.1159-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJFWDKF47Ww48Jr18urWkXwc_yoW5WrWDpF sxK3y5Kr4Yqr1xWwn7tayvgFy3Gw4kWF17JrsrKr1rZ3sFyr1rKFW2kryak3Z8Grn2va17 Xa4Y9ry3CF4DA3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWU twAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73 UjIFyTuYvjxUc0eHDUUUU 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, the relocation type is not PC relative, in the case of STT_SECTION, reloc->sym->offset is always zero, while for the other symbol types, reloc_addend(reloc) is always zero, therefore 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 --- 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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDB791804E for ; Sat, 7 Dec 2024 01:59:24 +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=1733536768; cv=none; b=VV5kq42sp5gGqEtmcDzuITCXlUhQftTbucK2p6f06dwESh39VXGF4D5/1XfJjETUNkXZ/KjI0EhlkvnFbebbubo9ECbFsZmSKsCceEsPLk+kROyEbsudjZEtuKWWoh9h20cH3R2GKgG4bO71xYNIlsF+5Ix/K2FacDFeWC2ULJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536768; c=relaxed/simple; bh=0CbpOPI4Xa7ty6GYDZyXKqQGKZIAwaVBL6eU1ORjlx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G5Kr8FL5sEe/A3A6LNQo/mH3dP8WgAPDeUA3B8VHclpoL0FF2rR4pXitUPIk4QkOwKgjKBLPxmIYBuGBxUoXo61U56VP+/uLbP0PPfnkvL91A+R9dcqJlZeH838WHP239nsmIks5t4e+wkQ3SMy7MWW5LliECDmuz+CP9jF7WUY= 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 _____8Axjq_6q1NnFq1SAA--.6130S3; Sat, 07 Dec 2024 09:59:22 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S4; Sat, 07 Dec 2024 09:59:21 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/10] objtool: Handle different entry size of rodata Date: Sat, 7 Dec 2024 09:59:07 +0800 Message-ID: <20241207015915.1159-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4fuF4DtryruF45CF13WrX_yoW5AF45pF srC3yrGr4Fgry3Gwnrta1kurZ8Gws2gryIqF9rJry8ArZrXr15JFWSyryUtF18XwsYgFWf XFZYgr15AF4qy3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8N6pPUUUUU== 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, but when compiling with Clang on LoongArch, there exists 32 bit relocation type, 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, the default value is 8 in the weak definition, it can be overridden by archs that have different requirements. Signed-off-by: Tiezhu Yang --- tools/objtool/arch/loongarch/decode.c | 11 +++++++++++ tools/objtool/check.c | 10 +++++++++- tools/objtool/include/objtool/arch.h | 2 ++ 3 files changed, 22 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/check.c b/tools/objtool/check.c index f64435ad3514..7271e959520e 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 int arch_reloc_size(struct reloc *reloc) +{ + return 8; +} + static int add_jump_table(struct objtool_file *file, struct instruction *i= nsn, struct reloc *next_table) { @@ -1954,6 +1959,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, struct reloc *reloc =3D table; struct alternative *alt; unsigned long sym_offset; + unsigned int entry_size; =20 /* * Each @reloc is a switch table relocation which points to the target @@ -1967,8 +1973,10 @@ static int add_jump_table(struct objtool_file *file,= struct instruction *insn, if (reloc !=3D table && reloc =3D=3D next_table) break; =20 + entry_size =3D arch_reloc_size(reloc); + /* 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 + entry_size) 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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9728A17BA3 for ; Sat, 7 Dec 2024 01:59:24 +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=1733536766; cv=none; b=BkoQmGoy1CJndhJZ0Itv0/zJXsktGYNqW5JgbzorCeXEHhX9YBfp2kCAXWtb8UeXOBdq0KbpkmAfkIUpYwLQRrbeb9EOXwWAmHvN2fkU0tSoEdkCU1YpcC8PBdfNNk5gWacvfPmg0xYyS0ZbpWclCOCwRdGqX1HC77euNnpk3DQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536766; c=relaxed/simple; bh=N/F2zjofPysRYI7xOdfPGnfrL6z85FVliafcbYErn30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Peo606byt4B1lYCZBO0nj3LWamru7UXRcskLntgZuWjv3YTtAu8/4rX8x93MdAOGNzWLqgsBmgVNn9J7i8Wmx0iJXXzrYCIogne5w34uuJQ6aMgNJIN7SuxP90pTQ7G9w8DZZcVhX+oqnsw5vAu3YC3TajkQ55HTb70SLvSd3Mw= 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 _____8BxeeH7q1NnGq1SAA--.31966S3; Sat, 07 Dec 2024 09:59:23 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S5; Sat, 07 Dec 2024 09:59:22 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 03/10] objtool: Handle PC relative relocation type Date: Sat, 7 Dec 2024 09:59:08 +0800 Message-ID: <20241207015915.1159-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw1UCF13WF4xKrW3Aw1fAFc_yoWrGw4fpF srC398Gr4Fgr1fW347t3WkWFZ8Gws7Wry2qFyDAryrZrZFqw15tr4xAFn8Wa1UXwsYgayx ZFZYgw17AF4qvwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8EeHDUUUUU== Content-Type: text/plain; charset="utf-8" When compiling on LoongArch, there exists PC relative relocation type, it needs to get the symbol offset with "S + A - PC" according to the spec of "ELF for the LoongArch Architecture". Add an arch-specific function arch_adjust_offset() to assign the symbol offset, the default value is "reloc->sym->offset + reloc_addend(reloc)" in the weak definition, it can be overridden by archs that have different requirements. Signed-off-by: Tiezhu Yang --- tools/objtool/arch/loongarch/decode.c | 20 +++++++++++++++---- .../objtool/arch/loongarch/include/arch/elf.h | 7 +++++++ tools/objtool/check.c | 7 ++++++- tools/objtool/include/objtool/arch.h | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index b64205b89f6b..431eb4757458 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,18 @@ unsigned int arch_reloc_size(struct reloc *reloc) return 8; } } + +unsigned long arch_adjust_offset(struct reloc *reloc, struct reloc *table) +{ + switch (reloc_type(reloc)) { + case R_LARCH_32_PCREL: + case R_LARCH_64_PCREL: + if (reloc->sym->type =3D=3D STT_SECTION) + return reloc->sym->offset + reloc_addend(reloc) - + (reloc_offset(reloc) - reloc_offset(table)); + else + return reloc->sym->offset; + 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 7271e959520e..4a23aae40c03 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1948,6 +1948,11 @@ __weak unsigned int arch_reloc_size(struct reloc *re= loc) return 8; } =20 +__weak unsigned long arch_adjust_offset(struct reloc *reloc, struct 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) { @@ -1979,7 +1984,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, if (prev_offset && reloc_offset(reloc) !=3D prev_offset + entry_size) break; =20 - sym_offset =3D reloc->sym->offset + reloc_addend(reloc); + sym_offset =3D arch_adjust_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..34f41ba6d910 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_adjust_offset(struct reloc *reloc, struct reloc *table); =20 #endif /* _ARCH_H */ --=20 2.42.0 From nobody Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC19117C8D for ; Sat, 7 Dec 2024 01:59:25 +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=1733536768; cv=none; b=Ole7qDhk+W/z6w6SPAdDr9qa9KTVKtKKCUanineJlEg37Pm+6rh7RZRZjPNyP4La/7UFK1eaaPwJ6lxsdy97ftcH+eAEMQeMHSe32q/uWxhtrfmrdGNckqWU5Akluv79kYj1oA3oS8XJT8f8ajmGfuHdL7QbXIHU2DgX56zzfVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536768; c=relaxed/simple; bh=eeYgVDaOUpgFXQ4u/yte0mm/eHnqyND2grkL94d+lvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KJeSvGKE5kK1e7XRC3bAe3UTxwxAXD5Pfc+2+UePSzWoIjwBDDV5kos98ZrhMN9d6cKbMs2j2RtkZOHqoP/r5MeNM8jpQmINzkM7SL81rsqkYfaYBSS01o26rmmQSmrDIaSgO+bZ/aY9Wn6j0+SBezTuYV9H21A16i7PO9zgQm8= 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 _____8BxIK_7q1NnHq1SAA--.5749S3; Sat, 07 Dec 2024 09:59:23 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S6; Sat, 07 Dec 2024 09:59:23 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 04/10] objtool: Handle unreachable entry of rodata Date: Sat, 7 Dec 2024 09:59:09 +0800 Message-ID: <20241207015915.1159-5-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj9xXoW7JFWfCFW8ZF15GF48Kw4DAwc_yoWDtwc_Aa 40grn7Jrs8XF4Iy3W0krs5WFy0ka1rWr4UXw17GF1Yg3W5J3yDuFZ2kFn0yFyF9rWSyFZx u3s3Ar1fCwnF9osvyTuYvTs0mTUanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUb38YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5 McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_ JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73 UjIFyTuYvjxU4AhLUUUUU 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 --- 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 4a23aae40c03..b85fc33fdd67 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1994,9 +1994,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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88F375B216 for ; Sat, 7 Dec 2024 01:59:28 +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=1733536770; cv=none; b=D6Z1VbytiJPmypITfsxGgIAxY4Qd+a+gaxUISd+UohoZflAnzrrPtyClwxjwTqEBINpWgwupZ652j/4TVChc3dZdcqmBzuiUFh+b4xHh5nn9MASJFjHAp9ATdcPjVOCmfhwMO7SBmfzmrWVlEdvnY77m+RIpJAyvv9I5K73Mrn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536770; c=relaxed/simple; bh=QVmrM8f3nhhAJnyGl7OMrM8qjRlcA+7PGC0I6StoDhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q+r1Rb+col/vM5ib4MGieLr6tnYdgT70GyUjqv9czqq70ikyoPKsTUILiNXFbhbxhK+k34IcF+ktvqwMPwulwlZag8C93l0iTY5tlocTLqch8p8Yw41xYAYHkMFGzIAp0u76JiXjfaflL2uBQzhFsIwxXOJvaMtte1M2hhLzOdg= 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 _____8CxSOH+q1NnIq1SAA--.29183S3; Sat, 07 Dec 2024 09:59:26 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S7; Sat, 07 Dec 2024 09:59:23 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 05/10] objtool/LoongArch: Add support for switch table Date: Sat, 7 Dec 2024 09:59:10 +0800 Message-ID: <20241207015915.1159-6-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S7 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4rWw18Wr1fWr43Zw43Jwc_yoWrXryDpF W7C345Kr45XryfWw13ta18uryakws7WFy7Jry3Kr93Aw4aqF1rtF4Sy3Z0yFy5ArsYyr4I qr4fKr4UCF4DAabCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8EeHDUUUUU== 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. 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 --- tools/objtool/arch/loongarch/special.c | 53 +++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index 87230ed570fd..f933f6b5bac6 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include #include =20 bool arch_support_alt_relocation(struct special_alt *special_alt, @@ -8,9 +9,59 @@ bool arch_support_alt_relocation(struct special_alt *speci= al_alt, return false; } =20 +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) { + 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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6F6877F10 for ; Sat, 7 Dec 2024 01:59:28 +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=1733536770; cv=none; b=KF8+MiLQ+mhAUa1fytJIvycsnNq5Nam6teFkyn7fNFAkAVFmABuDKeA4X7m6Bffr32cig3uqxRZ3CO/Sm9N16BFcIRcudzTR+t2pKzWHQWpuMH94I6yNTxihl0zjAI0FNBFJTSeWXjK9SRUOkRZXa2uFIKe33co9kJzRLzjBaCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536770; c=relaxed/simple; bh=9Q7dz9jM5oZIZ8a2FKoquMcBtbWYyAdtBn1B+G4tBco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdnSIYVMgONBkDm+ZX9194+FtrCQ2EOQFRj1YM78I+Hvg9aaUioiS+uH1/Oi3rBptxNWccDkwSnnbQgfG69Fo48sUcHM7Cfdss/g1q7hybIn03Eon1m9X5xusGj1X0fQrFsChIDALUFuW13SXQOQ3wgb+RpOQUk1RDyYU2TvDaI= 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 _____8AxbeL+q1NnJq1SAA--.29033S3; Sat, 07 Dec 2024 09:59:26 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S8; Sat, 07 Dec 2024 09:59:26 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 06/10] objtool/LoongArch: Get each table size of rodata Date: Sat, 7 Dec 2024 09:59:11 +0800 Message-ID: <20241207015915.1159-7-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxXF48uw1UZw43uw4DJF1xXrc_yoWrWFWrpF 95C34DtrWYqFy8WF47JF4ayrW3Jw48Wry7Gr9rKw1Fy343tr9Yqay2vasIk3Z5JrZ8Cr1S qFWrKr1xuF4kArXCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8XyCJUUUUU== Content-Type: text/plain; charset="utf-8" When compiling with Clang on LoongArch, there are unsorted table offset of rodata if there exist many jump tables, it will get the wrong table end and find the wrong 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. Signed-off-by: Tiezhu Yang --- tools/objtool/arch/loongarch/special.c | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index f933f6b5bac6..c1db0c59f9a1 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -1,6 +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, @@ -9,6 +10,87 @@ bool arch_support_alt_relocation(struct special_alt *spec= ial_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) { + if (reloc->sym->type !=3D STT_SECTION) { + *table_size =3D 0; + return; + } + + orig_table =3D malloc(sizeof(struct table_info)); + if (!orig_table) { + WARN("malloc failed"); + return; + } + + orig_table->insn_offset =3D reloc_addend(reloc); + reloc++; + orig_table->rodata_offset =3D 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) @@ -30,6 +112,7 @@ static struct reloc *find_reloc_by_table_annotate(struct= objtool_file *file, =20 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; } --=20 2.42.0 From nobody Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14E777F460 for ; Sat, 7 Dec 2024 01:59:28 +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=1733536771; cv=none; b=TIQI3qW1CgpeWklGxIMMJP7Cb2zC42uXW55aAPbbPnAOepGdba354YsFMHOIFEUdfQ/w5bjDYp1+iWb/Aj93khjACqzOcqCcBMBV+P/8/AT9BI7j/6b4PBibJ2zEpp1STlkjpSK1dUDMWibX/P2h1178WaGXEI/4fx4R3acdx9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536771; c=relaxed/simple; bh=eqaduniEyXH5k1KEnULm9YE0PxuykGi4EFID1nVVyOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SqPbeXsL198i+fUfa5E0dbUiI3rRFPt4e69bQF/T282eiRhlSQWDbATNiw3tMCBldL2GhtTAncOiQ9fIDOFh3egE3MbID28dntKChJC16MzHZ6TYEVhI+vaIQdRb5q32Q/g6Ww/wxG0EM5LVw3N40miXu4uPi1snhL70r6aQIVk= 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+L_q1NnKq1SAA--.29225S3; Sat, 07 Dec 2024 09:59:27 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S9; Sat, 07 Dec 2024 09:59:26 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 07/10] objtool/LoongArch: Add support for goto table Date: Sat, 7 Dec 2024 09:59:12 +0800 Message-ID: <20241207015915.1159-8-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S9 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4rWw18Wr1fWr43Zw43Jwc_yoWrXFy5pF W3C345Kr45Zr4Igr47tay09ryaya1IgFy7JrW7t34fAw43Xr1FyF1SvF9IyFWrCrZ5tr4I qr18Kr48CF4DAacCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8XyCJUUUUU== 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 --- 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 c1db0c59f9a1..7dbdf3d388a6 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -121,6 +121,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) @@ -131,8 +155,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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18FE6126BF9 for ; Sat, 7 Dec 2024 01:59:29 +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=1733536771; cv=none; b=WoVIsE/U1Pt7bSje2DfFjEmEhliOVqFFaEfF+Mmjlsve9ujZ1lrZqMrqu26QM8IuJ+U/rIQwvO145VSablHnuj6DGUrcnoI2rSykAKy/gkvx5wh9EVtG2pBdl3VsLU5yZS5wx4PzoOgv0ntPcsKwl5RzAfbOGTYsXLURGAT6Q64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536771; c=relaxed/simple; bh=B3KZMIw95MBg61/d6zZGkkqFyUQXS571JeCHkftd3nY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/F7blJgckulZr15wSejqsrXVM9BkpcwzFIJ7rAX4N16VRtGTmPgHHYimCFexNwOjyukz29udoXH7HVjavFlw+iFH3M0nAegDDzCf60fUD0FcyMeO6zMqtM3gNtXww4TxW/Wjo09GxjUhoWfeRIZGU7l5SI1phE88qSSNXo4wBY= 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 _____8AxquEArFNnNa1SAA--.32929S3; Sat, 07 Dec 2024 09:59:28 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S10; Sat, 07 Dec 2024 09:59:27 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 08/10] LoongArch: Enable jump table for objtool Date: Sat, 7 Dec 2024 09:59:13 +0800 Message-ID: <20241207015915.1159-9-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S10 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7uFWDWF4fuF1fAw1xCr1xJFc_yoW8WrW3pw s7Zr4kKr4kWF1ktrZrJ3ySgr98JrnrKr43ZF42ga48ArW7Z3yUZr48ta9rXF15AwsxJrWI qFWfKasIvFWUJ3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWrXVW3 AwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU0E38UUUUUU== 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 --- 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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EF5712F375 for ; Sat, 7 Dec 2024 01:59:30 +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=1733536772; cv=none; b=BZ4XfR22BFoYokLAuybEl/RJ4ax6PBFmkiM1AIsmaHjEPBn4kdAWCM5oYDSSHoGE2tQofcULg7wOtRpk7Yi7FnpX17Ooen4zrHmQae6iVKWl5kEq4rzmYGUKq9+VkhvNf7bpcC7SKNKJUyDgsU5RLojlk/E7jvBjxW0IHsZbKEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536772; c=relaxed/simple; bh=ZtOhJE1cTY/xHXj1EAXPWLuV43L7x8hjDPN8Z46WR28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETRXn8uCCarSAyylI3m0GNmCBYPfmYxAYmxfWcgII4EDJJ8Oit9snCp6UX+2h8xgJn5Q4ClUiK+Y32AUJo/2mRTqJcSLY5ECTN+b8b2G2jZ2HKqlW6ErncDxQzVnUFPx978gCRT4bH3eR/ptsv6v/C1gd9CSa9UauBy/otex/sk= 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 _____8CxPuMArFNnO61SAA--.28971S3; Sat, 07 Dec 2024 09:59:28 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S11; Sat, 07 Dec 2024 09:59:28 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 09/10] LoongArch: Convert unreachable() to BUG() Date: Sat, 7 Dec 2024 09:59:14 +0800 Message-ID: <20241207015915.1159-10-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S11 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj9xXoWrZr4rZFW3JF13tryfWryrKrX_yoWkCwcEyr yxJw1UGrWrZFZrAw1Utr4rWryFq3WrKFWY9wn7Zay5A3W5t348t3y5tas8Ar1ktFWkGrZ5 t39YvFZYkw1xKosvyTuYvTs0mTUanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUb3xYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWrXVW3 AwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU0NJ57UUUUU== 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 --- 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 Thu Dec 18 23:15:13 2025 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FA8413C836 for ; Sat, 7 Dec 2024 01:59:32 +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=1733536774; cv=none; b=kn/PWjdcZsi8yCv795kEHSSA4UCdfCh3k7eC4tGiGEeJBOusAg/4Beqv7iUYdWs8H+0cJJOMlMP2gvZ3Omjz4AsH/VaUrflzb2t+0z8KhDm5M8RemUoVEueL/S4DWaL6W3WbmT2Rh1/Zss0j0712ZRbZNsraLrri2fixCiGZqyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733536774; c=relaxed/simple; bh=MhDtD1hnbhebvcmqXJ5exN8uWQg9/37rRWH+w7S3d+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rhRaivRm0ngnM7CK/SumpWSB+7gltoT7jwsOYtN47EJ4GaEKKIi1N0Pbhj+RBslUkuZFyLkmB+mbTMoiFbD4EeWYpNM5/3m7AcKu91fm5wVe3bOvFygsOp694dEoQF3F1O87vc4y7LKjuKUh/3eVAbD3aietwIjrZNxIJv1e+Ms= 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 _____8BxIK8BrFNnS61SAA--.5753S3; Sat, 07 Dec 2024 09:59:29 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowMBx_uD1q1Nn3Wd5AA--.42544S12; Sat, 07 Dec 2024 09:59:28 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 10/10] drm/amd/display: Mark dc_fixpt_from_fraction() noinline Date: Sat, 7 Dec 2024 09:59:15 +0800 Message-ID: <20241207015915.1159-11-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241207015915.1159-1-yangtiezhu@loongson.cn> References: <20241207015915.1159-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: qMiowMBx_uD1q1Nn3Wd5AA--.42544S12 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7ZF17KFWruF4DAw1DtrWDGFX_yoW8Gr1DpF 43JFy5Wa1kJF1xKa98Ja43uFW3Ca95XrW8Wr1UArs5Aa4UZ3WvgFZxKw1DGFWakF4Yyr4S vFWDKay7KFn2yrcCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26rWY 6Fy7McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU0E38UUUUUU== 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. Cc: amd-gfx@lists.freedesktop.org Signed-off-by: Tiezhu Yang --- 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