mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 23/27] kbuild: Do the per-module objtool pass right before linking
Date: Thu, 27 Aug 2026 21:51:52 -0700	[thread overview]
Message-ID: <fd11abd629eef313fa52a6fd154ac3b2049da8a5.1787890035.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1787890035.git.jpoimboe@kernel.org>

With CONFIG_OBJTOOL_CONTROL_FLOW, the objtool pass on vmlinux.o is going
to be generating a list of its exported noreturns which will then be
read by the modules' objtool pass, so there will need to be a build
dependency between them.

In preparation for that, run objtool right before the module link so its
no longer done on the descend in the deferred case.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 scripts/Makefile.build      | 31 +++++++++++++++----------------
 scripts/Makefile.modfinal   | 20 +++++++++++++++-----
 scripts/livepatch/klp-build |  4 ++--
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 84ef12f784330..9e672979a976c 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -270,15 +270,21 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),
 	$(sub_cmd_record_mcount))
 endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
 
-# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
-# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
-# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
-
+ifdef CONFIG_OBJTOOL
+#
+# NOTE: these variables are deprecated, and have no effect when
+# CONFIG_OBJTOOL_DEFERRED is enabled.  Objtool-allergic code can instead be
+# marked with STACK_FRAME_NON_STANDARD() or ANNOTATE_*().
+#
+#   'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
+#   'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
+#   'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
+#
 is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object))
 
-ifdef CONFIG_OBJTOOL
-$(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(CONFIG_OBJTOOL_DEFERRED),$(is-single-obj-m),y))
-endif
+# Enable per-TU objtool for !CONFIG_OBJTOOL_DEFERRED
+$(obj)/%.o: private objtool-enabled = $(if $(CONFIG_OBJTOOL_DEFERRED),,$(if $(is-standard-object),y))
+endif # CONFIG_OBJTOOL
 
 ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
 cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
@@ -495,17 +501,10 @@ $(obj)/lib.a: $(lib-y) FORCE
 	$(call if_changed,ar)
 
 quiet_cmd_ld_multi_m = LD [M]  $@
-      cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$< $(cmd_objtool)
+      cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$<
 
-define rule_ld_multi_m
-	$(call cmd_and_savecmd,ld_multi_m)
-	$(call cmd,gen_objtooldep)
-endef
-
-$(multi-obj-m): private objtool-enabled := $(CONFIG_OBJTOOL_DEFERRED)
-$(multi-obj-m): private part-of-module := y
 $(multi-obj-m): %.o: %.mod FORCE
-	$(call if_changed_rule,ld_multi_m)
+	$(call if_changed,ld_multi_m)
 $(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
 
 # Add intermediate targets:
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 01a37ec872b90..56b4227cc6863 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -32,11 +32,18 @@ ifneq ($(WARN_ON_UNUSED_TRACEPOINTS),)
 cmd_check_tracepoint = $(objtree)/scripts/tracepoint-update --module $<;
 endif
 
+$(modules:%.o=%.ko): private objtool-enabled = $(CONFIG_OBJTOOL_DEFERRED)
+
+mod-objtool = $(if $(objtool-enabled),$(objtool) $(objtool-args) -o $@.o $< ;)
+mod-obj = $(if $(objtool-enabled),$@.o,$<)
+
 quiet_cmd_ld_ko_o = LD [M]  $@
       cmd_ld_ko_o =							\
+	$(mod-objtool)							\
 	$(LD) -r $(KBUILD_LDFLAGS)					\
 		$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)		\
-		-T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^)
+		-T $(objtree)/scripts/module.lds -o $@			\
+		$(mod-obj) $(filter-out $<, $(filter %.o, $^))
 
 quiet_cmd_btf_ko = BTF [M] $@
       cmd_btf_ko = 							\
@@ -46,12 +53,15 @@ quiet_cmd_btf_ko = BTF [M] $@
 		$(CONFIG_SHELL) $(srctree)/scripts/gen-btf.sh --btf_base $(objtree)/vmlinux $@; \
 	fi;
 
+define rule_ld_ko_o
+	+$(call cmd_and_savecmd,ld_ko_o)
+	+$(call cmd,gen_objtooldep)
+	+$(if $(CONFIG_DEBUG_INFO_BTF_MODULES),$(if $(newer-prereqs),$(call cmd,btf_ko)))
+endef
+
 # Re-generate module BTFs if either module's .ko or vmlinux changed
 %.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE
-	+$(call if_changed,ld_ko_o)
-ifdef CONFIG_DEBUG_INFO_BTF_MODULES
-	+$(if $(newer-prereqs),$(call cmd,btf_ko))
-endif
+	$(call if_changed_rule,ld_ko_o)
 	+$(call cmd,check_tracepoint)
 
 targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index b52a8489d9f67..5237bad90f2cb 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -600,7 +600,7 @@ copy_orig_objects() {
 	xtrace_save "copying original objects"
 	for _file in "${files[@]}"; do
 		local rel_file="${_file/.ko/.o}"
-		local file="$PWD/$rel_file"
+		local file="$PWD/${_file/%.ko/.ko.o}"
 		local orig_file="$ORIG_DIR/$rel_file"
 		local orig_dir="$(dirname "$orig_file")"
 
@@ -636,7 +636,7 @@ copy_patched_objects() {
 	xtrace_save "copying changed objects"
 	for _file in "${files[@]}"; do
 		local rel_file="${_file/.ko/.o}"
-		local file="$PWD/$rel_file"
+		local file="$PWD/${_file/%.ko/.ko.o}"
 		local orig_file="$ORIG_DIR/$rel_file"
 		local patched_file="$PATCHED_DIR/$rel_file"
 		local patched_dir="$(dirname "$patched_file")"
-- 
2.55.0


  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 ` Josh Poimboeuf [this message]
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=fd11abd629eef313fa52a6fd154ac3b2049da8a5.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®