Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1649326ybt; Thu, 18 Jun 2020 13:51:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZuIS4qE51S3+XHOWOfBzDJLGq+xaNdm5I4FNZAWOOES8/BhBRLkydx1hnNu5t7tD2+83Y X-Received: by 2002:a50:fa8d:: with SMTP id w13mr84582edr.324.1592513494580; Thu, 18 Jun 2020 13:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592513494; cv=none; d=google.com; s=arc-20160816; b=KUA+gEC1/vOfbOFBpEzHMzLUpKFcwnUcPuCoegEzKVSUED2ztQ1qQNGxuBIA2fXHHX 83W/huMcnDgPie4n0k5MIN3zP1D1mNIw0WVGcUvWtoPiJTPMlBmXPbUwtO045Gc4MhMi TjeXbUktLa5R/wNk6sD62NmlwqMvYZ2dsVnlpAH5jzR3LuIpD0fcDT30zRWDu3lwu+oG YEp2HsOhs23GEXpZoiIpWxDGBn5MoZ5azpvSrWTo5Dg3xF0e1uFBFfFRJjHs81CW7sx4 O4DSThIfOs3EUqD//1WVYqn2C8Kvw4dxFAx+r99bUL4PWEVpynpbohdNRln8Gs0kBANb O65Q== 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=LPfO0L4p1TJaay1kFXcjuBkUh9iS9jVPEGolrFQRsDw=; b=xE8cYrSnpb2uelzNSyum3M8g3xUzwy4R4aOcK7cpH8scb3upBbDRo4pq3tx8UultoG D3AXTSg84uYfhZ2lxGfE7U30otF4k6ur6LPrG3Na4vFQS9FIZmz02ZLonT/kbPAmE5ai iWaUVZtfQ7T+0NFNfYcsQYV9W5OO7ccXTRt6AiKK4XlpcI9x5xbAkX+AuWnhnJMRCHsu II0elvEnqLANFBOnuQgBsRjJF1w1wv92wxGj0BP+lPYID8Um6UNdQbZGGVmJM/Udh9U9 9v7jWAk1dRVPKV30zWr1ACvU3ODz3OCQKm8pMYh/hJFUvUnbQMsGVqhdERqAqY9rGeoP yRAA== 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 v27si2433128eja.107.2020.06.18.13.51.12; Thu, 18 Jun 2020 13:51:34 -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 S1732118AbgFRUlx (ORCPT + 99 others); Thu, 18 Jun 2020 16:41:53 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:40437 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731391AbgFRUjg (ORCPT ); Thu, 18 Jun 2020 16:39:36 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Thu, 18 Jun 2020 13:39:32 -0700 Received: from sc9-mailhost2.vmware.com (unknown [10.129.221.29]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9A0E7B2668; Thu, 18 Jun 2020 16:39:35 -0400 (EDT) From: Matt Helsley To: CC: Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Julien Thierry , Kamalesh Babulal , Matt Helsley Subject: [RFC][PATCH v5 42/51] objtool: mcount: Move mcount symbol name testing Date: Thu, 18 Jun 2020 13:38:28 -0700 Message-ID: <0a4ae1e3db4f65c8da1988b58e19915e1bf8327d.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-001.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 Move the test for mcount symbols into the ELF code itself and set a class on indicator on the symbol. This simplifies mcount a little and tests the symbols names near where they're first touched so should be cache-hot and may also help us reduce the number of passes through the ELF contents needed for individual subcommands. Finally, if we manage to combine subcommands into a single exec of objtool the number of passes through the ELF data could be even further reduced. Suggested-by: Peter Zijlstra Signed-off-by: Matt Helsley --- tools/objtool/elf.c | 18 ++++++++++++++++++ tools/objtool/elf.h | 6 ++++++ tools/objtool/mcount.c | 31 +++---------------------------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 8dcdea8020a5..d55d8fef11b4 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -387,6 +387,21 @@ static int read_sections(struct elf *elf) return 0; } +static bool is_mcount_sym(const char *name) +{ + if (name[0] == '.') + name++; /* ppc64 hack */ + + if (name[0] == '_') + name++; + + if (strcmp("mcount", name) == 0 || + (strcmp("__gnu_mcount_nc", name) == 0) || + (strcmp("_fentry__", name) == 0)) + return true; + return false; +} + static int read_symbols(struct elf *elf) { struct section *symtab, *symtab_shndx, *sec; @@ -456,6 +471,9 @@ static int read_symbols(struct elf *elf) } else sym->sec = find_section_by_index(elf, 0); + if (is_mcount_sym(sym->name)) + sym->class = SYM_MCOUNT; + sym->offset = sym->sym.st_value; sym->len = sym->sym.st_size; diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h index 09fa0d085341..13935edaff54 100644 --- a/tools/objtool/elf.h +++ b/tools/objtool/elf.h @@ -42,6 +42,11 @@ struct section { bool changed, text, rodata, noinstr; }; +enum symbol_class { + SYM_REGULAR = 0, + SYM_MCOUNT = 1, +}; + struct symbol { struct list_head list; struct rb_node node; @@ -55,6 +60,7 @@ struct symbol { unsigned long offset; unsigned int len; struct symbol *pfunc, *cfunc, *alias; + enum symbol_class class; bool uaccess_safe; }; diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c index 029e6e72c972..7fbde6ce6eb8 100644 --- a/tools/objtool/mcount.c +++ b/tools/objtool/mcount.c @@ -152,24 +152,6 @@ static int is_mcounted_section_name(char const *const txtname) strcmp(".cpuidle.text", txtname) == 0; } -static struct symbol *get_mcount_sym(struct reloc *reloc) -{ - struct symbol *sym = reloc->sym; - char const *symname = sym->name; - - if (symname[0] == '.') - symname++; /* ppc64 hack */ - - if (symname[0] == '_') - symname++; - - if (strcmp("mcount", symname) == 0 || - (strcmp("__gnu_mcount_nc", symname) == 0) || - (strcmp("_fentry__", symname) == 0)) - return sym; - return NULL; -} - /* * MIPS mcount long call has 2 _mcount symbols, only the position of the 1st * _mcount symbol is needed for dynamic function tracer, with it, to disable @@ -266,16 +248,13 @@ static int nop_mcount(struct section * const rels, { struct reloc *reloc; struct section *txts = find_section_by_index(lf, rels->sh.sh_info); - struct symbol *mcount_sym = NULL; int once = 0; list_for_each_entry(reloc, &rels->reloc_list, list) { int ret = -1; - if (!mcount_sym) - mcount_sym = get_mcount_sym(reloc); - - if (mcount_sym == reloc->sym && !is_fake_mcount(reloc)) { + if (reloc->sym->class == SYM_MCOUNT && + !is_fake_mcount(reloc)) { if (make_nop) { ret = make_nop(txts, reloc->offset); if (ret < 0) @@ -355,16 +334,12 @@ static void sift_rel_mcount(GElf_Addr **mlocpp, { GElf_Rel *mrelp = *mrelpp; GElf_Rela *mrelap = *mrelpp; - struct symbol *mcount_sym = NULL; struct reloc *reloc; list_for_each_entry(reloc, &rels->reloc_list, list) { unsigned long addend; - if (!mcount_sym) - mcount_sym = get_mcount_sym(reloc); - - if (mcount_sym != reloc->sym || is_fake_mcount(reloc)) + if (reloc->sym->class == SYM_MCOUNT || is_fake_mcount(reloc)) continue; addend = reloc->offset - recval + mcount_adjust; -- 2.20.1