From nobody Sun Feb 8 21:29:33 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 A0D19C7EE23 for ; Tue, 30 May 2023 17:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233300AbjE3RWF (ORCPT ); Tue, 30 May 2023 13:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232862AbjE3RVj (ORCPT ); Tue, 30 May 2023 13:21:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2BDEC for ; Tue, 30 May 2023 10:21:35 -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 432C763123 for ; Tue, 30 May 2023 17:21:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C5AEC433A0; Tue, 30 May 2023 17:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467294; bh=Ysxh7lAkSp3EE9042bKmW8CQmu0Vy2TT9tV2rI9hxSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ruh/7afCQoGJd7hDuV73+GW+lr51JA200teuHzksxnUpgZgRQWR6ZKQf2SKyBOiw5 Og4+2H07UOJuxuCwPKZAF9s/9hnWoWsg6PS0D5D3rMqnFpXcONgHfKJk13K++5naWq 2f24BRs6Cz7y0HMj0+xOEGiCzX7XFiUqTDdsuOQoTb/g8vHmXT0Eg28jMq0Vg+Elds ClHLv3phlxlXv7Rj9NCFjQYmFBCER3BgOYjf/CVH9hLBbyyrfOve0GPq5UWBLaXjVf tCuMJ4X3BcsW05PqTiSxAc2ry1bNsXO2QiDz6uvS/zBmDb+4wuzekpeeH3N9/e1BJd 0DBc51CYo3+SQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 08/22] objtool: Keep GElf_Rel[a] structs synced Date: Tue, 30 May 2023 10:21:00 -0700 Message-Id: <156d8a3e528a11e5c8577cf552890ed1f2b9567b.1685464332.git.jpoimboe@kernel.org> 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" Keep the GElf_Rela structs synced with their 'struct reloc' counterparts instead of having to go back and "rebuild" them later. Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 55 ++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 5cbc9d578a45..8d491b2d123e 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -534,16 +534,18 @@ static int read_symbols(struct elf *elf) } =20 /* - * Ensure that any reloc section containing references to @sym is marked - * changed such that it will get re-generated in elf_rebuild_reloc_section= s() - * with the new symbol index. + * @sym's idx has changed. Update the relocs which reference it. */ -static void elf_dirty_reloc_sym(struct elf *elf, struct symbol *sym) +static int elf_update_sym_relocs(struct elf *elf, struct symbol *sym) { struct reloc *reloc; =20 - list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) - mark_sec_changed(elf, reloc->sec, true); + list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) { + if (elf_write_reloc(elf, reloc)) + return -1; + } + + return 0; } =20 /* @@ -716,13 +718,14 @@ __elf_create_symbol(struct elf *elf, struct symbol *s= ym) hlist_del(&old->hash); elf_hash_add(symbol, &old->hash, old->idx); =20 - elf_dirty_reloc_sym(elf, old); - if (elf_update_symbol(elf, symtab, symtab_shndx, old)) { WARN("elf_update_symbol move"); return NULL; } =20 + if (elf_update_sym_relocs(elf, old)) + return NULL; + new_idx =3D first_non_local; } =20 @@ -833,12 +836,13 @@ static struct reloc *elf_init_reloc(struct elf *elf, = struct section *rsec, reloc->sym =3D sym; reloc->addend =3D addend; =20 + if (elf_write_reloc(elf, reloc)) + return NULL; + list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list); list_add_tail(&reloc->list, &rsec->reloc_list); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); =20 - mark_sec_changed(elf, rsec, true); - return reloc; } =20 @@ -1203,31 +1207,6 @@ struct section *elf_create_section_pair(struct elf *= elf, const char *name, return sec; } =20 -static int elf_rebuild_reloc_section(struct elf *elf, struct section *rsec) -{ - struct reloc *reloc; - int idx =3D 0, ret; - - idx =3D 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { - reloc->rel.r_offset =3D reloc->offset; - reloc->rel.r_info =3D GELF_R_INFO(reloc->sym->idx, reloc->type); - if (rsec->sh.sh_type =3D=3D SHT_RELA) { - reloc->rela.r_addend =3D reloc->addend; - ret =3D gelf_update_rela(rsec->data, idx, &reloc->rela); - } else { - ret =3D gelf_update_rel(rsec->data, idx, &reloc->rel); - } - if (!ret) { - WARN_ELF("gelf_update_rel"); - return -1; - } - idx++; - } - - return 0; -} - int elf_write_insn(struct elf *elf, struct section *sec, unsigned long offset, unsigned int len, const char *insn) @@ -1351,12 +1330,6 @@ int elf_write(struct elf *elf) return -1; } =20 - if (sec->base && - elf_rebuild_reloc_section(elf, sec)) { - WARN("elf_rebuild_reloc_section"); - return -1; - } - mark_sec_changed(elf, sec, false); } } --=20 2.40.1