[RFC PATCH 1/4] Kbuild/link-vmlinux.sh: Make output file name configurable

Ard Biesheuvel
2025-02-24T13:21:53Z

From: Ard Biesheuvel <ardb@kernel.org>

In order to introduce an intermediate, non-stripped vmlinux build that
can be used by other build steps as an input, pass the output file name
to link-vmlinux.sh via its command line.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
scripts/Makefile.vmlinux | 2 +-
scripts/link-vmlinux.sh | 11 ++++++-----
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 873caaa55313..3523ce3ce3dc 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -69,7 +69,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)

# Final link of vmlinux with optional arch pass after final link
cmd_link_vmlinux = \
- $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \
+ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)

targets += vmlinux
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 56a077d204cf..e55026128e05 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -31,6 +31,7 @@ set -e
LD="$1"
KBUILD_LDFLAGS="$2"
LDFLAGS_vmlinux="$3"
+VMLINUX="$4"

is_enabled() {
grep -q "^$1=y" include/config/auto.conf
@@ -278,7 +279,7 @@ fi

strip_debug=

-vmlinux_link vmlinux
+vmlinux_link "${VMLINUX}"

# fill in BTF IDs
if is_enabled CONFIG_DEBUG_INFO_BTF; then
@@ -290,11 +291,11 @@ if is_enabled CONFIG_DEBUG_INFO_BTF; then
${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_ARGS} vmlinux
fi

-mksysmap vmlinux System.map
+mksysmap "${VMLINUX}" System.map

if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then
- info SORTTAB vmlinux
- if ! sorttable vmlinux; then
+ info SORTTAB "${VMLINUX}"
+ if ! sorttable "${VMLINUX}"; then
echo >&2 Failed to sort kernel tables
exit 1
fi
@@ -310,4 +311,4 @@ if is_enabled CONFIG_KALLSYMS; then
fi

# For fixdep
-echo "vmlinux: $0" > .vmlinux.d
+echo "${VMLINUX}: $0" > ".${VMLINUX}.d"
--
2.48.1.601.g30ceb7b040-goog