[PATCH RESEND] objtool: speedup subsequent calls to dead_end_function()

Dmitry Antipov posted 1 patch 1 week, 5 days ago
tools/objtool/check.c               | 5 ++++-
tools/objtool/include/objtool/elf.h | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
[PATCH RESEND] objtool: speedup subsequent calls to dead_end_function()
Posted by Dmitry Antipov 1 week, 5 days ago
Running over KASAN-enabled vmlinux.o, some functions comes from the
sanitizer runtime may be processed by 'dead_end_function()' a lot of
times, so it's reasonable to record the result in 'struct symbol' of
the relevant function. Briefly testing over huge 'make allyesconfig'
vmlinux.o, this may speedup objtool by nearly 10%.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 tools/objtool/check.c               | 5 ++++-
 tools/objtool/include/objtool/elf.h | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index d14f20ef1db1..d4c0ef419b95 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -322,7 +322,10 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 
 static bool dead_end_function(struct objtool_file *file, struct symbol *func)
 {
-	return __dead_end_function(file, func, 0);
+	if (func->functype == UNKNOWN)
+		func->functype = (__dead_end_function(file, func, 0)
+				  ? NORETURN : REGULAR);
+	return func->functype == NORETURN;
 }
 
 static void init_cfi_state(struct cfi_state *cfi)
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index 0a2fa3ac0079..2c491eb07741 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -70,6 +70,7 @@ struct symbol {
 	u8 local_label       : 1;
 	u8 frame_pointer     : 1;
 	u8 ignore	     : 1;
+	enum { UNKNOWN, REGULAR, NORETURN } functype : 2;
 	struct list_head pv_target;
 	struct reloc *relocs;
 	struct section *group_sec;
-- 
2.51.0
Re: [PATCH RESEND] objtool: speedup subsequent calls to dead_end_function()
Posted by Josh Poimboeuf 1 week, 5 days ago
On Fri, Sep 19, 2025 at 04:55:57PM +0300, Dmitry Antipov wrote:
> Running over KASAN-enabled vmlinux.o, some functions comes from the
> sanitizer runtime may be processed by 'dead_end_function()' a lot of
> times, so it's reasonable to record the result in 'struct symbol' of
> the relevant function. Briefly testing over huge 'make allyesconfig'
> vmlinux.o, this may speedup objtool by nearly 10%.
> 
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
>  tools/objtool/check.c               | 5 ++++-
>  tools/objtool/include/objtool/elf.h | 1 +
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index d14f20ef1db1..d4c0ef419b95 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -322,7 +322,10 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
>  
>  static bool dead_end_function(struct objtool_file *file, struct symbol *func)
>  {
> -	return __dead_end_function(file, func, 0);
> +	if (func->functype == UNKNOWN)
> +		func->functype = (__dead_end_function(file, func, 0)
> +				  ? NORETURN : REGULAR);
> +	return func->functype == NORETURN;
>  }

Thanks for the patch.

Since this basically gets called at least once for every function
anyway, how about we just identify them during init, all at once, in
decode_sections()?  Then we only need a single "noreturn" bit.

-- 
Josh