[PATCH] objtool: Cache number of return sites recorded

From: Nikolay Borisov
Date: Tue Aug 15 2023 - 06:36:37 EST


On an allyesconfig currently the kernels emits 454324. No point in
making around half a million iterations just to count them. Simply
increment a counter at the time of creation of each site.

Quick measurements shows a meager 200ms improvement when running
objtool --rethunk --prefix=64 --no-unreachable --stats --link

Signed-off-by: Nikolay Borisov <nik.borisov@xxxxxxxx>
---
tools/objtool/check.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 8936a05f0e5a..bb71c5d8859f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -33,6 +33,7 @@ static struct cfi_init_state initial_func_cfi;
static struct cfi_state init_cfi;
static struct cfi_state func_cfi;
static struct cfi_state force_undefined_cfi;
+static unsigned long nr_rethunk_sites;

struct instruction *find_insn(struct objtool_file *file,
struct section *sec, unsigned long offset)
@@ -802,15 +803,12 @@ static int create_return_sites_sections(struct objtool_file *file)
return 0;
}

- idx = 0;
- list_for_each_entry(insn, &file->return_thunk_list, call_node)
- idx++;
-
- if (!idx)
+ if (!nr_rethunk_sites)
return 0;

sec = elf_create_section_pair(file->elf, ".return_sites",
- sizeof(int), idx, idx);
+ sizeof(int), nr_rethunk_sites,
+ nr_rethunk_sites);
if (!sec)
return -1;

@@ -1473,8 +1471,10 @@ static void add_return_call(struct objtool_file *file, struct instruction *insn,
insn->type = INSN_RETURN;
insn->retpoline_safe = true;

- if (add)
+ if (add) {
list_add_tail(&insn->call_node, &file->return_thunk_list);
+ nr_rethunk_sites++;
+ }
}

static bool is_first_func_insn(struct objtool_file *file,
--
2.34.1