Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1368458imi; Sat, 23 Jul 2022 03:53:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t9h08cHFok23+vW2K92zLTowa9qqVluOlAVhDQXN93SG/V3fJaW1msPQtprqOTXkW+sAgN X-Received: by 2002:a62:158a:0:b0:52a:c074:3e08 with SMTP id 132-20020a62158a000000b0052ac0743e08mr4048242pfv.16.1658573625668; Sat, 23 Jul 2022 03:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573625; cv=none; d=google.com; s=arc-20160816; b=o6FNnTgGtgZS+ZJgRIfFLy/tSF6cFOJeCYry/F3C+gn54MRryNaOdfmtt1Cq6pF7KS LrdSD1ctoSKlh2NSYn79zBVD2BaeeirlLTmSZ9ZuVcpihsiHT9R6uUYaj9qlAHo7A5Vv YdsML+IAHa15AVpUQ5mX0LEAxwb6iMEfEfaRnUF0oAijiGRQwICIdGbJdQehgPwHZLRW soaZ7CKemQarscGrGVFLdHC+GOPppmYc04n/Kkj3Ru1fx1hFJaRPibavVwLmCjmAzfQj 6NrP4cjiNiR7EzoDvqolIsy3zFWurxAaVGmuZ8oqB5Z8nfvb9oH3XexI6yqU/TIFuyla 5sSA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NxBeT7HMFpn6arw/515pkb4fpgSWsUY98tjRkWVT2as=; b=zwImC1Fw0s3lrSKMP13f/Mk31SBj56oryVT6fl1G2uTZEV9NiT5UPeUOsivHLndk2C jGTVzFFOFFuOAjmRqnROSXysIP1cwvv54KGCBwBv82mUvlr6q///BUQ9WUZsJZlrhufz j4y19n/GhLKTZN5pzScBVp+8babF+cW9FxaVvaak6xhV4C1kMinaxUISd3ZUjfJsCcdT MlknCbKIrFcCxb3LFWC5YFpwTCoNZcWgJWJQqy4+xOgGpbrTnwd7LxsgU2xEcqzirSaB azjG2m6yjvCNoxQ2xF1UUm6OLinVoUc4+Q/igagM91qQD01yN+1/q7MnX+92fy8XpyJI faxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qfghO25L; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170903300300b0016c66bf1a15si7318908pla.34.2022.07.23.03.53.30; Sat, 23 Jul 2022 03:53:45 -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=@linuxfoundation.org header.s=korg header.b=qfghO25L; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237783AbiGWJ7h (ORCPT + 99 others); Sat, 23 Jul 2022 05:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237488AbiGWJ64 (ORCPT ); Sat, 23 Jul 2022 05:58:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE94C6D2CF; Sat, 23 Jul 2022 02:57:43 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7873BB827CC; Sat, 23 Jul 2022 09:57:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCC8EC341C0; Sat, 23 Jul 2022 09:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570261; bh=fUn8IkFO0m8VZnxYLrY3/qaO1ly3x4v0tCiWNKY25ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfghO25L21MW3RlV1WF/RsFn+Hlwdt9E85eMWfIcQvu/mgFak0Hg9Tmhp1hxcxHnm 3OxRznv1Cfhe7w+aD9nFUI4/9zOa3/86ZO3tTewJnH+4X0pSQ2c1GNcKnwqk6ZvUZe 1KQTbr8UdvT5B0wYxDVGUVnzB9AOJ9eTBb+ChZoA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Ingo Molnar , Miroslav Benes , Ben Hutchings Subject: [PATCH 5.10 025/148] objtool: Rework the elf_rebuild_reloc_section() logic Date: Sat, 23 Jul 2022 11:53:57 +0200 Message-Id: <20220723095231.451413936@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 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 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 From: Peter Zijlstra commit 3a647607b57ad8346e659ddd3b951ac292c83690 upstream. Instead of manually calling elf_rebuild_reloc_section() on sections we've called elf_add_reloc() on, have elf_write() DTRT. This makes it easier to add random relocations in places without carefully tracking when we're done and need to flush what section. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Signed-off-by: Ingo Molnar Reviewed-by: Miroslav Benes Link: https://lkml.kernel.org/r/20210326151259.754213408@infradead.org [bwh: Backported to 5.10: drop changes in create_mcount_loc_sections()] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/check.c | 3 --- tools/objtool/elf.c | 20 ++++++++++++++------ tools/objtool/elf.h | 1 - tools/objtool/orc_gen.c | 3 --- 4 files changed, 14 insertions(+), 13 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -542,9 +542,6 @@ static int create_static_call_sections(s idx++; } - if (elf_rebuild_reloc_section(file->elf, reloc_sec)) - return -1; - return 0; } --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -530,6 +530,8 @@ void elf_add_reloc(struct elf *elf, stru list_add_tail(&reloc->list, &sec->reloc_list); elf_hash_add(elf->reloc_hash, &reloc->hash, reloc_hash(reloc)); + + sec->changed = true; } static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) @@ -609,7 +611,9 @@ static int read_relocs(struct elf *elf) return -1; } - elf_add_reloc(elf, reloc); + list_add_tail(&reloc->list, &sec->reloc_list); + elf_hash_add(elf->reloc_hash, &reloc->hash, reloc_hash(reloc)); + nr_reloc++; } max_reloc = max(max_reloc, nr_reloc); @@ -920,14 +924,11 @@ static int elf_rebuild_rela_reloc_sectio return 0; } -int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) +static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) { struct reloc *reloc; int nr; - sec->changed = true; - elf->changed = true; - nr = 0; list_for_each_entry(reloc, &sec->reloc_list, list) nr++; @@ -991,9 +992,15 @@ int elf_write(struct elf *elf) struct section *sec; Elf_Scn *s; - /* Update section headers for changed sections: */ + /* Update changed relocation sections and section headers: */ list_for_each_entry(sec, &elf->sections, list) { if (sec->changed) { + if (sec->base && + elf_rebuild_reloc_section(elf, sec)) { + WARN("elf_rebuild_reloc_section"); + return -1; + } + s = elf_getscn(elf->elf, sec->idx); if (!s) { WARN_ELF("elf_getscn"); @@ -1005,6 +1012,7 @@ int elf_write(struct elf *elf) } sec->changed = false; + elf->changed = true; } } --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -142,7 +142,6 @@ struct reloc *find_reloc_by_dest_range(c struct symbol *find_func_containing(struct section *sec, unsigned long offset); void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset, struct reloc *reloc); -int elf_rebuild_reloc_section(struct elf *elf, struct section *sec); #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -251,8 +251,5 @@ int orc_create(struct objtool_file *file return -1; } - if (elf_rebuild_reloc_section(file->elf, ip_rsec)) - return -1; - return 0; }