Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1649015ybt; Thu, 18 Jun 2020 13:51:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyxtMJiD+FCh9vYk5+ZuLro845nEzRxtRUo8qtHDnpkzsWC4yBSZBEpUZ01ptazUV2OghW X-Received: by 2002:a05:6402:376:: with SMTP id s22mr85010edw.250.1592513465334; Thu, 18 Jun 2020 13:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513465; cv=none; d=google.com; s=arc-20160816; b=R7Nd/ZGcjk37SYW4rVxQYDPjNfAENRhfIVdMat7qPBVe9vaE52M8Dwp3RdXLWyF/dg 9zQo5GSyhv6Tx1d8MHTLIHBMIP2VE/6QfLooOPpSbq/8jtI2yfugpT15SPFghvXvvYvu 9jrdU00Hd6GI06gbrkIf2Vt6fpHZdSv21PwShJQMhdo2SWuj6pA706wuRRHgyA6iN4mq ZwbIXBBAIhWdq/o0pZaV9UtS6lYAEX3pQ06+BRTy2RXEUmod6f+vX55gn5jq4mJAeoF5 Bj4nA70/5ZF+IylCxd9qxcZK9/Bt2p0dCG6feSZo7qXifbCHZuI0zBj7smOVKEeNY2uU QfwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RS3MPWQnfxmks/lToGltoMHZTcE/d3sdOlMjJ98uarM=; b=NhxQBetNLBVfi6XDT3kFpuyX3uwV6nughd+CIuTXs0RiniEfvqdv86B0/uO9L20mip 8j0h3iT+kpbkq9aO1k9uHJfgp4gxWtVlK3mk6BzzAjyxTrHnqsPjULRwa/iBIwoOKEBD avSvg70YpcdjIqCF9TvqymY+pfN+vP7yrSINF/arbpoD1Y4WY38oOMDje3JNS6qlQLXD qn+lFsUa8ZWAF0HfiyFUL0rhWW9k0I6Od3MPgpcWE6OExSN7e1aj0A6pvhJsgvcXWC4A vMkC6l1WPWLE3q6QbL2hJcZ6Qiea9X3AydiRbIxWleo0lppMAkMWB/5cxNRsczPihpBY PudQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si2625686edl.529.2020.06.18.13.50.43; Thu, 18 Jun 2020 13:51:05 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732331AbgFRUkw (ORCPT + 99 others); Thu, 18 Jun 2020 16:40:52 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36734 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731484AbgFRUjm (ORCPT ); Thu, 18 Jun 2020 16:39:42 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:36 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 2B062B265A; Thu, 18 Jun 2020 16:39:40 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 48/51] objtool: mcount: Eliminate first pass Date: Thu, 18 Jun 2020 13:38:34 -0700 Message-ID: <0cac2f36423a66cf981f66cc1710735602786225.1592510545.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Determine the size of the mcount relocations in objtool's ELF reading code. This reduces the number of passes we make through the list of sections (which can become large due to things like -ffunction-sections). Signed-off-by: Matt Helsley --- tools/objtool/elf.c | 2 ++ tools/objtool/elf.h | 1 + tools/objtool/mcount.c | 16 +--------------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 12bd889a62ba..733e10d4a574 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -642,6 +642,8 @@ static int read_relocs(struct elf *elf) sec->base->reloc = sec; sec->mcountable = relocs_mcountable(sec); + if (sec->mcountable && !elf->mcount_rel_entsize) + elf->mcount_rel_entsize = sec->sh.sh_entsize; nr_reloc = 0; for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h index fb10f470d1a4..8ece1ca79cca 100644 --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -87,6 +87,7 @@ struct elf { Elf *elf; GElf_Ehdr ehdr; int fd; + size_t mcount_rel_entsize; bool changed; char *name; struct list_head sections; diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c index 80daf0e17eab..9527924af56b 100644 --- a/tools/objtool/mcount.c +++ b/tools/objtool/mcount.c @@ -274,19 +274,6 @@ static int nop_mcount(struct section * const rels, return 0; } -static void tot_relsize(unsigned int *rel_entsize) -{ - const struct section *sec; - - list_for_each_entry(sec, &lf->sections, list) { - if (sec->sh.sh_type != SHT_REL && - sec->sh.sh_type != SHT_RELA) - continue; - if (sec->mcountable) - *rel_entsize = sec->sh.sh_entsize; - } -} - /* zero or a small negative offset added to get the start of the call * instruction */ @@ -388,14 +375,13 @@ static int do_mcount(unsigned const reltype, size_t rela_size) struct section *sec, *mlocs, *mrels; const char * const mc_name = "__mcount_loc"; - unsigned int rel_entsize = 0; + const unsigned int rel_entsize = lf->mcount_rel_entsize; int result = -1; bool is_rela; if (find_section_by_name(lf, "__mcount_loc") != NULL) return 0; - tot_relsize(&rel_entsize); is_rela = (rela_size == rel_entsize); /* add section: __mcount_loc */ -- 2.20.1