From nobody Sun Feb 8 18:56:34 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 2480BC7EE23 for ; Tue, 30 May 2023 17:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233440AbjE3RWo (ORCPT ); Tue, 30 May 2023 13:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233230AbjE3RVn (ORCPT ); Tue, 30 May 2023 13:21:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F9DEF7 for ; Tue, 30 May 2023 10:21:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BCB3063138 for ; Tue, 30 May 2023 17:21:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6289DC433A0; Tue, 30 May 2023 17:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467297; bh=pNfbAmu0/tic6xcfteWUfNk4M0kZWxM3aNAl/VUcN9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kChLyN3RMKEm349Q59K+r3Bwcshk/vF0duCdtnLKqYmXwXbWFURcScsNVjas8VJiu Z/PE6hzQg1eSMRDBWsLwduTV3tGdymqtG58qVdMnPaTtA0r0DLwqGI6Ap/pqnypTag UwR5HqjWp5nJYekzctbf3yg4wnSfLYxCT0d9U270qWFT2f81h6O3x1mebY7ksdy3Sx EoIqSFRe69p/Z0SkC9x0lE0D+NaDyOXT13Eog4mUqNzb6bexZpQ6tVF5Rt0P/4mD+/ Ipgv9gkzgDRKyN7QP3oSZetMSqBYSeq4dUV1Iwbp8OdMUxfHaV0ZjggypAIwiWiH17 0Vkporxo7fbRw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 16/22] objtool: Get rid of reloc->addend Date: Tue, 30 May 2023 10:21:08 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Get the addend from the embedded GElf_Rel[a] struct. With allyesconfig + CONFIG_DEBUG_INFO: - Before: peak heap memory consumption: 42.10G - After: peak heap memory consumption: 40.37G Signed-off-by: Josh Poimboeuf --- tools/objtool/arch/x86/decode.c | 4 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 69 +++++++++++++++++------------ tools/objtool/elf.c | 10 ++--- tools/objtool/include/objtool/elf.h | 6 ++- tools/objtool/special.c | 4 +- 6 files changed, 53 insertions(+), 42 deletions(-) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index ffb12e83b238..2e1caabecb18 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -623,11 +623,11 @@ int arch_decode_instruction(struct objtool_file *file= , const struct section *sec if (!immr || strcmp(immr->sym->name, "pv_ops")) break; =20 - idx =3D (immr->addend + 8) / sizeof(void *); + idx =3D (reloc_addend(immr) + 8) / sizeof(void *); =20 func =3D disp->sym; if (disp->sym->type =3D=3D STT_SECTION) - func =3D find_symbol_by_offset(disp->sym->sec, disp->addend); + func =3D find_symbol_by_offset(disp->sym->sec, reloc_addend(disp)); if (!func) { WARN("no func for pv_ops[]"); return -1; diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 1a54a249cb50..65f48f35b97e 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -105,7 +105,7 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, !text_reloc->sym->sec->rodata) return NULL; =20 - table_offset =3D text_reloc->addend; + table_offset =3D reloc_addend(text_reloc); table_sec =3D text_reloc->sym->sec; =20 if (reloc_type(text_reloc) =3D=3D R_X86_64_PC32) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 1d794d15bc53..12a9e6fb3fe7 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -508,7 +508,8 @@ static int add_pv_ops(struct objtool_file *file, const = char *symname) =20 func =3D reloc->sym; if (func->type =3D=3D STT_SECTION) - func =3D find_symbol_by_offset(reloc->sym->sec, reloc->addend); + func =3D find_symbol_by_offset(reloc->sym->sec, + reloc_addend(reloc)); =20 idx =3D (reloc_offset(reloc) - sym->offset) / sizeof(unsigned long); =20 @@ -582,6 +583,7 @@ static int add_dead_ends(struct objtool_file *file) struct section *rsec; struct reloc *reloc; struct instruction *insn; + s64 addend; =20 /* * Check for manually annotated dead ends. @@ -591,23 +593,27 @@ static int add_dead_ends(struct objtool_file *file) goto reachable; =20 for_each_reloc(rsec, reloc) { + if (reloc->sym->type !=3D STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + + addend =3D reloc_addend(reloc); + + insn =3D find_insn(file, reloc->sym->sec, addend); if (insn) insn =3D prev_insn_same_sec(file, insn); - else if (reloc->addend =3D=3D reloc->sym->sec->sh.sh_size) { + else if (addend =3D=3D reloc->sym->sec->sh.sh_size) { insn =3D find_last_insn(file, reloc->sym->sec); if (!insn) { WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, reloc->addend); + reloc->sym->sec->name, addend); return -1; } } else { WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, reloc->addend); + reloc->sym->sec->name, addend); return -1; } =20 @@ -626,23 +632,27 @@ static int add_dead_ends(struct objtool_file *file) return 0; =20 for_each_reloc(rsec, reloc) { + if (reloc->sym->type !=3D STT_SECTION) { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + + addend =3D reloc_addend(reloc); + + insn =3D find_insn(file, reloc->sym->sec, addend); if (insn) insn =3D prev_insn_same_sec(file, insn); - else if (reloc->addend =3D=3D reloc->sym->sec->sh.sh_size) { + else if (addend =3D=3D reloc->sym->sec->sh.sh_size) { insn =3D find_last_insn(file, reloc->sym->sec); if (!insn) { WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, reloc->addend); + reloc->sym->sec->name, addend); return -1; } } else { WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, reloc->addend); + reloc->sym->sec->name, addend); return -1; } =20 @@ -1025,7 +1035,7 @@ static void add_ignores(struct objtool_file *file) break; =20 case STT_SECTION: - func =3D find_func_by_offset(reloc->sym->sec, reloc->addend); + func =3D find_func_by_offset(reloc->sym->sec, reloc_addend(reloc)); if (!func) continue; break; @@ -1265,7 +1275,7 @@ static int add_ignore_alternatives(struct objtool_fil= e *file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.ignore_alts entry"); return -1; @@ -1541,7 +1551,7 @@ static int add_jump_destinations(struct objtool_file = *file) dest_off =3D arch_jump_destination(insn); } else if (reloc->sym->type =3D=3D STT_SECTION) { dest_sec =3D reloc->sym->sec; - dest_off =3D arch_dest_reloc_offset(reloc->addend); + dest_off =3D arch_dest_reloc_offset(reloc_addend(reloc)); } else if (reloc->sym->retpoline_thunk) { add_retpoline_call(file, insn); continue; @@ -1558,7 +1568,7 @@ static int add_jump_destinations(struct objtool_file = *file) } else if (reloc->sym->sec->idx) { dest_sec =3D reloc->sym->sec; dest_off =3D reloc->sym->sym.st_value + - arch_dest_reloc_offset(reloc->addend); + arch_dest_reloc_offset(reloc_addend(reloc)); } else { /* non-func asm code jumping to another file */ continue; @@ -1675,7 +1685,7 @@ static int add_call_destinations(struct objtool_file = *file) } =20 } else if (reloc->sym->type =3D=3D STT_SECTION) { - dest_off =3D arch_dest_reloc_offset(reloc->addend); + dest_off =3D arch_dest_reloc_offset(reloc_addend(reloc)); dest =3D find_call_destination(reloc->sym->sec, dest_off); if (!dest) { WARN_INSN(insn, "can't find call dest symbol at %s+0x%lx", @@ -2002,10 +2012,10 @@ static int add_jump_table(struct objtool_file *file= , struct instruction *insn, =20 /* Detect function pointers from contiguous objects: */ if (reloc->sym->sec =3D=3D pfunc->sec && - reloc->addend =3D=3D pfunc->offset) + reloc_addend(reloc) =3D=3D pfunc->offset) break; =20 - dest_insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!dest_insn) break; =20 @@ -2066,7 +2076,7 @@ static struct reloc *find_jump_table(struct objtool_f= ile *file, table_reloc =3D arch_find_switch_table(file, insn); if (!table_reloc) continue; - dest_insn =3D find_insn(file, table_reloc->sym->sec, table_reloc->addend= ); + dest_insn =3D find_insn(file, table_reloc->sym->sec, reloc_addend(table_= reloc)); if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) continue; =20 @@ -2202,7 +2212,7 @@ static int read_unwind_hints(struct objtool_file *fil= e) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("can't find insn for unwind_hints[%d]", i); return -1; @@ -2265,7 +2275,8 @@ static int read_noendbr_hints(struct objtool_file *fi= le) return 0; =20 for_each_reloc(rsec, reloc) { - insn =3D find_insn(file, reloc->sym->sec, reloc->sym->offset + reloc->ad= dend); + insn =3D find_insn(file, reloc->sym->sec, + reloc->sym->offset + reloc_addend(reloc)); if (!insn) { WARN("bad .discard.noendbr entry"); return -1; @@ -2293,7 +2304,7 @@ static int read_retpoline_hints(struct objtool_file *= file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.retpoline_safe entry"); return -1; @@ -2329,7 +2340,7 @@ static int read_instr_hints(struct objtool_file *file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.instr_end entry"); return -1; @@ -2348,7 +2359,7 @@ static int read_instr_hints(struct objtool_file *file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.instr_begin entry"); return -1; @@ -2376,7 +2387,7 @@ static int read_validate_unret_hints(struct objtool_f= ile *file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.instr_end entry"); return -1; @@ -2407,7 +2418,7 @@ static int read_intra_function_calls(struct objtool_f= ile *file) return -1; } =20 - insn =3D find_insn(file, reloc->sym->sec, reloc->addend); + insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); if (!insn) { WARN("bad .discard.intra_function_call entry"); return -1; @@ -3307,7 +3318,7 @@ static inline const char *call_dest_name(struct instr= uction *insn) =20 reloc =3D insn_reloc(NULL, insn); if (reloc && !strcmp(reloc->sym->name, "pv_ops")) { - idx =3D (reloc->addend / sizeof(void *)); + idx =3D (reloc_addend(reloc) / sizeof(void *)); snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx); return pvname; } @@ -3325,7 +3336,7 @@ static bool pv_call_dest(struct objtool_file *file, s= truct instruction *insn) if (!reloc || strcmp(reloc->sym->name, "pv_ops")) return false; =20 - idx =3D (arch_dest_reloc_offset(reloc->addend) / sizeof(void *)); + idx =3D (arch_dest_reloc_offset(reloc_addend(reloc)) / sizeof(void *)); =20 if (file->pv_ops[idx].clean) return true; @@ -4270,9 +4281,9 @@ static int validate_ibt_insn(struct objtool_file *fil= e, struct instruction *insn off =3D reloc->sym->offset; if (reloc_type(reloc) =3D=3D R_X86_64_PC32 || reloc_type(reloc) =3D=3D R_X86_64_PLT32) - off +=3D arch_dest_reloc_offset(reloc->addend); + off +=3D arch_dest_reloc_offset(reloc_addend(reloc)); else - off +=3D reloc->addend; + off +=3D reloc_addend(reloc); =20 dest =3D find_insn(file, reloc->sym->sec, off); if (!dest) @@ -4329,7 +4340,7 @@ static int validate_ibt_data_reloc(struct objtool_fil= e *file, struct instruction *dest; =20 dest =3D find_insn(file, reloc->sym->sec, - reloc->sym->offset + reloc->addend); + reloc->sym->offset + reloc_addend(reloc)); if (!dest) return 0; =20 diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index be9d24dcdf56..16e019a1762c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -833,10 +833,10 @@ static struct reloc *elf_init_reloc(struct elf *elf, = struct section *rsec, =20 reloc->sec =3D rsec; reloc->sym =3D sym; - reloc->addend =3D addend; =20 reloc->rel.r_offset =3D offset; reloc->rel.r_info =3D GELF_R_INFO(sym->idx, type); + reloc->rela.r_addend =3D addend; =20 if (elf_write_reloc(elf, reloc)) return NULL; @@ -911,8 +911,6 @@ static int read_reloc(struct section *rsec, int i, stru= ct reloc *reloc) return -1; } =20 - reloc->addend =3D rela ? reloc->rela.r_addend : 0; - return 0; } =20 @@ -1231,12 +1229,10 @@ int elf_write_reloc(struct elf *elf, struct reloc *= reloc) struct section *rsec =3D reloc->sec; int ret; =20 - if (rsec->sh.sh_type =3D=3D SHT_RELA) { - reloc->rela.r_addend =3D reloc->addend; + if (rsec->sh.sh_type =3D=3D SHT_RELA) ret =3D gelf_update_rela(rsec->data, reloc_idx(reloc), &reloc->rela); - } else { + else ret =3D gelf_update_rel(rsec->data, reloc_idx(reloc), &reloc->rel); - } =20 if (!ret) { WARN_ELF("gelf_update_rela"); diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 41d2149f8bb8..be08b32a93ee 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -75,7 +75,6 @@ struct reloc { struct section *sec; struct symbol *sym; struct list_head sym_reloc_entry; - s64 addend; bool jump_table_start; }; =20 @@ -217,6 +216,11 @@ static inline void set_reloc_type(struct reloc *reloc,= int type) reloc->rel.r_info =3D GELF_R_INFO(GELF_R_SYM(reloc->rel.r_info), type); } =20 +static inline s64 reloc_addend(struct reloc *reloc) +{ + return reloc->rela.r_addend; +} + #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) =20 diff --git a/tools/objtool/special.c b/tools/objtool/special.c index baa85c31526b..91b1950f5bd8 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -62,7 +62,7 @@ static void reloc_to_sec_off(struct reloc *reloc, struct = section **sec, unsigned long *off) { *sec =3D reloc->sym->sec; - *off =3D reloc->sym->offset + reloc->addend; + *off =3D reloc->sym->offset + reloc_addend(reloc); } =20 static int get_alt_entry(struct elf *elf, const struct special_entry *entr= y, @@ -126,7 +126,7 @@ static int get_alt_entry(struct elf *elf, const struct = special_entry *entry, sec, offset + entry->key); return -1; } - alt->key_addend =3D key_reloc->addend; + alt->key_addend =3D reloc_addend(key_reloc); } =20 return 0; --=20 2.40.1