Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10010261ybi; Wed, 24 Jul 2019 14:06:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9Zi/VUEFr1kgx15/7MaliSBIbZ1V6DQA51k8kcCswbMRKQE/Y29t5aj5OZARnCvBAB/N4 X-Received: by 2002:a17:90a:c68c:: with SMTP id n12mr90906387pjt.29.1564002417626; Wed, 24 Jul 2019 14:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564002417; cv=none; d=google.com; s=arc-20160816; b=Lcoqqq05Yq6ZIjj50S6AvgdyKUk5l18fC8MkzFg8z+vOAA+D05ma/zvOr0cF/24rha FfkADzpghXV1PQMF1kUGqekaMFriq9eUmnRAICOo7w/FKhFEUM8xCMGB9/JbE8Ex+9eK 8hXTWto2OFFsq/RovcmnSopsZsWlAoOqdZCyaFcM4MASaKmpj1K24rkjqEMK79ddWVSS WZBc8IrAA7fVZEFxSMPc0BI6kzGYkGtQsj65Pta8UAuxZDgSwb2aoHU/XRxQyD3QfM8Q 0ALPFvnzs0CgaYSeFlxh6QfGiRzVBtEZqv3DY5jaX3mG+y0iaOyRCtQT+OhfK1U3mIzr Jg/g== 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=j4+njSxMtb39TU6hHtt768GY907jmX4shttRNErKkCc=; b=BizGpWIbgVQw0s4Z1r3Ii4qNF17xZLiC4Bxvo4Ov2gaQKirmkRIHMyXo4iHveR2sUk YcFCf0ADo4A6cCazpISLdQROItjijg4gwlTDLcXaijhflyy9IRTdREH4AIz/rEE/7S/1 caI+I3i/s6Jz7G0jmnCAMVUs6lRDWCaP/EKvswjz2P7jJarW7PVr4zpL1IKwwvG3m5Th 1ZAL2YA/VVTBa2LQ9MsMz0Qm3bJuD94w74k3bsFaePPAKa3qwf2c+Vp3xqHqXr01q8x2 +0wjpuuIpal66XFpDNwN5HM8xm2U3KuZ6wASAoidlRdpEkwT1+GoquRPBzkSfwe03lc2 A76w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 207si18516183pfu.258.2019.07.24.14.06.43; Wed, 24 Jul 2019 14:06:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388195AbfGXVFr (ORCPT + 99 others); Wed, 24 Jul 2019 17:05:47 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:53154 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388086AbfGXVFo (ORCPT ); Wed, 24 Jul 2019 17:05:44 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Wed, 24 Jul 2019 14:05:10 -0700 Received: from rlwimi.localdomain (unknown [10.166.65.164]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 64227407C8; Wed, 24 Jul 2019 14:05:30 -0700 (PDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [PATCH v3 12/13] objtool: recordmcount: Search for __mcount_loc before walking the sections Date: Wed, 24 Jul 2019 14:05:06 -0700 Message-ID: <033f258d1967b78e717b2bbf3d593ce4441d8f57.1563992889.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.20.1 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 recordmcount iterates over the sections in the order they're listed in the ELF file and checks whether the section name indicates it's of interest. Objtool's elf code works differently -- it scans the elf file and builds up data structures representing the headers, sections, etc. and then supplies functions to search these structures. Both walk the elf file in order, however objtool uses more memory to enable faster searches it needs for other tools such as the reliable backtrace support offered by the ORC unwinder. Rather than walk the section table a second time in the recordmcount code, we use objtool's elf code to search for the section recordmcount is interested in. This also simplifies flow and means we can easily check for already-processed object files before we do any of the more complex things recordmcount does. This also allows us to remove the already_has_rel_mcount string pointer trick. Signed-off-by: Matt Helsley --- tools/objtool/recordmcount.c | 2 -- tools/objtool/recordmcount.h | 22 +++------------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c index 28b5c5e4beae..7e7a738373c3 100644 --- a/tools/objtool/recordmcount.c +++ b/tools/objtool/recordmcount.c @@ -204,8 +204,6 @@ static void *mmap_file(char const *fname) } else mmap_failed = 0; out: - elf_close(lf); - lf = NULL; fd_map = -1; file_end = file_map + sb.st_size; diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h index ef2eefb65d02..2345017f59d9 100644 --- a/tools/objtool/recordmcount.h +++ b/tools/objtool/recordmcount.h @@ -26,7 +26,6 @@ #undef nop_mcount #undef missing_sym #undef find_secsym_ndx -#undef already_has_rel_mcount #undef __has_rel_mcount #undef has_rel_mcount #undef tot_relsize @@ -58,7 +57,6 @@ # define nop_mcount nop_mcount_64 # define missing_sym missing_sym_64 # define find_secsym_ndx find64_secsym_ndx -# define already_has_rel_mcount already_has_rel_mcount_64 # define __has_rel_mcount __has64_rel_mcount # define has_rel_mcount has64_rel_mcount # define tot_relsize tot64_relsize @@ -93,7 +91,6 @@ # define nop_mcount nop_mcount_32 # define missing_sym missing_sym_32 # define find_secsym_ndx find32_secsym_ndx -# define already_has_rel_mcount already_has_rel_mcount_32 # define __has_rel_mcount __has32_rel_mcount # define has_rel_mcount has32_rel_mcount # define tot_relsize tot32_relsize @@ -472,8 +469,6 @@ static unsigned find_secsym_ndx(unsigned const txtndx, return missing_sym; } -char const *already_has_rel_mcount = "success"; /* our work here is done! */ - /* Evade ISO C restriction: no declaration after statement in has_rel_mcount. */ static char const * __has_rel_mcount(Elf_Shdr const *const relhdr, /* reltype */ Elf_Shdr const *const shdr0, @@ -484,11 +479,6 @@ static char const * __has_rel_mcount(Elf_Shdr const *const relhdr, /* reltype */ Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)]; char const *const txtname = &shstrtab[w(txthdr->sh_name)]; - if (strcmp("__mcount_loc", txtname) == 0) { - fprintf(stderr, "warning: __mcount_loc already exists: %s\n", - fname); - return already_has_rel_mcount; - } if (w(txthdr->sh_type) != SHT_PROGBITS || !(_w(txthdr->sh_flags) & SHF_EXECINSTR)) return NULL; @@ -517,10 +507,6 @@ static unsigned tot_relsize(Elf_Shdr const *const shdr0, for (; nhdr; --nhdr, ++shdrp) { txtname = has_rel_mcount(shdrp, shdr0, shstrtab, fname); - if (txtname == already_has_rel_mcount) { - totrelsz = 0; - break; - } if (txtname && is_mcounted_section_name(txtname)) totrelsz += _w(shdrp->sh_size); } @@ -556,6 +542,9 @@ static int do_func(Elf_Ehdr *const ehdr, char const *const fname, int result = 0; + if (find_section_by_name(lf, "__mcount_loc") != NULL) + return 0; + totrelsz = tot_relsize(shdr0, nhdr, shstrtab, fname); if (totrelsz == 0) return 0; @@ -575,11 +564,6 @@ static int do_func(Elf_Ehdr *const ehdr, char const *const fname, for (relhdr = shdr0, k = nhdr; k; --k, ++relhdr) { char const *const txtname = has_rel_mcount(relhdr, shdr0, shstrtab, fname); - if (txtname == already_has_rel_mcount) { - result = 0; - file_updated = 0; - goto out; /* Nothing to be done; don't append! */ - } if (txtname && is_mcounted_section_name(txtname)) { uint_t recval = 0; unsigned const int recsym = find_secsym_ndx( -- 2.20.1