[RFC][PATCH v5 50/51] objtool: mcount: Remove useless lookup

From: Matt Helsley
Date: Thu Jun 18 2020 - 16:41:28 EST


Since the relocation section's sh_info points back to the text
section it applies to and we already have that we can just pass
it in and greatly simplify find_section_sym_index().

Signed-off-by: Matt Helsley <mhelsley@xxxxxxxxxx>
---
tools/objtool/mcount.c | 39 +++++++++++++++------------------------
1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c
index 084bbc02de0c..a74625aed09b 100644
--- a/tools/objtool/mcount.c
+++ b/tools/objtool/mcount.c
@@ -198,35 +198,27 @@ static const unsigned int missing_sym = (unsigned int)-1;
* Num: Value Size Type Bind Vis Ndx Name
* 2: 00000000 0 SECTION LOCAL DEFAULT 1
*/
-static int find_section_sym_index(unsigned const txtndx,
- char const *const txtname,
- unsigned long *const recvalp,
- unsigned int *sym_index)
+static int find_section_sym_index(const struct section * const txts,
+ unsigned long *const recvalp,
+ unsigned int *sym_index)
{
struct symbol *sym;
- struct section *txts = find_section_by_index(lf, txtndx);
-
- if (!txts) {
- fprintf(stderr, "Cannot find section %u: %s.\n",
- txtndx, txtname);
- return missing_sym;
- }

list_for_each_entry(sym, &txts->symbol_list, list) {
/* avoid symbols with weak binding */
- if ((sym->bind == STB_LOCAL) || (sym->bind == STB_GLOBAL)) {
- /* function symbols on ARM have quirks, avoid them */
- if (lf->ehdr.e_machine == EM_ARM
- && sym->type == STT_FUNC)
- continue;
-
- *recvalp = sym->sym.st_value;
- *sym_index = sym->idx;
- return 0;
- }
+ if ((sym->bind != STB_LOCAL) && (sym->bind != STB_GLOBAL))
+ continue;
+
+ /* function symbols on ARM have quirks, avoid them */
+ if (lf->ehdr.e_machine == EM_ARM && sym->type == STT_FUNC)
+ continue;
+
+ *recvalp = sym->sym.st_value;
+ *sym_index = sym->idx;
+ return 0;
}
fprintf(stderr, "Cannot find symbol for section %u: %s.\n",
- txtndx, txtname);
+ txts->idx, txts->name);
return missing_sym;
}

@@ -414,8 +406,7 @@ static int do_mcount(unsigned const reltype)
unsigned long recval = 0;
unsigned int recsym;

- if (find_section_sym_index(sec->sh.sh_info,
- txts->name, &recval, &recsym))
+ if (find_section_sym_index(txts, &recval, &recsym))
goto out;

sift_rel_mcount(&r_offset, sec, mrels, mlocs,
--
2.20.1