From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Miroslav Benes <mbenes@suse.cz>
Subject: Re: [PATCH v2 8/9] objtool: Detect missing __noreturn annotations
Date: Thu, 13 Apr 2023 10:48:01 +0200 [thread overview]
Message-ID: <20230413084801.GI4253@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <0f630a0eb4585ab4114e4eecaa6f166a1fd81d49.1681325924.git.jpoimboe@kernel.org>
On Wed, Apr 12, 2023 at 12:03:23PM -0700, Josh Poimboeuf wrote:
> Most "unreachable instruction" warnings these days seem to actually be
> the result of a missing __noreturn annotation. Add an explicit check
> for that.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
> tools/objtool/Documentation/objtool.txt | 6 ++++++
> tools/objtool/check.c | 14 +++++++++++++-
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt
> index 5a69c207a10e..2cd1fa16ed08 100644
> --- a/tools/objtool/Documentation/objtool.txt
> +++ b/tools/objtool/Documentation/objtool.txt
> @@ -303,6 +303,12 @@ the objtool maintainers.
> If it's not actually in a callable function (e.g. kernel entry code),
> change ENDPROC to END.
>
> +3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn annotation
> +
> + The call from foo() to bar() doesn't return, but bar() is missing the
> + __noreturn annotation. NOTE: In addition to adding the __noreturn
> + annotation, the function name also needs to be added to
> + 'global_noreturns' in tools/objtool/check.c.
Do we want something like the below (except perhaps less horrible) ?
---
tools/objtool/Makefile | 1 +
tools/objtool/check.c | 27 +--------------------------
tools/objtool/noreturns | 26 ++++++++++++++++++++++++++
tools/objtool/noreturns.sh | 7 +++++++
4 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 83b100c1e7f6..50b6cd241571 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -63,6 +63,7 @@ include $(srctree)/tools/build/Makefile.include
$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
$(Q)$(CONFIG_SHELL) ./sync-check.sh
+ $(Q)$(CONFIG_SHELL) ./noreturns.sh
$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
LDFLAGS="$(OBJTOOL_LDFLAGS)"
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f937be1afe65..f558730c27b6 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -197,32 +197,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
* attribute isn't provided in ELF data. Keep 'em sorted.
*/
static const char * const global_noreturns[] = {
- "__invalid_creds",
- "__module_put_and_kthread_exit",
- "__reiserfs_panic",
- "__stack_chk_fail",
- "__ubsan_handle_builtin_unreachable",
- "cpu_bringup_and_idle",
- "cpu_startup_entry",
- "do_exit",
- "do_group_exit",
- "do_task_dead",
- "ex_handler_msr_mce",
- "fortify_panic",
- "kthread_complete_and_exit",
- "kthread_exit",
- "kunit_try_catch_throw",
- "lbug_with_loc",
- "machine_real_restart",
- "make_task_dead",
- "panic",
- "rewind_stack_and_make_dead",
- "sev_es_terminate",
- "snp_abort",
- "stop_this_cpu",
- "usercopy_abort",
- "xen_cpu_bringup_again",
- "xen_start_kernel",
+#include "noreturns.h"
};
if (!func)
diff --git a/tools/objtool/noreturns b/tools/objtool/noreturns
new file mode 100644
index 000000000000..75f35fbb34d1
--- /dev/null
+++ b/tools/objtool/noreturns
@@ -0,0 +1,26 @@
+__invalid_creds
+__module_put_and_kthread_exit
+__reiserfs_panic
+__stack_chk_fail
+__ubsan_handle_builtin_unreachable
+cpu_bringup_and_idle
+cpu_startup_entry
+do_exit
+do_group_exit
+do_task_dead
+ex_handler_msr_mce
+fortify_panic
+kthread_complete_and_exit
+kthread_exit
+kunit_try_catch_throw
+lbug_with_loc
+machine_real_restart
+make_task_dead
+panic
+rewind_stack_and_make_dead
+sev_es_terminate
+snp_abort
+stop_this_cpu
+usercopy_abort
+xen_cpu_bringup_again
+xen_start_kernel
diff --git a/tools/objtool/noreturns.sh b/tools/objtool/noreturns.sh
new file mode 100755
index 000000000000..f728cb61e665
--- /dev/null
+++ b/tools/objtool/noreturns.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+cat noreturns | while read func
+do
+ echo \"${func}\",
+done > noreturns.h
next prev parent reply other threads:[~2023-04-13 8:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-12 19:03 [PATCH v2 0/9] objtool: warning improvements Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 1/9] scripts/objdump-func: Support multiple functions Josh Poimboeuf
2023-04-14 14:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 2/9] objtool: Add WARN_INSN() Josh Poimboeuf
2023-04-14 14:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 3/9] objtool: Limit unreachable warnings to once per function Josh Poimboeuf
2023-04-13 8:01 ` Peter Zijlstra
2023-04-13 15:03 ` Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 4/9] objtool: Add symbol iteration helpers Josh Poimboeuf
2023-04-14 14:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 5/9] objtool: Add verbose option for disassembling affected functions Josh Poimboeuf
2023-04-13 8:05 ` Peter Zijlstra
2023-04-13 15:05 ` Josh Poimboeuf
2023-04-13 8:08 ` Peter Zijlstra
2023-04-13 14:03 ` Miroslav Benes
2023-04-13 15:09 ` Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 6/9] objtool: Include backtrace in verbose mode Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 7/9] objtool: Remove superfluous dead_end_function() check Josh Poimboeuf
2023-04-14 14:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 8/9] objtool: Detect missing __noreturn annotations Josh Poimboeuf
2023-04-13 8:48 ` Peter Zijlstra [this message]
2023-04-13 15:19 ` Josh Poimboeuf
2023-04-13 19:17 ` Peter Zijlstra
2023-04-13 14:19 ` Miroslav Benes
2023-04-13 15:32 ` Josh Poimboeuf
2023-04-12 19:03 ` [PATCH v2 9/9] objtool: Ignore exc_double_fault() __noreturn warnings Josh Poimboeuf
2023-04-13 9:24 ` Peter Zijlstra
2023-04-14 21:16 ` Nick Desaulniers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230413084801.GI4253@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®