2020-06-18 20:51:05

by Matt Helsley

[permalink] [raw]
Subject: [RFC][PATCH v5 48/51] objtool: mcount: Eliminate first pass

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 <[email protected]>
---
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