Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4834680rwd; Tue, 30 May 2023 10:31:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5vc+BTidCSMT2KiLa4lGgI3XWU7dESz1rHEQxSfLvQe6oYQRQf1GEb2m10gcP4QFeonnHg X-Received: by 2002:a05:6a20:1612:b0:10f:652a:27ea with SMTP id l18-20020a056a20161200b0010f652a27eamr11879506pzj.6.1685467887096; Tue, 30 May 2023 10:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685467887; cv=none; d=google.com; s=arc-20160816; b=v7SllfcTS7dXQ/F6kEewlYYW9tw4grkNSdEgdOtTmoieyrL3OgHOPrqzZ9UbZV00Jo qZWPyFIS5xSxr8+ntsR8qjcaGJt3aDlNJ0OxYlsrm944xBi5Z40Hp8R+GLtWAF/HyW+P Xl7UYHFQvs21U1HtykkNGtWTNWTqIbhp4oNijxWZbTwAFi5gPKEDWTC02kp2vggBoX3n nTlcFaYW9p51GncGdeCx9n+PpixrNYsfGK9EEbJpxGBd0UesRcnCxDgzgN5TwsnGn9YP T6l0oUdFH6pFEUdurLWdE/D2npch6catwgZTviY8mS/ZZXA2P+fO29sZAhs4pZSC5KaR 9tzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UcDAqSR1Px9ocY2Z8y0JplTm3/sHup5UI7mt0jAWxxA=; b=LD8i10WTy+CnmrE6nUl+xtzSlXzLhyuQEbIrhDmmLiBuryeRngXj8KrL9DEgyQyaRH WXp67byaT4UfxiaN8XNrA0MRYGslO6WsAPd8/fkrQjQzwrSYpjm2Mc9tNRHtRS/xIZQ3 oLtX/rt8aXJoL6oaWDNCcVX+FuLYoiEnIsi0qgnP8u/zPaQCWk/tuqBcH3yhANplwNW4 6OTdjq1fKJdiErvkajaFiI7cy4Z7nkCGP/vQ/lL3ubmxKTJBwL6s1jAUN+43W2X+lvXD lGLfvFaPPiMAlrKqZBsZjZpxuvDtZTo47ZbB7n+ZQhBNDdO4ohbPtEDqOHJdQuiqbqOw f5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ruh/7afC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s205-20020a632cd6000000b0053f2803af48si1920791pgs.581.2023.05.30.10.31.12; Tue, 30 May 2023 10:31:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ruh/7afC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231702AbjE3RWD (ORCPT + 99 others); Tue, 30 May 2023 13:22:03 -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: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) } /* - * Ensure that any reloc section containing references to @sym is marked - * changed such that it will get re-generated in elf_rebuild_reloc_sections() - * 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; - 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; } /* @@ -716,13 +718,14 @@ __elf_create_symbol(struct elf *elf, struct symbol *sym) hlist_del(&old->hash); elf_hash_add(symbol, &old->hash, old->idx); - elf_dirty_reloc_sym(elf, old); - if (elf_update_symbol(elf, symtab, symtab_shndx, old)) { WARN("elf_update_symbol move"); return NULL; } + if (elf_update_sym_relocs(elf, old)) + return NULL; + new_idx = first_non_local; } @@ -833,12 +836,13 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, reloc->sym = sym; reloc->addend = addend; + 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)); - mark_sec_changed(elf, rsec, true); - return reloc; } @@ -1203,31 +1207,6 @@ struct section *elf_create_section_pair(struct elf *elf, const char *name, return sec; } -static int elf_rebuild_reloc_section(struct elf *elf, struct section *rsec) -{ - struct reloc *reloc; - int idx = 0, ret; - - idx = 0; - list_for_each_entry(reloc, &rsec->reloc_list, list) { - reloc->rel.r_offset = reloc->offset; - reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); - if (rsec->sh.sh_type == SHT_RELA) { - reloc->rela.r_addend = reloc->addend; - ret = gelf_update_rela(rsec->data, idx, &reloc->rela); - } else { - ret = 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; } - if (sec->base && - elf_rebuild_reloc_section(elf, sec)) { - WARN("elf_rebuild_reloc_section"); - return -1; - } - mark_sec_changed(elf, sec, false); } } -- 2.40.1