Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp8324250pxb; Fri, 19 Feb 2021 13:12:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbzHBON7bqShQ+PpDMTw/ZbzAO9EY7EjZt4Iyc8mHP0ZN7HOFwIhfPEh0lWx3sTEArMaHw X-Received: by 2002:a17:906:af84:: with SMTP id mj4mr10800005ejb.84.1613769145411; Fri, 19 Feb 2021 13:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613769145; cv=none; d=google.com; s=arc-20160816; b=nqQnZtZxoKe5BzUHwy0j8x3gcARicsPNoyKQHLlTOFvoOWOC0mbJLQAl60uCGpnFf+ FGhJ2yThfSMyedqBtgkJ/x2xWUllpuI4xyHhaKBNbBgnjHwQIzyvnV7Y7ynMiSLxp7Np emtroQliCdU55AwON3Ba5sUjx2r6x3GXUMHsAYSyMQSluT772bgcYDKaDn7It//IWig8 onnkWnFzU3rGzI1I5MW5/tXPJObVbmUVuEVfQHrKacxYLcOYt1CowEHuhvzN3b83seHU PT0j5jtUmVOu6O2FHIRoSFvyAaG1DxdTrjC3JmodB8vke35cd1f29ePWx83rYzhfny34 bHCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=3vPoZkrKeiK4JPBw7+vZIWdXmKr4+YumvsYH8ORDDis=; b=Ko2Y8fFYH0EmV1Az9S33n8Cmixi1L8Dd8XCF08MQQoXvl6oO3/muxv1Wv8A94SlMKZ VWOJDIXeyVMIpo/xSHv44Fv06M87M2aC/YrOv1uH3RcP/eWDzsGnv/45dvQwxuZfJqk2 6O4h+sg/MAkfJizBL/MnOhCOu3DEe0imdW1j/BSM2G2bCmxNkregYAyn+U0ves0b63Qh ZV7+yrpeJAT1HTfBb5WPKDVCwYcN65MbBMTq/NUliJAB+Qt4woeBAVNS1jod1MzPcj/P Xyc8rqJRCTN9dDVcxCXtn+Pus3BMnNLATdN+3HVlfNFNAU52wPrmL6Gch1S+5C8qj8Fk 6lEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=FFtAgiJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si7470735eji.387.2021.02.19.13.12.02; Fri, 19 Feb 2021 13:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=FFtAgiJt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbhBSVLC (ORCPT + 99 others); Fri, 19 Feb 2021 16:11:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbhBSVK4 (ORCPT ); Fri, 19 Feb 2021 16:10:56 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B44BC06178B for ; Fri, 19 Feb 2021 13:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=3vPoZkrKeiK4JPBw7+vZIWdXmKr4+YumvsYH8ORDDis=; b=FFtAgiJtTpyvmlMdZTSOKena+Y 5rtWOnfFfVJYs0g+ZaB9m2MgN6+wg37fpq2siZxUU1qRWQqB9pkrxS0suc1BA1Zq3tjnvuRpWkUwy l2QSTxAemvz929CNpYPpkvit88To8GoRNJHGOwtc5fHsNhEJCS14DvlYR9gVzeUvoDXejXySJX1oe d3gT24XwiInHmx+x3SUKkHwujDQbJCs8ygsjhF/PSFAgVJnBHijCH1EvIh0KxezQRat4Rd1J9fuvW +pWNaCCfz0DsTboEozeJ64jOGsJ9TKVZhq66fWhx/2qIiMfWjR3V0QIUcUFCAcrmQbP312w8jJNBg +LIO626A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1lDD2N-0006Gc-U3; Fri, 19 Feb 2021 21:10:08 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 697BC306099; Fri, 19 Feb 2021 22:10:05 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 4A8DA20215560; Fri, 19 Feb 2021 22:10:05 +0100 (CET) Message-ID: <20210219210535.312773268@infradead.org> User-Agent: quilt/0.66 Date: Fri, 19 Feb 2021 21:43:03 +0100 From: Peter Zijlstra To: jpoimboe@redhat.com, x86@kernel.org, pjt@google.com, mbenes@suze.cz, jgross@suse.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [RFC][PATCH 3/6] objtool: Rework rebuild_reloc logic References: <20210219204300.749932493@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) --- tools/objtool/check.c | 3 --- tools/objtool/elf.c | 13 ++++++++++++- tools/objtool/include/objtool/elf.h | 2 +- tools/objtool/orc_gen.c | 3 --- 4 files changed, 13 insertions(+), 8 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 @@ -479,6 +479,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->rereloc = true; } static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) @@ -558,7 +560,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); @@ -890,6 +894,8 @@ int elf_rebuild_reloc_section(struct elf case SHT_RELA: return elf_rebuild_rela_reloc_section(sec, nr); default: return -1; } + + sec->rereloc = false; } int elf_write_insn(struct elf *elf, struct section *sec, @@ -944,6 +950,11 @@ int elf_write(struct elf *elf) struct section *sec; Elf_Scn *s; + list_for_each_entry(sec, &elf->sections, list) { + if (sec->reloc && sec->reloc->rereloc) + elf_rebuild_reloc_section(elf, sec->reloc); + } + /* Update section headers for changed sections: */ list_for_each_entry(sec, &elf->sections, list) { if (sec->changed) { --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -39,7 +39,7 @@ struct section { char *name; int idx; unsigned int len; - bool changed, text, rodata, noinstr; + bool changed, text, rodata, noinstr, rereloc; }; struct symbol { --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -254,8 +254,5 @@ int orc_create(struct objtool_file *file return -1; } - if (elf_rebuild_reloc_section(file->elf, ip_rsec)) - return -1; - return 0; }