From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Gary Guo <gary@garyguo.net>,
rust-for-linux@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Miguel Ojeda <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>,
linux-kbuild@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>
Subject: [PATCH 27/27] objtool: Warn about missing/stale ANNOTATE_EXPORTED_NORETURN() usage
Date: Thu, 27 Aug 2026 21:51:56 -0700 [thread overview]
Message-ID: <4db947677ac3e655a094335c8a23fc0dfe5b2e56.1787890035.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1787890035.git.jpoimboe@kernel.org>
Add some warnings to keep ANNOTATE_EXPORTED_NORETURN() annotations
correct.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/Documentation/objtool.txt | 22 ++++++++-
tools/objtool/check.c | 59 ++++++++++++++++++++-----
tools/objtool/include/objtool/elf.h | 1 +
3 files changed, 71 insertions(+), 11 deletions(-)
diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt
index d5ac48bc203ec..950e88c713d1d 100644
--- a/tools/objtool/Documentation/objtool.txt
+++ b/tools/objtool/Documentation/objtool.txt
@@ -393,7 +393,7 @@ the objtool maintainers.
a) funcA()'s last instruction is a call to a "noreturn" function like
panic(), and objtool doesn't know that function never returns. See
- warning 3 above.
+ warnings 3 and 13.
b) funcA() uses the unreachable() annotation in a section of code
that is actually reachable.
@@ -455,6 +455,26 @@ the objtool maintainers.
macros to create them.
+13. file.o: warning: objtool: func() is exported and noreturn, its declaration needs __noreturn and ANNOTATE_EXPORTED_NORETURN()
+
+ func() is exported and never returns, but is defined in a module, so
+ its noreturn status needs to be manually annotated. Put an
+ ANNOTATE_EXPORTED_NORETURN() next to its declaration.
+
+ Mark the declaration __noreturn while you're there, if it isn't
+ already. The two go together: __noreturn stops the compiler from
+ emitting code after the call, and the annotation tells objtool the
+ call doesn't return.
+
+
+14. file.o: warning: objtool: func() has ANNOTATE_EXPORTED_NORETURN() but returns
+
+ func() is annotated as never returning, but it does. Usually this
+ means the annotation outlived the fact: the function grew a return path
+ and the ANNOTATE_EXPORTED_NORETURN() next to its declaration was left
+ behind. Remove it, along with the __noreturn.
+
+
If the error doesn't seem to make sense, it could be a bug in objtool.
Feel free to ask objtool maintainers for help.
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index aced52ad6fc81..ac6ae823a2d45 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -224,6 +224,22 @@ static bool might_return(struct objtool_file *file, struct symbol *func)
return false;
}
+static bool is_noreturn_candidate(struct objtool_file *file, struct symbol *func)
+{
+ struct instruction *insn;
+
+ if (!is_func_sym(func) || is_undef_sym(func) ||
+ is_prefix_func(func) || func->embedded_insn ||
+ func != func->alias->pfunc)
+ return false;
+
+ insn = find_insn(file, func->sec, func->offset);
+ if (!insn || insn_func(insn) != func)
+ return false;
+
+ return true;
+}
+
static void detect_noreturns(struct objtool_file *file)
{
struct symbol *func, *dest;
@@ -232,15 +248,7 @@ static void detect_noreturns(struct objtool_file *file)
/* Mark all functions guilty until proven innocent */
for_each_sym(file->elf, func) {
-
- /* Aliases and cold subfunctions inherit the parent's verdict */
- if (!is_func_sym(func) || is_undef_sym(func) ||
- is_prefix_func(func) || func->embedded_insn ||
- func != func->alias->pfunc)
- continue;
-
- insn = find_insn(file, func->sec, func->offset);
- if (!insn || insn_func(insn) != func)
+ if (!is_noreturn_candidate(file, func))
continue;
func->_noreturn = 1;
@@ -410,9 +418,38 @@ static void read_annotate_noreturn(struct objtool_file *file)
if (is_undef_sym(func))
func->_noreturn = 1;
+
+ func->annotate_noreturn = 1;
}
}
+static int validate_noreturns(struct objtool_file *file)
+{
+ struct symbol *func;
+ int warnings = 0;
+
+ for_each_sym(file->elf, func) {
+ if (!is_noreturn_candidate(file, func))
+ continue;
+
+ if (opts.module && is_noreturn(func) && func->exported &&
+ !func->annotate_noreturn) {
+ WARN("%s() is exported and noreturn, its declaration needs __noreturn and ANNOTATE_EXPORTED_NORETURN()",
+ func->name);
+ warnings++;
+ }
+
+ if (func->annotate_noreturn && !func->ignore_noreturn &&
+ !is_noreturn(func)) {
+ WARN("%s() has ANNOTATE_EXPORTED_NORETURN() but returns",
+ func->name);
+ warnings++;
+ }
+ }
+
+ return warnings;
+}
+
static void init_cfi_state(struct cfi_state *cfi)
{
int i;
@@ -5005,8 +5042,10 @@ int check(struct objtool_file *file)
w += validate_functions(file);
w += validate_unwind_hints(file, NULL);
- if (!w)
+ if (!w) {
w += validate_reachable_instructions(file);
+ w += validate_noreturns(file);
+ }
warnings += w;
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index adf6e1322c6df..e79cdabf09c26 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -100,6 +100,7 @@ struct symbol {
u8 fake : 1;
u8 _noreturn : 1;
u8 ignore_noreturn : 1;
+ u8 annotate_noreturn : 1;
u8 exported : 1;
struct list_head pv_target;
struct reloc *relocs;
--
2.55.0
prev parent reply other threads:[~2026-08-28 4:52 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 4:51 [PATCH 00/27] objtool: dynamically detect noreturns Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 01/27] objtool: Remove obsolete noreturns.h entries Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 02/27] kbuild: Add CONFIG_OBJTOOL_DEFERRED Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 03/27] kbuild: Add CONFIG_OBJTOOL_CONTROL_FLOW Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 04/27] objtool: Fix dead end detection for sibling calls Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 05/27] objtool: Refactor the noreturn/dead-end detection Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 06/27] objtool: Ignore traps after noreturn calls in STT_CODE Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 07/27] objtool: Make .discard.stack_frame_non_standard non-allocatable Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 08/27] efi/libstub: Drop .discard.addressable from the stub objects Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 09/27] efi/loongarch: Mark loongarch efi_boot_kernel() non-standard for objtool Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 10/27] objtool: Add ANNOTATE_IGNORE_NORETURN() Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 11/27] LoongArch: Annotate reboot and kexec paths as returnable Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 12/27] kbuild: Defer running objtool to link time for all CFG features Josh Poimboeuf
2026-08-28 17:57 ` Nathan Chancellor
2026-08-28 18:19 ` Josh Poimboeuf
2026-08-28 19:27 ` Nathan Chancellor
2026-08-28 4:51 ` [PATCH 13/27] rust: Annotate the intrinsic stubs as returnable Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 14/27] panic: Mark abort() __noreturn Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 15/27] x86/xen: Ignore noreturn status of weak mem_map_via_hcall() Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 16/27] objtool: Detect noreturns in weak functions Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 17/27] x86/entry: Make rewind_stack_and_make_dead() a real function Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 18/27] x86/xen: Make xen_cpu_bringup_again() " Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 19/27] x86/xen: Make xen_start_kernel() noreturn Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 20/27] x86/boot: Rework how pi startup symbols get exposed to vmlinux Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 21/27] objtool: Fix noreturn detection for non-sibling jumps to SYM_CODE Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 22/27] objtool: Add options to write/read exported noreturns to/from a file Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 23/27] kbuild: Do the per-module objtool pass right before linking Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 24/27] kbuild: Generate the noreturn list and validate modules against it Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 25/27] objtool: Add ANNOTATE_EXPORTED_NORETURN() Josh Poimboeuf
2026-08-28 4:51 ` [PATCH 26/27] objtool: Annotate all module-exported noreturns and remove noreturns.h Josh Poimboeuf
2026-08-28 4:51 ` Josh Poimboeuf [this message]
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=4db947677ac3e655a094335c8a23fc0dfe5b2e56.1787890035.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--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®