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 25/27] objtool: Add ANNOTATE_EXPORTED_NORETURN()
Date: Thu, 27 Aug 2026 21:51:54 -0700 [thread overview]
Message-ID: <5cb3ce81ac9bc1087313397d5e4b9fc066748dea.1787890035.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1787890035.git.jpoimboe@kernel.org>
Add ANNOTATE_EXPORTED_NORETURN() for the rare case where a module
exports a noreturn function.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
include/linux/annotate.h | 17 +++++++++++++++++
tools/objtool/check.c | 27 +++++++++++++++++++++++++++
tools/objtool/klp-diff.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/include/linux/annotate.h b/include/linux/annotate.h
index a81ca04b4c501..70450eeec3186 100644
--- a/include/linux/annotate.h
+++ b/include/linux/annotate.h
@@ -25,6 +25,15 @@
"912: " \
__stringify(__ASM_ANNOTATE(.discard.annotate_data, 912b, type))
+/*
+ * Annotate a symbol by name rather than by relocation, so it can optionally be
+ * used in a header file.
+ */
+#define ASM_ANNOTATE_NAME(section, sym) \
+ ".pushsection " section ", \"MS\", @progbits, 1\n\t" \
+ ".asciz \"" __stringify(sym) "\"\n\t" \
+ ".popsection"
+
#else /* __ASSEMBLY__ */
.macro ANNOTATE type
@@ -44,6 +53,7 @@
#define ASM_ANNOTATE_LABEL(label, type) ""
#define ASM_ANNOTATE(type)
#define ASM_ANNOTATE_DATA(type)
+#define ASM_ANNOTATE_NAME(section, sym) ""
#else /* __ASSEMBLY__ */
.macro ANNOTATE type
.endm
@@ -112,6 +122,13 @@
*/
#define ANNOTATE_IGNORE_NORETURN(sym) asm(ASM_ANNOTATE_LABEL(sym, ANNOTYPE_IGNORE_NORETURN))
+/*
+ * Tell objtool running on a module that a function exported by another module
+ * is __noreturn. Objtool has no way of communicating that between modules due
+ * to the parallel nature of module linking in kbuild.
+ */
+#define ANNOTATE_EXPORTED_NORETURN(sym) asm(ASM_ANNOTATE_NAME(".discard.annotate_noreturn", sym))
+
/*
* Annotate a special section entry. This emables livepatch module generation
* to find and extract individual special section entries as needed.
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 583d86220e040..6eaac32374722 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -409,6 +409,31 @@ static int read_noreturns(struct objtool_file *file)
return 0;
}
+static void read_annotate_noreturn(struct objtool_file *file)
+{
+ struct section *sec;
+ struct symbol *func;
+ unsigned long off;
+ const char *name;
+
+ sec = find_section_by_name(file->elf, ".discard.annotate_noreturn");
+ if (!sec || !sec->data)
+ return;
+
+ for (off = 0; off < sec_size(sec); off += strlen(name) + 1) {
+ name = sec->data->d_buf + off;
+ if (!*name)
+ continue;
+
+ func = find_global_symbol_by_name(file->elf, name);
+ if (!func)
+ continue;
+
+ if (is_undef_sym(func))
+ func->_noreturn = 1;
+ }
+}
+
static void init_cfi_state(struct cfi_state *cfi)
{
int i;
@@ -4984,6 +5009,8 @@ int check(struct objtool_file *file)
goto out;
}
+ read_annotate_noreturn(file);
+
ret = decode_file(file);
if (ret)
goto out;
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 16681a76f13d0..5719a8e016cb3 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -361,6 +361,7 @@ static bool is_special_section(struct section *sec)
static const char * const non_special_discards[] = {
".discard.addressable",
+ ".discard.annotate_noreturn",
".discard.sym_checksum",
};
@@ -2217,6 +2218,34 @@ static int copy_import_ns(struct elfs *e)
return 0;
}
+/*
+ * ANNOTATE_EXPORTED_NORETURN() annotations reference their functions by name
+ * rather than by relocation, so individual entries can't be extracted. Copy
+ * the (tiny) section as-is.
+ */
+static int copy_annotate_noreturn(struct elfs *e)
+{
+ struct section *patched_sec, *out_sec;
+
+ patched_sec = find_section_by_name(e->patched, ".discard.annotate_noreturn");
+ if (!patched_sec || !patched_sec->data || !sec_size(patched_sec))
+ return 0;
+
+ out_sec = elf_create_section(e->out, patched_sec->name, 0,
+ patched_sec->sh.sh_entsize,
+ patched_sec->sh.sh_type,
+ patched_sec->sh.sh_addralign,
+ patched_sec->sh.sh_flags);
+ if (!out_sec)
+ return -1;
+
+ if (!elf_add_data(e->out, out_sec, patched_sec->data->d_buf,
+ sec_size(patched_sec)))
+ return -1;
+
+ return 0;
+}
+
int cmd_klp_diff(int argc, const char **argv)
{
struct elfs e = {0};
@@ -2288,6 +2317,9 @@ int cmd_klp_diff(int argc, const char **argv)
if (copy_import_ns(&e))
return -1;
+ if (copy_annotate_noreturn(&e))
+ return -1;
+
if (elf_write(e.out))
return -1;
--
2.55.0
next 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 ` Josh Poimboeuf [this message]
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 ` [PATCH 27/27] objtool: Warn about missing/stale ANNOTATE_EXPORTED_NORETURN() usage Josh Poimboeuf
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=5cb3ce81ac9bc1087313397d5e4b9fc066748dea.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