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 20/27] x86/boot: Rework how pi startup symbols get exposed to vmlinux
Date: Thu, 27 Aug 2026 21:51:49 -0700 [thread overview]
Message-ID: <e28e963bbdcf0dc7e93d5c42333296168cae8ca0.1787890035.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1787890035.git.jpoimboe@kernel.org>
objcopy prefixes every symbol in arch/x86/boot/startup/ with __pi_,
which confines the startup code so that it can only reach other startup
code or symbols deliberately exposed to it with SYM_PIC_ALIAS().
Nine of its functions are called by the core kernel at runtime. They
are made accessible to the kernel by exports.h, which is included by
vmlinux.lds.S to create aliases for each one.
That's problematic for objtool running on vmlinux.o, which is built
before the linker script runs, so the call sites to the startup symbols
are undefined, so objtool can't see their actual destinations functions.
Instead of making aliases at link time, rename the needed symbols using
a second objcopy pass so they're visible in vmlinux.o. That also means
objtool can now detect that sev_es_terminate() is noreturn, so it can be
removed from noreturns.h.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
arch/x86/boot/startup/Makefile | 14 ++++++++++----
arch/x86/boot/startup/exports.h | 14 --------------
arch/x86/boot/startup/unprefix.syms | 13 +++++++++++++
arch/x86/kernel/vmlinux.lds.S | 2 --
tools/objtool/noreturns.h | 1 -
5 files changed, 23 insertions(+), 21 deletions(-)
delete mode 100644 arch/x86/boot/startup/exports.h
create mode 100644 arch/x86/boot/startup/unprefix.syms
diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile
index ab6e9970d4f4e..5255abe2bd77f 100644
--- a/arch/x86/boot/startup/Makefile
+++ b/arch/x86/boot/startup/Makefile
@@ -41,12 +41,18 @@ $(pi-objs): objtool-args = $(if $(CONFIG_OBJTOOL_DEFERRED),--dry-run,$(objtool-a
#
# Confine the startup code by prefixing all symbols with __pi_ (for position
# independent). This ensures that startup code can only call other startup
-# code, or code that has explicitly been made accessible to it via a symbol
-# alias.
+# code.
#
+# The few pi symbols which are allowed to be called by the core kernel are then
+# un-prefixed back to their original name using a second objcopy.
+#
+quiet_cmd_pi_objcopy = $(quiet_cmd_objcopy)
+ cmd_pi_objcopy = $(cmd_objcopy) && \
+ $(OBJCOPY) --redefine-syms=$(src)/unprefix.syms $@
+
$(obj)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_
-$(obj)/%.pi.o: $(obj)/%.o FORCE
- $(call if_changed,objcopy)
+$(obj)/%.pi.o: $(obj)/%.o $(src)/unprefix.syms FORCE
+ $(call if_changed,pi_objcopy)
targets += $(obj-y)
obj-y := $(patsubst %.o,%.pi.o,$(obj-y))
diff --git a/arch/x86/boot/startup/exports.h b/arch/x86/boot/startup/exports.h
deleted file mode 100644
index 01d2363dc445f..0000000000000
--- a/arch/x86/boot/startup/exports.h
+++ /dev/null
@@ -1,14 +0,0 @@
-
-/*
- * The symbols below are functions that are implemented by the startup code,
- * but called at runtime by the SEV code residing in the core kernel.
- */
-PROVIDE(early_set_pages_state = __pi_early_set_pages_state);
-PROVIDE(early_snp_set_memory_private = __pi_early_snp_set_memory_private);
-PROVIDE(early_snp_set_memory_shared = __pi_early_snp_set_memory_shared);
-PROVIDE(get_hv_features = __pi_get_hv_features);
-PROVIDE(sev_es_terminate = __pi_sev_es_terminate);
-PROVIDE(snp_cpuid = __pi_snp_cpuid);
-PROVIDE(snp_cpuid_get_table = __pi_snp_cpuid_get_table);
-PROVIDE(svsm_issue_call = __pi_svsm_issue_call);
-PROVIDE(svsm_process_result_codes = __pi_svsm_process_result_codes);
diff --git a/arch/x86/boot/startup/unprefix.syms b/arch/x86/boot/startup/unprefix.syms
new file mode 100644
index 0000000000000..fd80adf558a51
--- /dev/null
+++ b/arch/x86/boot/startup/unprefix.syms
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+# The symbols below are functions that are implemented by the startup code,
+# but called at runtime by the SEV code residing in the core kernel. Undo the
+# __pi_ prefixing so the core kernel can call them.
+__pi_early_set_pages_state early_set_pages_state
+__pi_early_snp_set_memory_private early_snp_set_memory_private
+__pi_early_snp_set_memory_shared early_snp_set_memory_shared
+__pi_get_hv_features get_hv_features
+__pi_sev_es_terminate sev_es_terminate
+__pi_snp_cpuid snp_cpuid
+__pi_snp_cpuid_get_table snp_cpuid_get_table
+__pi_svsm_issue_call svsm_issue_call
+__pi_svsm_process_result_codes svsm_process_result_codes
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 74e336d7f9dd2..3d6f4634475cf 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -533,5 +533,3 @@ xen_elfnote_entry_value =
xen_elfnote_phys32_entry_value =
ABSOLUTE(xen_elfnote_phys32_entry) + ABSOLUTE(pvh_start_xen - LOAD_OFFSET);
#endif
-
-#include "../boot/startup/exports.h"
diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h
index c4b93fc6e6299..2dce56030b980 100644
--- a/tools/objtool/noreturns.h
+++ b/tools/objtool/noreturns.h
@@ -20,4 +20,3 @@ NORETURN(mpt_halt_firmware)
NORETURN(panic)
NORETURN(vpanic)
NORETURN(rust_helper_BUG)
-NORETURN(sev_es_terminate)
--
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 ` Josh Poimboeuf [this message]
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 ` [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=e28e963bbdcf0dc7e93d5c42333296168cae8ca0.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