From patchwork Tue Oct 15 11:39:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836244 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 118071E6321; Tue, 15 Oct 2024 11:39: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=1728992363; cv=none; b=Y3TWjeDHprUJVaHXp8RIHjIfr4Czx1Pv3X6ivAYmkZV1+wWOjHgI6bxEfE06K/2IuGsxDXlWjpSLRC0Ws1cF+yaxodnYnNeq/wj0SfvcTXdLJtebm5Luou0R+DZVX8aEgCX1V2CSO5Efdqc2eES0zrrgSyhHW3mae8Wxz/qJBT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992363; c=relaxed/simple; bh=+QVfX6uapABdVeCjMpgWmzX0OQSpPJMdLuTtOhOojko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nd77opW9tQspoz3qKFz6dn4rq/BgRBagLlgeiC9IjQ+6xSi2KjF1KAojHLzzkYAuuBa0ctJa+KcdK446ETAZBmbg8g/U46C83ETRNwxkOh7j01nD+f1D9xR9rl+AWyrKuuA5/6BpTpMuq+lr2FcR1HN1u3K/SuHHx6Hnz0VXUnA= 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 _____8Cx44hmVA5n6X8dAA--.42655S3; Tue, 15 Oct 2024 19:39:18 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S3; Tue, 15 Oct 2024 19:39:17 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/6] objtool: Check various symbol types for jump table Date: Tue, 15 Oct 2024 19:39:10 +0800 Message-ID: <20241015113915.12623-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJFWDKF4kAF4kGrW3Aw4xGrX_yoW5GFykpF sxG345Kr4Yqr1xWwnrtFZY9Fy3Gws7WFnrJrZrKr4Fv3sFvr1rKFWakw1ay3WDGr1Svw47 XF4Ygry7uF4UA3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU AVWUtwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIev Ja73UjIFyTuYvjxU466zUUUUU 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(). This is preparation for later patch on LoongArch, there is no effect for the other archs with this patch. Signed-off-by: Tiezhu Yang --- tools/objtool/check.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6604f5d038aa..cda7306d07c2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2079,6 +2079,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, unsigned int prev_offset = 0; struct reloc *reloc = table; struct alternative *alt; + unsigned long offset; /* * Each @reloc is a switch table relocation which points to the target @@ -2094,12 +2095,16 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, if (prev_offset && reloc_offset(reloc) != prev_offset + 8) break; + if (reloc->sym->type == STT_SECTION) + offset = reloc_addend(reloc); + else + offset = reloc->sym->offset; + /* Detect function pointers from contiguous objects: */ - if (reloc->sym->sec == pfunc->sec && - reloc_addend(reloc) == pfunc->offset) + if (reloc->sym->sec == pfunc->sec && offset == pfunc->offset) break; - dest_insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + dest_insn = find_insn(file, reloc->sym->sec, offset); if (!dest_insn) break; @@ -2137,6 +2142,7 @@ static struct reloc *find_jump_table(struct objtool_file *file, { struct reloc *table_reloc; struct instruction *dest_insn, *orig_insn = insn; + unsigned long offset; /* * Backward search using the @first_jump_src links, these help avoid @@ -2160,7 +2166,13 @@ static struct reloc *find_jump_table(struct objtool_file *file, table_reloc = arch_find_switch_table(file, insn); if (!table_reloc) continue; - dest_insn = find_insn(file, table_reloc->sym->sec, reloc_addend(table_reloc)); + + if (table_reloc->sym->type == STT_SECTION) + offset = reloc_addend(table_reloc); + else + offset = table_reloc->sym->offset; + + dest_insn = find_insn(file, table_reloc->sym->sec, offset); if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != func) continue; From patchwork Tue Oct 15 11:39:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836245 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F8E01E8855; Tue, 15 Oct 2024 11:39:21 +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=1728992364; cv=none; b=pvUZun5s63qp4g4iBnq+WjdSpUJ91leJsTzaFw7sTX7164EVfkz/xtr3BceQ13tnKxvLwJ854D/nEvrOT4I/2DIkwSVn+9oJ08wn9osRWusL3qaAI9e8FaKj2HcBY0K4Y4tbwXPcpvdJ9fBCG9F5LEGwfjYFSJpo3jmLdWmhLe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992364; c=relaxed/simple; bh=BMzaHd/KZvfQw6XtDmSYagMqPYpWkf/ORu4doTVMsno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L31nGz0fm39I2QC1leyIS/X2jSBZ/dr31jpkFdDRPTSiAv8xQkDHK543dyW6CN57P/b4pCPNl9kUqhhIyC7P6GtcMTbQl4Oo6v8YE+aY/mYF3uAWNDVH6u4O1clseqt581UicjLFGotGzbrzCN3FruPvoO62mBUYJ3B976glScI= 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 _____8DxfWtnVA5n7n8dAA--.42285S3; Tue, 15 Oct 2024 19:39:19 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S4; Tue, 15 Oct 2024 19:39:18 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/6] objtool/LoongArch: Add support for jump table Date: Tue, 15 Oct 2024 19:39:11 +0800 Message-ID: <20241015113915.12623-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4rWw4UXF1UCw1xXr4fJFc_yoW5KrWkpF W7C345Kr45XryfWw43ta18uryakws7WFy7Gry3Kr93Aw4aqF1rtFsayFn0yF15ursYyr4I qr4fKr4UCF4DAabCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8EeHDUUUUU== The objtool program needs to analysis the control flow of each object file generated by compiler toolchain, 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, the relocation is directly on the jump instruction and to the table. But on LoongArch, the relocation is on some kind of instruction prior to the jump instruction, with scheduling it is not easy to tell the offset of that instruction from the jump instruction. Furthermore, because LoongArch has -fsection-anchors the relocation may actually points to a section anchor instead of the table itself. So it needs some non-trivial data flow analysis in objtool without special support of compiler. The good news is that the GCC patch "LoongArch: Add support to annotate tablejump" has been merged into the upstream mainline, the changes are very trivial in GCC, it makes life much easier for jump 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=gcc.git;a=commit;h=0ee028f55640 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/loongarch/special.c index 9bba1e9318e0..65b1ed297d57 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include + #include bool arch_support_alt_relocation(struct special_alt *special_alt, @@ -8,8 +10,57 @@ bool arch_support_alt_relocation(struct special_alt *special_alt, return false; } +static struct reloc *find_reloc_by_table_annotate(struct objtool_file *file, + struct instruction *insn) +{ + struct section *rsec; + struct reloc *reloc; + unsigned long offset; + + rsec = find_section_by_name(file->elf, ".rela.discard.tablejump_annotate"); + 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 = reloc->sym->offset; + if (insn->offset == offset) { + reloc++; + return reloc; + } + } + + return NULL; +} + struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn) { - return NULL; + struct reloc *annotate_reloc; + struct reloc *rodata_reloc; + struct section *table_sec; + unsigned long table_offset; + + annotate_reloc = find_reloc_by_table_annotate(file, insn); + if (!annotate_reloc) + return NULL; + + table_sec = annotate_reloc->sym->sec; + table_offset = annotate_reloc->sym->offset; + + /* + * Each table entry has a rela associated with it. The rela + * should reference text in the same function as the original + * instruction. + */ + rodata_reloc = find_reloc_by_dest(file->elf, table_sec, table_offset); + if (!rodata_reloc) + return NULL; + + return rodata_reloc; } From patchwork Tue Oct 15 11:39:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836246 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 226101E7658; Tue, 15 Oct 2024 11:39:21 +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=1728992364; cv=none; b=Yu9MWw5x4ou3xYWELgGvweUfINu0dRgZmoLQwC1ngkpvN0eNOdDdlJMZqTIR+V9mgAGVOHqMeCdJ5SJyyo5S+reXJK/oUimTPRLpDvekET69AuPVn1AU7WQU7WTNdgpKgBXY1KeeHhCip6/XUPYtneFSzA2rpE/CKfa7gZqa/Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992364; c=relaxed/simple; bh=SbfJr9+jdDKjyBPYTFn1HGRQF9YgV69BHlnKnAozTHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cuRLV0KbT90tSAb/s8ZLZODjA10mcNBNYdXTPXmJxyTcYDcLYPXazdatwni0jWx2OXSUkuCX2z82izv8VOn/oZvMWUjNzCMtO7FB8FvTbcviVpgnkiyIp5L2X24cS5XyJ/LheERPAQ86kYE3pEaBADmUxy3c5qgASIHNk62P7WA= 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 _____8DxyrFnVA5n8n8dAA--.42637S3; Tue, 15 Oct 2024 19:39:19 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S5; Tue, 15 Oct 2024 19:39:19 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/6] LoongArch: Enable jump table for objtool Date: Tue, 15 Oct 2024 19:39:12 +0800 Message-ID: <20241015113915.12623-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7tF47uFWrtr1xZw15Kw13Jrc_yoW8uF1kpr Z7Zr1kGr4kXF4vqry3J3yFg398AFnrtr4fXF4xWa4rCrWSq3yavw40yrsrGa40k398J3yS gFWfGa4ayF4UGwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8EeHDUUUUU== For now, it can remove -fno-jump-tables and then enable jump table for objtool if the compiler has option -mannotate-tablejump. Signed-off-by: Tiezhu Yang --- arch/loongarch/Kconfig | 8 +++++++- arch/loongarch/Makefile | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index bb35c34f86d2..49ed776cb253 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -150,7 +150,7 @@ config LOONGARCH select HAVE_LIVEPATCH select HAVE_MOD_ARCH_SPECIFIC select HAVE_NMI - select HAVE_OBJTOOL if AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB + select HAVE_OBJTOOL if TOOLCHAIN_SUPPORTS_OBJTOOL select HAVE_PCI select HAVE_PERF_EVENTS select HAVE_PERF_REGS @@ -284,6 +284,12 @@ config AS_HAS_LBT_EXTENSION config AS_HAS_LVZ_EXTENSION def_bool $(as-instr,hvcl 0) +config CC_HAS_ANNOTATE_TABLEJUMP + def_bool $(cc-option,-mannotate-tablejump) + +config TOOLCHAIN_SUPPORTS_OBJTOOL + def_bool AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && CC_HAS_ANNOTATE_TABLEJUMP + menu "Kernel type and options" source "kernel/Kconfig.hz" diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index ae3f80622f4c..69a3b4ae6c60 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -99,10 +99,7 @@ KBUILD_AFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno KBUILD_CFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax) KBUILD_AFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub) KBUILD_CFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub) - -ifdef CONFIG_OBJTOOL -KBUILD_CFLAGS += -fno-jump-tables -endif +KBUILD_CFLAGS += $(call cc-option,-mannotate-tablejump) KBUILD_RUSTFLAGS += --target=loongarch64-unknown-none-softfloat KBUILD_RUSTFLAGS_KERNEL += -Zdirect-access-external-data=yes From patchwork Tue Oct 15 11:39:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836247 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 923281E9080; Tue, 15 Oct 2024 11:39: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=1728992364; cv=none; b=er2TnZBu9LpOOScJJbo6ohvEYvjWcNYk2scC9FDlRHa7MY4lvvEEzLL3FTyDjxISCS+6NcjhHLccUDkgLopuwVojBm6POu3/cGu//cNP0dwncA3KibUTkp82OVbUJrwNgfqZno9vJisZQJbaPwVKBE6kpMvqMa7JTS4xtPMyXsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992364; c=relaxed/simple; bh=rqu0fWfmQu2kYrqp0OPfNmQup6sQp3MP6/e6QsJ8MWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GU6gguRw02MTGDVjbrNBRjYYsm4pHw/Z01uzjnEikg3Sc+6KTt4RyqScWeb47JIyna0+V/VJ85gqyosjz95eKn09ZSpJnrJ6rBRM2dsVDkP8v6PN519cvK9sC3vkPYDqYtONaKGbXV9dX1NGJHDf4OeyMkpx7hpEL45bT3SRlAI= 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 _____8Cx44hoVA5n938dAA--.42656S3; Tue, 15 Oct 2024 19:39:20 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S6; Tue, 15 Oct 2024 19:39:19 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/6] bpf, core: Add weak arch_prepare_goto() Date: Tue, 15 Oct 2024 19:39:13 +0800 Message-ID: <20241015113915.12623-5-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4rWw1rKryfXF13uF17Jwc_yoW5AFW7pa s5u3yFkr4rXw4S934UJw4vgrWakr48KrZ8G3s5J34xAw4Ygw18ta4vgFnIyFZ8CrnYkr4I qw1UKryUKa4DAFgCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8EeHDUUUUU== X-Patchwork-Delegate: bpf@iogearbox.net The objtool program needs 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. In the past, objtool only works on x86, where objtool can find the relocation against the nearest instruction before the jump instruction, which points to the goto table, because there is only one table jump instruction even if there is more than one computed goto in a function such as ___bpf_prog_run(). In fact, the compiler behaviors are different for various archs. On RISC machines (for example LoongArch) this approach does not work: with -fsection-anchors (often enabled at -O1 or above) the relocation entry may actually points to the section anchor instead of the table. Furthermore, objdump kernel/bpf/core.o shows that there are many table jump instructions in ___bpf_prog_run() with more than one computed gotos, but there are no relocations which actually points to the table for some table jump instructions on LoongArch. For the jump table of switch cases, a GCC patch "LoongArch: Add support to annotate tablejump" has been merged into the upstream mainline, it makes life much easier with 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 so easy to implement in the compiler, especially if there is more than one computed goto in a function. Without the help of compiler, in order to figure out the address of goto table by interpreting the LoongArch machine code, add a function arch_prepare_goto() for goto table, it is an empty weak definition and is only overridden by archs that have special requirements. This is preparation for later patch on LoongArch, there is no any effect for the other archs with this patch. Suggested-by: Xi Ruoyao Signed-off-by: Tiezhu Yang --- kernel/bpf/core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 5e77c58e0601..81e5d42619d5 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1706,6 +1706,14 @@ bool bpf_opcode_in_insntable(u8 code) } #ifndef CONFIG_BPF_JIT_ALWAYS_ON +/* + * This symbol is an empty weak definition and is only overridden + * by archs that have special requirements. + */ +#ifndef arch_prepare_goto +#define arch_prepare_goto() +#endif + /** * ___bpf_prog_run - run eBPF program on a given context * @regs: is the array of MAX_BPF_EXT_REG eBPF pseudo-registers @@ -1743,6 +1751,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) #define CONT_JMP ({ insn++; goto select_insn; }) select_insn: + arch_prepare_goto(); goto *jumptable[insn->code]; /* Explicitly mask the register-based shift amounts with 63 or 31 From patchwork Tue Oct 15 11:39:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836248 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8F071EF0BD; Tue, 15 Oct 2024 11:39: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=1728992366; cv=none; b=j1ZD+UQtBTyKl82knVeO+NG9aLIsNYPbCIVqM0j7k8dBKiqhqEn1joKgLEc2okBuPj0Zx4Aa4Q7DcTgwU6yER4ZIoZVATgtDKdAB5DI7TJq5d6q9oYaYP+cLijzpj4KuED1pjguUlgIjeFrFpCj6AbYSLXfMJ7a138/euQKZKQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992366; c=relaxed/simple; bh=ApEpc+gMzlX7HhsNG8gGJN7ES63x/5gdU3xsJJp/lNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V6qPTqFR1MUVvjvhwHkuVHpmH0HRljlMuWat1cLdk/XcTky/ZNqPP6I/H8nrlasLoGQvRF6UyZfnXhpnwaZzlp4tNyoAetgTliWFRLOc4oOvK3BdLOd33QUjETf8BueX4k8IxqKSN4DOgknfmlN1+C4st/Bq4yiaAQ1E1BuP4R0= 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 _____8BxkuhoVA5n_H8dAA--.42777S3; Tue, 15 Oct 2024 19:39:20 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S7; Tue, 15 Oct 2024 19:39:20 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/6] LoongArch: Define specified arch_prepare_goto() Date: Tue, 15 Oct 2024 19:39:14 +0800 Message-ID: <20241015113915.12623-6-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S7 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7CF1ftr4xAF43CF4xCF18CrX_yoW8WrW5pF 9rZ3WkKFZ7Wr4fCrZrta4UWr15Xan3WF47WF1Iqa48AF90q34vyr1kK34DAFyUCan5JrWI gF1fWa4YgF4UJabCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8EeHDUUUUU== In order to figure out the address of goto table by interpreting the LoongArch machine code, define specified arch_prepare_goto() to insert the relocation information of goto table address, then it can find the destination address of the table jump instruction. Suggested-by: Xi Ruoyao Signed-off-by: Tiezhu Yang --- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/compiler.h | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 arch/loongarch/include/asm/compiler.h diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 49ed776cb253..9eed0bde678f 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -106,6 +106,7 @@ config LOONGARCH select GPIOLIB select HAS_IOPORT select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_COMPILER_H select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN diff --git a/arch/loongarch/include/asm/compiler.h b/arch/loongarch/include/asm/compiler.h new file mode 100644 index 000000000000..424268a92c40 --- /dev/null +++ b/arch/loongarch/include/asm/compiler.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Loongson Technology Corporation Limited + */ +#ifndef _ASM_COMPILER_H +#define _ASM_COMPILER_H + +#ifndef CONFIG_BPF_JIT_ALWAYS_ON +#define arch_prepare_goto() \ + asm volatile(".reloc\t., R_LARCH_NONE, %0" : : "i" (jumptable)) +#endif + +#endif /* _ASM_COMPILER_H */ From patchwork Tue Oct 15 11:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13836249 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F1781F12E4; Tue, 15 Oct 2024 11:39: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=1728992367; cv=none; b=Nv7hQWYtCALyfB84jajHugKIb5Yp4TRNLy5ABgR2a/+2jcmOxdUPF4L4AWcfHsJiEngPH2fbbvGCA8PNbxmC+Ozvs7Nw+RHgorYNveoe7vm43ZJCbUW2RNRIhA86GobPD3GedONO85sBGuhjXiadUqmHo29CSpnpZSAOdTkOQNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728992367; c=relaxed/simple; bh=rr0nWEYrqLlVaPbZ9c1h3jCsPjkNEijFpvF3AjTKWk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gaz3hhUTwnSlNxLsXOkAHzP6e5PFSyFI3jouAPJ1tOD5u1ubWRB8AwPmdim7f1BkYLeGVfGbl0ikOatDh7yXlcJiLNlDMVmwjr6hyqXwTwBy/fpor7ACdjbTYZyeD7pzSx8Sf744rIBjKol+Z5pIYhYOhhbAfSIzdh+lCKAk/ko= 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 _____8Cx44hpVA5nAIAdAA--.42657S3; Tue, 15 Oct 2024 19:39:21 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front2 (Coremail) with SMTP id qciowMCxbcdkVA5n6E0uAA--.9583S8; Tue, 15 Oct 2024 19:39:21 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Josh Poimboeuf , Peter Zijlstra Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 6/6] objtool/LoongArch: Add support for goto table Date: Tue, 15 Oct 2024 19:39:15 +0800 Message-ID: <20241015113915.12623-7-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241015113915.12623-1-yangtiezhu@loongson.cn> References: <20241015113915.12623-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qciowMCxbcdkVA5n6E0uAA--.9583S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7KFWktry3tF13Ar4UZryfZrc_yoW8GFykpa 13C3s8Kw45XrWxKr13tay8uFy3Aa1xW3W2grWIkr93Zw43XF4rtF1SvF98tFWxWw4rtr4I qrs5Kr15AF1UA3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU92b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2 xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x 0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AK xVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67 AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI 42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVF xhVjvjDU0xZFpf9x07jz2NtUUUUU= If find_reloc_by_table_annotate() failed, it means that there is no relocation info of switch table address in the section ".rela.discard.tablejump_annotate", then objtool can find the relocation against the nearest instruction before the jump instruction with find_reloc_by_dest_range(), which points to the goto table. Signed-off-by: Tiezhu Yang --- tools/objtool/arch/loongarch/special.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/special.c index 65b1ed297d57..d2a6071d772f 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -47,8 +47,18 @@ struct reloc *arch_find_switch_table(struct objtool_file *file, unsigned long table_offset; annotate_reloc = find_reloc_by_table_annotate(file, insn); - if (!annotate_reloc) - return NULL; + if (!annotate_reloc) { + annotate_reloc = find_reloc_by_dest_range(file->elf, insn->sec, + insn->offset, insn->len); + if (!annotate_reloc) + return NULL; + + if (!annotate_reloc->sym->sec->rodata) + return NULL; + + if (reloc_type(annotate_reloc) != R_LARCH_NONE) + return NULL; + } table_sec = annotate_reloc->sym->sec; table_offset = annotate_reloc->sym->offset;