From nobody Sun Apr 26 21:38:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D272C43334 for ; Wed, 22 Jun 2022 10:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350056AbiFVKQ2 (ORCPT ); Wed, 22 Jun 2022 06:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350362AbiFVKQG (ORCPT ); Wed, 22 Jun 2022 06:16:06 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2383B287; Wed, 22 Jun 2022 03:15:58 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LSfQg17f4zDsL4; Wed, 22 Jun 2022 18:15:23 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 From: Chen Zhongjin To: , , , , , CC: , , , , , Subject: [PATCH v2 1/5] objtool: Make ORC type code arch-specific Date: Wed, 22 Jun 2022 18:13:40 +0800 Message-ID: <20220622101344.38002-2-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220622101344.38002-1-chenzhongjin@huawei.com> References: <20220622101344.38002-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Madhavan T. Venkataraman" The ORC code needs to be reorganized into arch-specific and generic parts so that architectures other than X86 can use the generic parts in orc_dump and orc_gen. Create the following two files: - tools/objtool/include/objtool/orc.h - tools/objtool/arch/x86/orc.c Make the following function arch-specific: - init_orc_entry() - reg_name() - orc_type_name() Then the orc_gen and orc_dump don't involve any x86 specific content. Signed-off-by: Madhavan T. Venkataraman Signed-off-by: Chen Zhongjin --- tools/objtool/arch/x86/Build | 1 + tools/objtool/arch/x86/orc.c | 137 ++++++++++++++++++++++++++++ tools/objtool/include/objtool/orc.h | 17 ++++ tools/objtool/orc_dump.c | 59 +----------- tools/objtool/orc_gen.c | 76 +-------------- 5 files changed, 159 insertions(+), 131 deletions(-) create mode 100644 tools/objtool/arch/x86/orc.c create mode 100644 tools/objtool/include/objtool/orc.h diff --git a/tools/objtool/arch/x86/Build b/tools/objtool/arch/x86/Build index 9f7869b5c5e0..3dedb2fd8f3a 100644 --- a/tools/objtool/arch/x86/Build +++ b/tools/objtool/arch/x86/Build @@ -1,5 +1,6 @@ objtool-y +=3D special.o objtool-y +=3D decode.o +objtool-y +=3D orc.o =20 inat_tables_script =3D ../arch/x86/tools/gen-insn-attr-x86.awk inat_tables_maps =3D ../arch/x86/lib/x86-opcode-map.txt diff --git a/tools/objtool/arch/x86/orc.c b/tools/objtool/arch/x86/orc.c new file mode 100644 index 000000000000..8543074d0b9e --- /dev/null +++ b/tools/objtool/arch/x86/orc.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2017 Josh Poimboeuf + */ + +#include + +#include + +#include +#include + +int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, + struct instruction *insn) +{ + struct cfi_reg *bp =3D &cfi->regs[CFI_BP]; + + memset(orc, 0, sizeof(*orc)); + + if (!cfi) { + orc->end =3D 0; + orc->sp_reg =3D ORC_REG_UNDEFINED; + return 0; + } + + orc->end =3D cfi->end; + + if (cfi->cfa.base =3D=3D CFI_UNDEFINED) { + orc->sp_reg =3D ORC_REG_UNDEFINED; + return 0; + } + + switch (cfi->cfa.base) { + case CFI_SP: + orc->sp_reg =3D ORC_REG_SP; + break; + case CFI_SP_INDIRECT: + orc->sp_reg =3D ORC_REG_SP_INDIRECT; + break; + case CFI_BP: + orc->sp_reg =3D ORC_REG_BP; + break; + case CFI_BP_INDIRECT: + orc->sp_reg =3D ORC_REG_BP_INDIRECT; + break; + case CFI_R10: + orc->sp_reg =3D ORC_REG_R10; + break; + case CFI_R13: + orc->sp_reg =3D ORC_REG_R13; + break; + case CFI_DI: + orc->sp_reg =3D ORC_REG_DI; + break; + case CFI_DX: + orc->sp_reg =3D ORC_REG_DX; + break; + default: + WARN_FUNC("unknown CFA base reg %d", + insn->sec, insn->offset, cfi->cfa.base); + return -1; + } + + switch (bp->base) { + case CFI_UNDEFINED: + orc->bp_reg =3D ORC_REG_UNDEFINED; + break; + case CFI_CFA: + orc->bp_reg =3D ORC_REG_PREV_SP; + break; + case CFI_BP: + orc->bp_reg =3D ORC_REG_BP; + break; + default: + WARN_FUNC("unknown BP base reg %d", + insn->sec, insn->offset, bp->base); + return -1; + } + + orc->sp_offset =3D cfi->cfa.offset; + orc->bp_offset =3D bp->offset; + orc->type =3D cfi->type; + + return 0; +} + +static const char *reg_name(unsigned int reg) +{ + switch (reg) { + case ORC_REG_PREV_SP: + return "prevsp"; + case ORC_REG_DX: + return "dx"; + case ORC_REG_DI: + return "di"; + case ORC_REG_BP: + return "bp"; + case ORC_REG_SP: + return "sp"; + case ORC_REG_R10: + return "r10"; + case ORC_REG_R13: + return "r13"; + case ORC_REG_BP_INDIRECT: + return "bp(ind)"; + case ORC_REG_SP_INDIRECT: + return "sp(ind)"; + default: + return "?"; + } +} + +const char *orc_type_name(unsigned int type) +{ + switch (type) { + case UNWIND_HINT_TYPE_CALL: + return "call"; + case UNWIND_HINT_TYPE_REGS: + return "regs"; + case UNWIND_HINT_TYPE_REGS_PARTIAL: + return "regs (partial)"; + default: + return "?"; + } +} + +void orc_print_reg(unsigned int reg, int offset) +{ + if (reg =3D=3D ORC_REG_BP_INDIRECT) + printf("(bp%+d)", offset); + else if (reg =3D=3D ORC_REG_SP_INDIRECT) + printf("(sp)%+d", offset); + else if (reg =3D=3D ORC_REG_UNDEFINED) + printf("(und)"); + else + printf("%s%+d", reg_name(reg), offset); +} diff --git a/tools/objtool/include/objtool/orc.h b/tools/objtool/include/ob= jtool/orc.h new file mode 100644 index 000000000000..4604c15ba07b --- /dev/null +++ b/tools/objtool/include/objtool/orc.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2015-2017 Josh Poimboeuf + */ + +#ifndef _OBJTOOL_ORC_H +#define _OBJTOOL_ORC_H + +#include +#include + +int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, + struct instruction *insn); +const char *orc_type_name(unsigned int type); +void orc_print_reg(unsigned int reg, int offset); + +#endif /* _OBJTOOL_ORC_H */ diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c index f5a8508c42d6..9bdda23f33c3 100644 --- a/tools/objtool/orc_dump.c +++ b/tools/objtool/orc_dump.c @@ -5,63 +5,11 @@ =20 #include #include -#include #include +#include #include #include =20 -static const char *reg_name(unsigned int reg) -{ - switch (reg) { - case ORC_REG_PREV_SP: - return "prevsp"; - case ORC_REG_DX: - return "dx"; - case ORC_REG_DI: - return "di"; - case ORC_REG_BP: - return "bp"; - case ORC_REG_SP: - return "sp"; - case ORC_REG_R10: - return "r10"; - case ORC_REG_R13: - return "r13"; - case ORC_REG_BP_INDIRECT: - return "bp(ind)"; - case ORC_REG_SP_INDIRECT: - return "sp(ind)"; - default: - return "?"; - } -} - -static const char *orc_type_name(unsigned int type) -{ - switch (type) { - case UNWIND_HINT_TYPE_CALL: - return "call"; - case UNWIND_HINT_TYPE_REGS: - return "regs"; - case UNWIND_HINT_TYPE_REGS_PARTIAL: - return "regs (partial)"; - default: - return "?"; - } -} - -static void print_reg(unsigned int reg, int offset) -{ - if (reg =3D=3D ORC_REG_BP_INDIRECT) - printf("(bp%+d)", offset); - else if (reg =3D=3D ORC_REG_SP_INDIRECT) - printf("(sp)%+d", offset); - else if (reg =3D=3D ORC_REG_UNDEFINED) - printf("(und)"); - else - printf("%s%+d", reg_name(reg), offset); -} - int orc_dump(const char *_objname) { int fd, nr_entries, i, *orc_ip =3D NULL, orc_size =3D 0; @@ -195,14 +143,13 @@ int orc_dump(const char *_objname) printf("%llx:", (unsigned long long)(orc_ip_addr + (i * sizeof(int)) + = orc_ip[i])); } =20 - printf(" sp:"); =20 - print_reg(orc[i].sp_reg, bswap_if_needed(orc[i].sp_offset)); + orc_print_reg(orc[i].sp_reg, bswap_if_needed(orc[i].sp_offset)); =20 printf(" bp:"); =20 - print_reg(orc[i].bp_reg, bswap_if_needed(orc[i].bp_offset)); + orc_print_reg(orc[i].bp_reg, bswap_if_needed(orc[i].bp_offset)); =20 printf(" type:%s end:%d\n", orc_type_name(orc[i].type), orc[i].end); diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index dd3c64af9db2..a7d060ba14d0 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -7,86 +7,12 @@ #include =20 #include -#include =20 #include +#include #include #include =20 -static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, - struct instruction *insn) -{ - struct cfi_reg *bp =3D &cfi->regs[CFI_BP]; - - memset(orc, 0, sizeof(*orc)); - - if (!cfi) { - orc->end =3D 0; - orc->sp_reg =3D ORC_REG_UNDEFINED; - return 0; - } - - orc->end =3D cfi->end; - - if (cfi->cfa.base =3D=3D CFI_UNDEFINED) { - orc->sp_reg =3D ORC_REG_UNDEFINED; - return 0; - } - - switch (cfi->cfa.base) { - case CFI_SP: - orc->sp_reg =3D ORC_REG_SP; - break; - case CFI_SP_INDIRECT: - orc->sp_reg =3D ORC_REG_SP_INDIRECT; - break; - case CFI_BP: - orc->sp_reg =3D ORC_REG_BP; - break; - case CFI_BP_INDIRECT: - orc->sp_reg =3D ORC_REG_BP_INDIRECT; - break; - case CFI_R10: - orc->sp_reg =3D ORC_REG_R10; - break; - case CFI_R13: - orc->sp_reg =3D ORC_REG_R13; - break; - case CFI_DI: - orc->sp_reg =3D ORC_REG_DI; - break; - case CFI_DX: - orc->sp_reg =3D ORC_REG_DX; - break; - default: - WARN_FUNC("unknown CFA base reg %d", - insn->sec, insn->offset, cfi->cfa.base); - return -1; - } - - switch (bp->base) { - case CFI_UNDEFINED: - orc->bp_reg =3D ORC_REG_UNDEFINED; - break; - case CFI_CFA: - orc->bp_reg =3D ORC_REG_PREV_SP; - break; - case CFI_BP: - orc->bp_reg =3D ORC_REG_BP; - break; - default: - WARN_FUNC("unknown BP base reg %d", - insn->sec, insn->offset, bp->base); - return -1; - } - - orc->sp_offset =3D cfi->cfa.offset; - orc->bp_offset =3D bp->offset; - orc->type =3D cfi->type; - - return 0; -} - static int write_orc_entry(struct elf *elf, struct section *orc_sec, struct section *ip_sec, unsigned int idx, struct section *insn_sec, unsigned long insn_off, --=20 2.17.1 From nobody Sun Apr 26 21:38:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25082C43334 for ; Wed, 22 Jun 2022 10:16:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351983AbiFVKQc (ORCPT ); Wed, 22 Jun 2022 06:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350435AbiFVKQH (ORCPT ); Wed, 22 Jun 2022 06:16:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CB0F3B28D; Wed, 22 Jun 2022 03:15:58 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LSfPM3htjzkWVS; Wed, 22 Jun 2022 18:14:15 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 From: Chen Zhongjin To: , , , , , CC: , , , , , Subject: [PATCH v2 2/5] objtool: Make ORC init and lookup code arch-generic Date: Wed, 22 Jun 2022 18:13:41 +0800 Message-ID: <20220622101344.38002-3-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220622101344.38002-1-chenzhongjin@huawei.com> References: <20220622101344.38002-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Madhavan T. Venkataraman" All of the ORC code in the kernel is currently under arch/x86. The following parts of that code can be shared by other architectures that wish to use ORC. (1) ORC lookup initialization for vmlinux (2) ORC lookup initialization for modules (3) ORC lookup functions Move arch/x86/include/asm/orc_lookup.h to include/asm-generic/orc_lookup.h. Move the ORC lookup code into kernel/orc_lookup.c. Rename the following init functions: unwind_module_init =3D=3D> orc_lookup_module_init unwind_init =3D=3D> orc_lookup_init since that is exactly what they do. orc_find() is the function that locates the ORC entry for a given PC. Currently, it contains an architecture-specific part to locate ftrace entries. Introduce a new arch-specific function called arch_orc_find() and move the ftrace-related lookup there. If orc_find() is unable to locate the ORC entry for a given PC in vmlinux or in the modules, it can call arch_orc_find() to find architecture-specific entries. Signed-off-by: Madhavan T. Venkataraman Signed-off-by: Chen Zhongjin --- arch/x86/include/asm/unwind.h | 5 - arch/x86/kernel/module.c | 7 +- arch/x86/kernel/unwind_orc.c | 256 +---------------- arch/x86/kernel/vmlinux.lds.S | 2 +- .../asm =3D> include/asm-generic}/orc_lookup.h | 42 +++ kernel/Makefile | 2 + kernel/orc_lookup.c | 261 ++++++++++++++++++ 7 files changed, 316 insertions(+), 259 deletions(-) rename {arch/x86/include/asm =3D> include/asm-generic}/orc_lookup.h (51%) create mode 100644 kernel/orc_lookup.c diff --git a/arch/x86/include/asm/unwind.h b/arch/x86/include/asm/unwind.h index 7cede4dc21f0..71af8246c69e 100644 --- a/arch/x86/include/asm/unwind.h +++ b/arch/x86/include/asm/unwind.h @@ -94,13 +94,8 @@ static inline struct pt_regs *unwind_get_entry_regs(stru= ct unwind_state *state, =20 #ifdef CONFIG_UNWINDER_ORC void unwind_init(void); -void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_si= ze, - void *orc, size_t orc_size); #else static inline void unwind_init(void) {} -static inline -void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_si= ze, - void *orc, size_t orc_size) {} #endif =20 static inline diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index b98ffcf4d250..4ebc9eddcb6b 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include =20 #if 0 #define DEBUGP(fmt, ...) \ @@ -308,8 +308,9 @@ int module_finalize(const Elf_Ehdr *hdr, jump_label_apply_nops(me); =20 if (orc && orc_ip) - unwind_module_init(me, (void *)orc_ip->sh_addr, orc_ip->sh_size, - (void *)orc->sh_addr, orc->sh_size); + orc_lookup_module_init(me, + (void *)orc_ip->sh_addr, orc_ip->sh_size, + (void *)orc->sh_addr, orc->sh_size); =20 return 0; } diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 38185aedf7d1..b7425855feda 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -6,80 +6,9 @@ #include #include #include -#include - -#define orc_warn(fmt, ...) \ - printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__) - -#define orc_warn_current(args...) \ -({ \ - if (state->task =3D=3D current && !state->error) \ - orc_warn(args); \ -}) - -extern int __start_orc_unwind_ip[]; -extern int __stop_orc_unwind_ip[]; -extern struct orc_entry __start_orc_unwind[]; -extern struct orc_entry __stop_orc_unwind[]; - -static bool orc_init __ro_after_init; -static unsigned int lookup_num_blocks __ro_after_init; - -static inline unsigned long orc_ip(const int *ip) -{ - return (unsigned long)ip + *ip; -} - -static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_tab= le, - unsigned int num_entries, unsigned long ip) -{ - int *first =3D ip_table; - int *last =3D ip_table + num_entries - 1; - int *mid =3D first, *found =3D first; - - if (!num_entries) - return NULL; - - /* - * Do a binary range search to find the rightmost duplicate of a given - * starting address. Some entries are section terminators which are - * "weak" entries for ensuring there are no gaps. They should be - * ignored when they conflict with a real entry. - */ - while (first <=3D last) { - mid =3D first + ((last - first) / 2); - - if (orc_ip(mid) <=3D ip) { - found =3D mid; - first =3D mid + 1; - } else - last =3D mid - 1; - } - - return u_table + (found - ip_table); -} - -#ifdef CONFIG_MODULES -static struct orc_entry *orc_module_find(unsigned long ip) -{ - struct module *mod; - - mod =3D __module_address(ip); - if (!mod || !mod->arch.orc_unwind || !mod->arch.orc_unwind_ip) - return NULL; - return __orc_find(mod->arch.orc_unwind_ip, mod->arch.orc_unwind, - mod->arch.num_orcs, ip); -} -#else -static struct orc_entry *orc_module_find(unsigned long ip) -{ - return NULL; -} -#endif +#include =20 #ifdef CONFIG_DYNAMIC_FTRACE -static struct orc_entry *orc_find(unsigned long ip); - /* * Ftrace dynamic trampolines do not have orc entries of their own. * But they are copies of the ftrace entries that are static and @@ -117,19 +46,10 @@ static struct orc_entry *orc_ftrace_find(unsigned long= ip) } #endif =20 -/* - * If we crash with IP=3D=3D0, the last successfully executed instruction - * was probably an indirect function call with a NULL function pointer, - * and we don't have unwind information for NULL. - * This hardcoded ORC entry for IP=3D=3D0 allows us to unwind from a NULL = function - * pointer into its parent and then continue normally from there. - */ -static struct orc_entry null_orc_entry =3D { - .sp_offset =3D sizeof(long), - .sp_reg =3D ORC_REG_SP, - .bp_reg =3D ORC_REG_UNDEFINED, - .type =3D UNWIND_HINT_TYPE_CALL -}; +struct orc_entry *arch_orc_find(unsigned long ip) +{ + return orc_ftrace_find(ip); +} =20 /* Fake frame pointer entry -- used as a fallback for generated code */ static struct orc_entry orc_fp_entry =3D { @@ -141,173 +61,9 @@ static struct orc_entry orc_fp_entry =3D { .end =3D 0, }; =20 -static struct orc_entry *orc_find(unsigned long ip) -{ - static struct orc_entry *orc; - - if (ip =3D=3D 0) - return &null_orc_entry; - - /* For non-init vmlinux addresses, use the fast lookup table: */ - if (ip >=3D LOOKUP_START_IP && ip < LOOKUP_STOP_IP) { - unsigned int idx, start, stop; - - idx =3D (ip - LOOKUP_START_IP) / LOOKUP_BLOCK_SIZE; - - if (unlikely((idx >=3D lookup_num_blocks-1))) { - orc_warn("WARNING: bad lookup idx: idx=3D%u num=3D%u ip=3D%pB\n", - idx, lookup_num_blocks, (void *)ip); - return NULL; - } - - start =3D orc_lookup[idx]; - stop =3D orc_lookup[idx + 1] + 1; - - if (unlikely((__start_orc_unwind + start >=3D __stop_orc_unwind) || - (__start_orc_unwind + stop > __stop_orc_unwind))) { - orc_warn("WARNING: bad lookup value: idx=3D%u num=3D%u start=3D%u stop= =3D%u ip=3D%pB\n", - idx, lookup_num_blocks, start, stop, (void *)ip); - return NULL; - } - - return __orc_find(__start_orc_unwind_ip + start, - __start_orc_unwind + start, stop - start, ip); - } - - /* vmlinux .init slow lookup: */ - if (is_kernel_inittext(ip)) - return __orc_find(__start_orc_unwind_ip, __start_orc_unwind, - __stop_orc_unwind_ip - __start_orc_unwind_ip, ip); - - /* Module lookup: */ - orc =3D orc_module_find(ip); - if (orc) - return orc; - - return orc_ftrace_find(ip); -} - -#ifdef CONFIG_MODULES - -static DEFINE_MUTEX(sort_mutex); -static int *cur_orc_ip_table =3D __start_orc_unwind_ip; -static struct orc_entry *cur_orc_table =3D __start_orc_unwind; - -static void orc_sort_swap(void *_a, void *_b, int size) -{ - struct orc_entry *orc_a, *orc_b; - struct orc_entry orc_tmp; - int *a =3D _a, *b =3D _b, tmp; - int delta =3D _b - _a; - - /* Swap the .orc_unwind_ip entries: */ - tmp =3D *a; - *a =3D *b + delta; - *b =3D tmp - delta; - - /* Swap the corresponding .orc_unwind entries: */ - orc_a =3D cur_orc_table + (a - cur_orc_ip_table); - orc_b =3D cur_orc_table + (b - cur_orc_ip_table); - orc_tmp =3D *orc_a; - *orc_a =3D *orc_b; - *orc_b =3D orc_tmp; -} - -static int orc_sort_cmp(const void *_a, const void *_b) -{ - struct orc_entry *orc_a; - const int *a =3D _a, *b =3D _b; - unsigned long a_val =3D orc_ip(a); - unsigned long b_val =3D orc_ip(b); - - if (a_val > b_val) - return 1; - if (a_val < b_val) - return -1; - - /* - * The "weak" section terminator entries need to always be on the left - * to ensure the lookup code skips them in favor of real entries. - * These terminator entries exist to handle any gaps created by - * whitelisted .o files which didn't get objtool generation. - */ - orc_a =3D cur_orc_table + (a - cur_orc_ip_table); - return orc_a->sp_reg =3D=3D ORC_REG_UNDEFINED && !orc_a->end ? -1 : 1; -} - -void unwind_module_init(struct module *mod, void *_orc_ip, size_t orc_ip_s= ize, - void *_orc, size_t orc_size) -{ - int *orc_ip =3D _orc_ip; - struct orc_entry *orc =3D _orc; - unsigned int num_entries =3D orc_ip_size / sizeof(int); - - WARN_ON_ONCE(orc_ip_size % sizeof(int) !=3D 0 || - orc_size % sizeof(*orc) !=3D 0 || - num_entries !=3D orc_size / sizeof(*orc)); - - /* - * The 'cur_orc_*' globals allow the orc_sort_swap() callback to - * associate an .orc_unwind_ip table entry with its corresponding - * .orc_unwind entry so they can both be swapped. - */ - mutex_lock(&sort_mutex); - cur_orc_ip_table =3D orc_ip; - cur_orc_table =3D orc; - sort(orc_ip, num_entries, sizeof(int), orc_sort_cmp, orc_sort_swap); - mutex_unlock(&sort_mutex); - - mod->arch.orc_unwind_ip =3D orc_ip; - mod->arch.orc_unwind =3D orc; - mod->arch.num_orcs =3D num_entries; -} -#endif - void __init unwind_init(void) { - size_t orc_ip_size =3D (void *)__stop_orc_unwind_ip - (void *)__start_orc= _unwind_ip; - size_t orc_size =3D (void *)__stop_orc_unwind - (void *)__start_orc_unwin= d; - size_t num_entries =3D orc_ip_size / sizeof(int); - struct orc_entry *orc; - int i; - - if (!num_entries || orc_ip_size % sizeof(int) !=3D 0 || - orc_size % sizeof(struct orc_entry) !=3D 0 || - num_entries !=3D orc_size / sizeof(struct orc_entry)) { - orc_warn("WARNING: Bad or missing .orc_unwind table. Disabling unwinder= .\n"); - return; - } - - /* - * Note, the orc_unwind and orc_unwind_ip tables were already - * sorted at build time via the 'sorttable' tool. - * It's ready for binary search straight away, no need to sort it. - */ - - /* Initialize the fast lookup table: */ - lookup_num_blocks =3D orc_lookup_end - orc_lookup; - for (i =3D 0; i < lookup_num_blocks-1; i++) { - orc =3D __orc_find(__start_orc_unwind_ip, __start_orc_unwind, - num_entries, - LOOKUP_START_IP + (LOOKUP_BLOCK_SIZE * i)); - if (!orc) { - orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n"); - return; - } - - orc_lookup[i] =3D orc - __start_orc_unwind; - } - - /* Initialize the ending block: */ - orc =3D __orc_find(__start_orc_unwind_ip, __start_orc_unwind, num_entries, - LOOKUP_STOP_IP); - if (!orc) { - orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n"); - return; - } - orc_lookup[lookup_num_blocks-1] =3D orc - __start_orc_unwind; - - orc_init =3D true; + orc_lookup_init(); } =20 unsigned long unwind_get_return_address(struct unwind_state *state) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 7fda7f27e762..1b0c6b4eafae 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include =20 diff --git a/arch/x86/include/asm/orc_lookup.h b/include/asm-generic/orc_lo= okup.h similarity index 51% rename from arch/x86/include/asm/orc_lookup.h rename to include/asm-generic/orc_lookup.h index 241631282e43..4a476269d151 100644 --- a/arch/x86/include/asm/orc_lookup.h +++ b/include/asm-generic/orc_lookup.h @@ -23,6 +23,8 @@ =20 #ifndef LINKER_SCRIPT =20 +#include + extern unsigned int orc_lookup[]; extern unsigned int orc_lookup_end[]; =20 @@ -31,4 +33,44 @@ extern unsigned int orc_lookup_end[]; =20 #endif /* LINKER_SCRIPT */ =20 +#ifndef __ASSEMBLY__ + +#include + +#ifdef CONFIG_UNWINDER_ORC +void orc_lookup_init(void); +void orc_lookup_module_init(struct module *mod, + void *orc_ip, size_t orc_ip_size, + void *orc, size_t orc_size); +#else +static inline void orc_lookup_init(void) {} +static inline +void orc_lookup_module_init(struct module *mod, + void *orc_ip, size_t orc_ip_size, + void *orc, size_t orc_size) +{ +} +#endif + +struct orc_entry *arch_orc_find(unsigned long ip); + +#define orc_warn(fmt, ...) \ + printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__) + +#define orc_warn_current(args...) \ +({ \ + if (state->task =3D=3D current && !state->error) \ + orc_warn(args); \ +}) + +struct orc_entry *orc_find(unsigned long ip); + +extern bool orc_init; +extern int __start_orc_unwind_ip[]; +extern int __stop_orc_unwind_ip[]; +extern struct orc_entry __start_orc_unwind[]; +extern struct orc_entry __stop_orc_unwind[]; + +#endif /* __ASSEMBLY__ */ + #endif /* _ORC_LOOKUP_H */ diff --git a/kernel/Makefile b/kernel/Makefile index 847a82bfe0e3..e5330aacb5b4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -134,6 +134,8 @@ obj-$(CONFIG_WATCH_QUEUE) +=3D watch_queue.o obj-$(CONFIG_RESOURCE_KUNIT_TEST) +=3D resource_kunit.o obj-$(CONFIG_SYSCTL_KUNIT_TEST) +=3D sysctl-test.o =20 +obj-$(CONFIG_UNWINDER_ORC) +=3D orc_lookup.o + CFLAGS_stackleak.o +=3D $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) +=3D stackleak.o KASAN_SANITIZE_stackleak.o :=3D n diff --git a/kernel/orc_lookup.c b/kernel/orc_lookup.c new file mode 100644 index 000000000000..2e04a5e2be45 --- /dev/null +++ b/kernel/orc_lookup.c @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +bool orc_init __ro_after_init; +static unsigned int lookup_num_blocks __ro_after_init; + +static inline unsigned long orc_ip(const int *ip) +{ + return (unsigned long)ip + *ip; +} + +static struct orc_entry *__orc_find(int *ip_table, struct orc_entry *u_tab= le, + unsigned int num_entries, unsigned long ip) +{ + int *first =3D ip_table; + int *last =3D ip_table + num_entries - 1; + int *mid =3D first, *found =3D first; + + if (!num_entries) + return NULL; + + /* + * Do a binary range search to find the rightmost duplicate of a given + * starting address. Some entries are section terminators which are + * "weak" entries for ensuring there are no gaps. They should be + * ignored when they conflict with a real entry. + */ + while (first <=3D last) { + mid =3D first + ((last - first) / 2); + + if (orc_ip(mid) <=3D ip) { + found =3D mid; + first =3D mid + 1; + } else + last =3D mid - 1; + } + + return u_table + (found - ip_table); +} + +#ifdef CONFIG_MODULES +static struct orc_entry *orc_module_find(unsigned long ip) +{ + struct module *mod; + + mod =3D __module_address(ip); + if (!mod || !mod->arch.orc_unwind || !mod->arch.orc_unwind_ip) + return NULL; + return __orc_find(mod->arch.orc_unwind_ip, mod->arch.orc_unwind, + mod->arch.num_orcs, ip); +} +#else +static struct orc_entry *orc_module_find(unsigned long ip) +{ + return NULL; +} +#endif + +/* + * If we crash with IP=3D=3D0, the last successfully executed instruction + * was probably an indirect function call with a NULL function pointer, + * and we don't have unwind information for NULL. + * This hardcoded ORC entry for IP=3D=3D0 allows us to unwind from a NULL = function + * pointer into its parent and then continue normally from there. + */ +static struct orc_entry null_orc_entry =3D { + .sp_offset =3D sizeof(long), + .sp_reg =3D ORC_REG_SP, + .bp_reg =3D ORC_REG_UNDEFINED, + .type =3D UNWIND_HINT_TYPE_CALL +}; + +struct orc_entry *orc_find(unsigned long ip) +{ + static struct orc_entry *orc; + + if (ip =3D=3D 0) + return &null_orc_entry; + + /* For non-init vmlinux addresses, use the fast lookup table: */ + if (ip >=3D LOOKUP_START_IP && ip < LOOKUP_STOP_IP) { + unsigned int idx, start, stop; + + if (!orc_init) { + /* + * Take the slow path if the fast lookup tables have + * not yet been initialized. + */ + return __orc_find(__start_orc_unwind_ip, + __start_orc_unwind, + __stop_orc_unwind_ip - + __start_orc_unwind_ip, ip); + } + + idx =3D (ip - LOOKUP_START_IP) / LOOKUP_BLOCK_SIZE; + + if (unlikely((idx >=3D lookup_num_blocks-1))) { + orc_warn("WARNING: bad lookup idx: idx=3D%u num=3D%u ip=3D%pB\n", + idx, lookup_num_blocks, (void *)ip); + return NULL; + } + + start =3D orc_lookup[idx]; + stop =3D orc_lookup[idx + 1] + 1; + + if (unlikely((__start_orc_unwind + start >=3D __stop_orc_unwind) || + (__start_orc_unwind + stop > __stop_orc_unwind))) { + orc_warn("WARNING: bad lookup value: idx=3D%u num=3D%u start=3D%u stop= =3D%u ip=3D%pB\n", + idx, lookup_num_blocks, start, stop, (void *)ip); + return NULL; + } + + return __orc_find(__start_orc_unwind_ip + start, + __start_orc_unwind + start, stop - start, ip); + } + + /* vmlinux .init slow lookup: */ + if (is_kernel_inittext(ip)) + return __orc_find(__start_orc_unwind_ip, __start_orc_unwind, + __stop_orc_unwind_ip - __start_orc_unwind_ip, ip); + + /* Module lookup: */ + orc =3D orc_module_find(ip); + if (orc) + return orc; + + return arch_orc_find(ip); +} + +#ifdef CONFIG_MODULES + +static DEFINE_MUTEX(sort_mutex); +static int *cur_orc_ip_table =3D __start_orc_unwind_ip; +static struct orc_entry *cur_orc_table =3D __start_orc_unwind; + +static void orc_sort_swap(void *_a, void *_b, int size) +{ + struct orc_entry *orc_a, *orc_b; + struct orc_entry orc_tmp; + int *a =3D _a, *b =3D _b, tmp; + int delta =3D _b - _a; + + /* Swap the .orc_unwind_ip entries: */ + tmp =3D *a; + *a =3D *b + delta; + *b =3D tmp - delta; + + /* Swap the corresponding .orc_unwind entries: */ + orc_a =3D cur_orc_table + (a - cur_orc_ip_table); + orc_b =3D cur_orc_table + (b - cur_orc_ip_table); + orc_tmp =3D *orc_a; + *orc_a =3D *orc_b; + *orc_b =3D orc_tmp; +} + +static int orc_sort_cmp(const void *_a, const void *_b) +{ + struct orc_entry *orc_a; + const int *a =3D _a, *b =3D _b; + unsigned long a_val =3D orc_ip(a); + unsigned long b_val =3D orc_ip(b); + + if (a_val > b_val) + return 1; + if (a_val < b_val) + return -1; + + /* + * The "weak" section terminator entries need to always be on the left + * to ensure the lookup code skips them in favor of real entries. + * These terminator entries exist to handle any gaps created by + * whitelisted .o files which didn't get objtool generation. + */ + orc_a =3D cur_orc_table + (a - cur_orc_ip_table); + return orc_a->sp_reg =3D=3D ORC_REG_UNDEFINED && !orc_a->end ? -1 : 1; +} + +void orc_lookup_module_init(struct module *mod, + void *_orc_ip, size_t orc_ip_size, + void *_orc, size_t orc_size) +{ + int *orc_ip =3D _orc_ip; + struct orc_entry *orc =3D _orc; + unsigned int num_entries =3D orc_ip_size / sizeof(int); + + WARN_ON_ONCE(orc_ip_size % sizeof(int) !=3D 0 || + orc_size % sizeof(*orc) !=3D 0 || + num_entries !=3D orc_size / sizeof(*orc)); + + /* + * The 'cur_orc_*' globals allow the orc_sort_swap() callback to + * associate an .orc_unwind_ip table entry with its corresponding + * .orc_unwind entry so they can both be swapped. + */ + mutex_lock(&sort_mutex); + cur_orc_ip_table =3D orc_ip; + cur_orc_table =3D orc; + sort(orc_ip, num_entries, sizeof(int), orc_sort_cmp, orc_sort_swap); + mutex_unlock(&sort_mutex); + + mod->arch.orc_unwind_ip =3D orc_ip; + mod->arch.orc_unwind =3D orc; + mod->arch.num_orcs =3D num_entries; +} +#endif + +void __init orc_lookup_init(void) +{ + size_t orc_ip_size =3D (void *)__stop_orc_unwind_ip - (void *)__start_orc= _unwind_ip; + size_t orc_size =3D (void *)__stop_orc_unwind - (void *)__start_orc_unwin= d; + size_t num_entries =3D orc_ip_size / sizeof(int); + struct orc_entry *orc; + int i; + + if (!num_entries || orc_ip_size % sizeof(int) !=3D 0 || + orc_size % sizeof(struct orc_entry) !=3D 0 || + num_entries !=3D orc_size / sizeof(struct orc_entry)) { + orc_warn("WARNING: Bad or missing .orc_unwind table. Disabling unwinder= .\n"); + return; + } + + /* + * Note, the orc_unwind and orc_unwind_ip tables were already + * sorted at build time via the 'sorttable' tool. + * It's ready for binary search straight away, no need to sort it. + */ + + /* Initialize the fast lookup table: */ + lookup_num_blocks =3D orc_lookup_end - orc_lookup; + for (i =3D 0; i < lookup_num_blocks-1; i++) { + orc =3D __orc_find(__start_orc_unwind_ip, __start_orc_unwind, + num_entries, + LOOKUP_START_IP + (LOOKUP_BLOCK_SIZE * i)); + if (!orc) { + orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n"); + return; + } + + orc_lookup[i] =3D orc - __start_orc_unwind; + } + + /* Initialize the ending block: */ + orc =3D __orc_find(__start_orc_unwind_ip, __start_orc_unwind, num_entries, + LOOKUP_STOP_IP); + if (!orc) { + orc_warn("WARNING: Corrupt .orc_unwind table. Disabling unwinder.\n"); + return; + } + orc_lookup[lookup_num_blocks-1] =3D orc - __start_orc_unwind; + + orc_init =3D true; +} + +__weak struct orc_entry *arch_orc_find(unsigned long ip) +{ + return NULL; +} --=20 2.17.1 From nobody Sun Apr 26 21:38:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB84CC433EF for ; Wed, 22 Jun 2022 10:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349773AbiFVKQW (ORCPT ); Wed, 22 Jun 2022 06:16:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350246AbiFVKQG (ORCPT ); Wed, 22 Jun 2022 06:16:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A31C3B290; Wed, 22 Jun 2022 03:15:58 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LSfNs2DBVzhXZY; Wed, 22 Jun 2022 18:13:49 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 From: Chen Zhongjin To: , , , , , CC: , , , , , Subject: [PATCH v2 3/5] objtool: Add generic symbol for relocation type Date: Wed, 22 Jun 2022 18:13:42 +0800 Message-ID: <20220622101344.38002-4-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220622101344.38002-1-chenzhongjin@huawei.com> References: <20220622101344.38002-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" objtool uses R_X86_64_X as relocation type. Add abstraction for them so that other architectures can use its own reloc enums. Signed-off-by: Chen Zhongjin --- tools/objtool/arch/x86/include/arch/elf.h | 5 ++++- tools/objtool/arch/x86/special.c | 5 +++-- tools/objtool/check.c | 12 ++++++------ tools/objtool/orc_gen.c | 3 ++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch= /x86/include/arch/elf.h index 69cc4264b28a..7b737fcfcb9c 100644 --- a/tools/objtool/arch/x86/include/arch/elf.h +++ b/tools/objtool/arch/x86/include/arch/elf.h @@ -1,6 +1,9 @@ #ifndef _OBJTOOL_ARCH_ELF #define _OBJTOOL_ARCH_ELF =20 -#define R_NONE R_X86_64_NONE +#define R_NONE R_X86_64_NONE +#define R_ABS64 R_X86_64_64 +#define R_REL32 R_X86_64_PC32 +#define R_PLT32 R_X86_64_PLT32 =20 #endif /* _OBJTOOL_ARCH_ELF */ diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 7c97b7391279..fbe0745a9ed7 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include =20 +#include #include #include =20 @@ -108,7 +109,7 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, table_offset =3D text_reloc->addend; table_sec =3D text_reloc->sym->sec; =20 - if (text_reloc->type =3D=3D R_X86_64_PC32) + if (text_reloc->type =3D=3D R_REL32) table_offset +=3D 4; =20 /* @@ -138,7 +139,7 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, * indicates a rare GCC quirk/bug which can leave dead * code behind. */ - if (text_reloc->type =3D=3D R_X86_64_PC32) + if (text_reloc->type =3D=3D R_REL32) file->ignore_unreachables =3D true; =20 return rodata_reloc; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 190b2f6e360a..11ab13fd99fd 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -650,7 +650,7 @@ static int create_static_call_sections(struct objtool_f= ile *file) /* populate reloc for 'addr' */ if (elf_add_reloc_to_insn(file->elf, sec, idx * sizeof(struct static_call_site), - R_X86_64_PC32, + R_REL32, insn->sec, insn->offset)) return -1; =20 @@ -691,7 +691,7 @@ static int create_static_call_sections(struct objtool_f= ile *file) /* populate reloc for 'key' */ if (elf_add_reloc(file->elf, sec, idx * sizeof(struct static_call_site) + 4, - R_X86_64_PC32, key_sym, + R_REL32, key_sym, is_sibling_call(insn) * STATIC_CALL_SITE_TAIL)) return -1; =20 @@ -735,7 +735,7 @@ static int create_retpoline_sites_sections(struct objto= ol_file *file) =20 if (elf_add_reloc_to_insn(file->elf, sec, idx * sizeof(int), - R_X86_64_PC32, + R_REL32, insn->sec, insn->offset)) { WARN("elf_add_reloc_to_insn: .retpoline_sites"); return -1; @@ -787,7 +787,7 @@ static int create_ibt_endbr_seal_sections(struct objtoo= l_file *file) =20 if (elf_add_reloc_to_insn(file->elf, sec, idx * sizeof(int), - R_X86_64_PC32, + R_REL32, insn->sec, insn->offset)) { WARN("elf_add_reloc_to_insn: .ibt_endbr_seal"); return -1; @@ -832,7 +832,7 @@ static int create_mcount_loc_sections(struct objtool_fi= le *file) =20 if (elf_add_reloc_to_insn(file->elf, sec, idx * sizeof(unsigned long), - R_X86_64_64, + R_ABS64, insn->sec, insn->offset)) return -1; =20 @@ -3711,7 +3711,7 @@ static int validate_ibt_insn(struct objtool_file *fil= e, struct instruction *insn continue; =20 off =3D reloc->sym->offset; - if (reloc->type =3D=3D R_X86_64_PC32 || reloc->type =3D=3D R_X86_64_PLT3= 2) + if (reloc->type =3D=3D R_REL32 || reloc->type =3D=3D R_PLT32) off +=3D arch_dest_reloc_offset(reloc->addend); else off +=3D reloc->addend; diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index a7d060ba14d0..ab4dbfa52b1e 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -8,6 +8,7 @@ =20 #include =20 +#include #include #include #include @@ -27,7 +28,7 @@ static int write_orc_entry(struct elf *elf, struct sectio= n *orc_sec, orc->bp_offset =3D bswap_if_needed(orc->bp_offset); =20 /* populate reloc for ip */ - if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_X86_64_PC32, + if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_REL32, insn_sec, insn_off)) return -1; =20 --=20 2.17.1 From nobody Sun Apr 26 21:38:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE456CCA47D for ; Wed, 22 Jun 2022 10:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350199AbiFVKQP (ORCPT ); Wed, 22 Jun 2022 06:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347800AbiFVKQG (ORCPT ); Wed, 22 Jun 2022 06:16:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A27D3B28F; Wed, 22 Jun 2022 03:15:58 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LSfNs3YmMzhXcb; Wed, 22 Jun 2022 18:13:49 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 From: Chen Zhongjin To: , , , , , CC: , , , , , Subject: [PATCH v2 4/5] objtool: Specify host-arch for making LIBSUBCMD Date: Wed, 22 Jun 2022 18:13:43 +0800 Message-ID: <20220622101344.38002-5-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220622101344.38002-1-chenzhongjin@huawei.com> References: <20220622101344.38002-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When singly cross-compiling objtool, LIBSUBCMD MAKE uses target-arch and failed to LD with other object files. Explicitly specify host-arch for LIBSUBCMD so it can be correctly cross-compiled. Signed-off-by: Chen Zhongjin --- tools/objtool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index e66d717c245d..2b97720ab608 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -58,7 +58,7 @@ $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN) =20 =20 $(LIBSUBCMD): fixdep FORCE - $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=3D$(LIBSUBCMD_OUTPUT) + $(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=3D$(LIBSUBCMD_OUTPUT) AR=3D$(AR) C= C=3D$(CC) LD=3D$(LD) =20 clean: $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) --=20 2.17.1 From nobody Sun Apr 26 21:38:01 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8428CC433EF for ; Wed, 22 Jun 2022 10:16:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350820AbiFVKQu (ORCPT ); Wed, 22 Jun 2022 06:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244791AbiFVKQL (ORCPT ); Wed, 22 Jun 2022 06:16:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C142C3AA4C; Wed, 22 Jun 2022 03:16:04 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LSfMV4mZMzShB9; Wed, 22 Jun 2022 18:12:38 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:57 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 22 Jun 2022 18:15:56 +0800 From: Chen Zhongjin To: , , , , , CC: , , , , , Subject: [PATCH v2 5/5] objtool: use arch_jump_destination in read_intra_function_calls Date: Wed, 22 Jun 2022 18:13:44 +0800 Message-ID: <20220622101344.38002-6-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220622101344.38002-1-chenzhongjin@huawei.com> References: <20220622101344.38002-1-chenzhongjin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now we use arch_jump_destination() instead of offset + len + immediate for jump destination. But in read_intra_function_calls it didn't get changed. Fix it. Signed-off-by: Chen Zhongjin --- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 11ab13fd99fd..35d0a1bc4279 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2127,7 +2127,7 @@ static int read_intra_function_calls(struct objtool_f= ile *file) */ insn->type =3D INSN_JUMP_UNCONDITIONAL; =20 - dest_off =3D insn->offset + insn->len + insn->immediate; + dest_off =3D arch_jump_destination(insn); insn->jump_dest =3D find_insn(file, insn->sec, dest_off); if (!insn->jump_dest) { WARN_FUNC("can't find call dest at %s+0x%lx", --=20 2.17.1