[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <88f2bfd4259b2e951cb9a6a96d2534df2a9be9fa.1586468801.git.mhelsley@vmware.com>
Date: Fri, 10 Apr 2020 12:35:32 -0700
From: Matt Helsley <mhelsley@...are.com>
To: <linux-kernel@...r.kernel.org>
CC: Josh Poimboeuf <jpoimboe@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Julien Thierry <jthierry@...hat.com>,
Ingo Molnar <mingo@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Miroslav Benes <mbenes@...e.cz>,
Matt Helsley <mhelsley@...are.com>
Subject: [RFC][PATCH 09/36] objtool: recordmcount: Search for __mcount_loc before walking the sections
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 <mhelsley@...are.com>
---
tools/objtool/recordmcount.c | 4 ----
tools/objtool/recordmcount.h | 17 +++--------------
2 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/tools/objtool/recordmcount.c b/tools/objtool/recordmcount.c
index 69da5339575f..46a275a393a8 100644
--- a/tools/objtool/recordmcount.c
+++ b/tools/objtool/recordmcount.c
@@ -208,8 +208,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;
@@ -424,8 +422,6 @@ static int is_mcounted_section_name(char const *const txtname)
strcmp(".cpuidle.text", txtname) == 0;
}
-static char const *already_has_rel_mcount = "success"; /* our work here is done! */
-
/* 32 bit and 64 bit are very similar */
#include "recordmcount.h"
#define RECORD_MCOUNT_64
diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h
index 74eab03e31d4..1a848b8104c8 100644
--- a/tools/objtool/recordmcount.h
+++ b/tools/objtool/recordmcount.h
@@ -473,11 +473,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;
@@ -506,10 +501,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);
}
@@ -545,6 +536,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;
@@ -564,11 +558,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)) {
unsigned int recsym;
uint_t recval = 0;
--
2.20.1
Powered by blists - more mailing lists