From nobody Fri Apr 10 06:22:25 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFE0024889B for ; Mon, 24 Feb 2025 13:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403316; cv=none; b=NEiWeysnT4WxbSIH0q8+Gbwy/rTPym01C4zw2LaTjm6lz0Tk79I1FJsPZynDWKr754YXqtrhsQQByU6LKqlf1ecAyPbS6QdZyF+mXD5xqUaUd/dTs1kFgJX8PC1GO0jPoAsq1GjAel+JY+4o7vDAbIdjj1YFpLtxkIxHDVUBpLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403316; c=relaxed/simple; bh=dRq0U8z9TE+qNLNwYD7S40TkyqyC8cws+VNe0sBWZT4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F207y7dFgKpy9V54Kp9pinYwuTLHJenh0s8yz49OvhisfDFxOITJ6d/F2GwAlgUVFKyDadd/5xHleu9dNaCDTPMn4HFUXTe28BqotPBdeuy39MH6CnoajF3mfQeG7/N4mBI2yDZ48ppOT9LiPU3wsNU4yvrk7wo2v53b1uxe66U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XaJOdO6w; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XaJOdO6w" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-38f51a3a833so1711794f8f.2 for ; Mon, 24 Feb 2025 05:21:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740403312; x=1741008112; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8PDru/78LRKbfp6+7TkdUZoiPcKmAw5IJh8X3W3/JHc=; b=XaJOdO6wnvC0oYsVP5uJJuueBs5CcjOaBlV/aQyiQIWySnuy9l0my08mNFsK07uB5/ JfHgtDgFX2gk1VVLvBbx6JXqi/xje2aDYrx8Qe7PAe7SxAST8tcvgCES4Te2x4RATqiV ntKLcZOCpagAI2GuBmQ0dOzfUE7mmtCfRHkCBQdRpISfZZoLDrv7IaPZyhbi3yzIKuuA mQJySE/ECfNQ48e0CV8InQIAJxW+8U5coJz7LK2DbpVEqPUgdgNTLXE8Me5gufnkaa0V JSW6KYredvXSnzF/+J2zjdSlZulUNTYrHOJI/6mvzpfHRy7uWb7m2SZzCnDqzoMzwsqY mm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740403312; x=1741008112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8PDru/78LRKbfp6+7TkdUZoiPcKmAw5IJh8X3W3/JHc=; b=Eo4cvrlmeFWUkMwJPTbDba2cmIK9UeCHnc+tgft8UtW4/z8wRsQih/DstJWNhIfcUn EmzoJNLCOFTCTvAtrUMHzX02GsAVsARNDgnMiGG2Ubpexm7hP4oEIRcROhZqgLi3qjtd 3wHQ+mpYHM8cMuoVRtLGsGzw6oIjZ6gJ1MfFfMfdQE6++RuB/5FuSnllI0jT5z5fpafv YdWbF7MqbPiikZk4W0POXj8IiTSEpOi5GYi8mW5sFwpmb2YEivzOS6SLdfLelW6pluqh erLhzql62dFJC6GuO3RXDHWLicH5ctLipX5RVUw7wHCHLI59z/ilwvSb/cA4uMsrsqZe 6K9Q== X-Gm-Message-State: AOJu0YyrnSOBLbS/pKfD1b/qfv1YBduA91XmjLZ3f2hYrQ44QepKsBvE gbuENb55ngIAji2HAjXwHsf5AwM0D0PLQtAsilQG14ecx+6Z1Bm17S5ReAY9q7FTSLViL4U5Wpi xLOT+GGKcertHFU3sEub9TafHY0XQQhzOKl/EnoECC8awxiObbwWVgob8yq00lgDGwS06KDlon/ yB68CriLyMHDj0H661tOMb32ODLEBupA== X-Google-Smtp-Source: AGHT+IGU6iDng62JC/uLtF9oeXB7JINtB0+X2gy+zOzmsORQVum5UsRDNd0ELZATXgLI/M52j6Z9Q+1I X-Received: from wmbec10.prod.google.com ([2002:a05:600c:610a:b0:439:35bc:65d0]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5886:0:b0:38a:2b34:e13e with SMTP id ffacd0b85a97d-38f70789b52mr11208308f8f.18.1740403312079; Mon, 24 Feb 2025 05:21:52 -0800 (PST) Date: Mon, 24 Feb 2025 14:21:34 +0100 In-Reply-To: <20250224132132.1765115-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250224132132.1765115-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2052; i=ardb@kernel.org; h=from:subject; bh=MckhOuu0fwDOa6nZDYfMs/sVcAaSvlXxSpoP6NXXouI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIX1PUZztSo+O9dm7WebVL9w0VV/ovoOuwKz/YUuWLuVgK HrtJlfdUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZSZcLwP6bXJ+ho2p3tq/mF W0/dF7jeO0fGQeFTyaZkbgeG7UxpyowME46d/Huu1O/g2f7TZyI/GctEFSh1PF9qumGpoL6FseB cVgA= X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250224132132.1765115-7-ardb+git@google.com> Subject: [RFC PATCH 1/4] Kbuild/link-vmlinux.sh: Make output file name configurable From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel 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 --- 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 :=3D $(wildcard $(srctree)/arch/$(SRCARCH)/= Makefile.postlink) =20 # Final link of vmlinux with optional arch pass after final link cmd_link_vmlinux =3D \ - $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ + $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) =20 targets +=3D 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=3D"$1" KBUILD_LDFLAGS=3D"$2" LDFLAGS_vmlinux=3D"$3" +VMLINUX=3D"$4" =20 is_enabled() { grep -q "^$1=3Dy" include/config/auto.conf @@ -278,7 +279,7 @@ fi =20 strip_debug=3D =20 -vmlinux_link vmlinux +vmlinux_link "${VMLINUX}" =20 # 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 =20 -mksysmap vmlinux System.map +mksysmap "${VMLINUX}" System.map =20 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 =20 # For fixdep -echo "vmlinux: $0" > .vmlinux.d +echo "${VMLINUX}: $0" > ".${VMLINUX}.d" --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Apr 10 06:22:25 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22D3D24EF6E for ; Mon, 24 Feb 2025 13:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403318; cv=none; b=qeNtOR+Pl02cP0KHjBDXCJaWGYkn3X06RFUjqekD4+5gTMYDG8wvw4jUfJhFAO9U0csBjxHMEN/YUYIjAr58ijoHVjU0knsPSbAy1UQUq8AjLBbSccZBaLdS2Zae110rFRhJ4Al+lLXoi9C8tywZJW+vqdnY4q+lOvl6DO0CNKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403318; c=relaxed/simple; bh=4JX+l3Lgbl+ZEiHLxUH/SYwEcP5mDlrM6p749Og3ZPk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dope1tBRUzxZz4kNnJYawY7qXTpAvzNmfJFip90o9ghdlfNQzHV9m7zgdaDx61wrjG2SMctH3UWeq+l+vW2NCqiIAmWUMFYh3+rzD35y+yAqF7xhfse7RVwjzfdV5+9bN8x3C0ceWtIuy2lj2iMBbCgAKMUG3So2Ve5OUnom4kE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EkhPRMmM; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EkhPRMmM" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-38f27acb979so4443305f8f.0 for ; Mon, 24 Feb 2025 05:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740403314; x=1741008114; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PgCkMehe7p3mehBNoMC8WFS/X7xwPD6PvbsrOWzFSqw=; b=EkhPRMmMsv2b8KIlYCEMfe3BnsX7f6FEXFUIkivxxq8ZWpiYW5nF5o4A1PMy3/WWzY IrCjH9Iw7yRVh+mgpvHlv/TgK5mTq1KP5bG7HWfMqUHQ/tC9IuhwdgYa0C/Z3ZYmAzhm zWhHNUvqNBuqZPJuGAilmQbI04Hotw1yBquiw+BnU4JogsuN/i/IEaEqJGviNoQxygm4 7WrnLdf4zS4rQK9/iEQvpPUlof67imQeSuYDg2/wu+pxzH/UmQki4t79I32qSOuvuknW HfbXh2qmKxUoCG4sgp+WeDr1njBeekHMMeApwpkp6X/phK3MpanSWtZmbEGHG/+/uxYi TZ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740403314; x=1741008114; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PgCkMehe7p3mehBNoMC8WFS/X7xwPD6PvbsrOWzFSqw=; b=wJmAtnL3JUqtn6xyxhA1P9LFPlCnl1RCpid+xkWIR4kKb+Dt5qS0cBqh6tTncegXz2 xOl0mT2xB7gDh6/cv6pSVY7O/Q6YPf/CHHek/tNITNB6gWCzo0W7q73CgEEqoGxHxZXy lPuCd8+GOIfP82EtIceFn01pywIrsCCW6km66O05S9qrnR+ecFA4vKdAmpWwl9fl1jKg UormimdTYXWjOnjN1MkKyKMZjBEizHCtgzHpy8EUh43hClYmnau+LwoLVxs6z9KdfI3c 2mpwmuqW4ZD31HvjNtHdgVmHUdbj6eX23Kbd2otQMaIw7fxJRSeRuiuVu/b7jrxjhK5n Ibgg== X-Gm-Message-State: AOJu0Yz5whyd1aCHJNrfzRzUad7rU8cbI1JJIExfiznEuReRrtic3oXb wsl4l7HfwxAy2PSRx+kNOg/GEq/k/OX9iXeKnI1xvYFe79cy50+QDe93CClPo9yRm1HNTATRtcw lNepjbVDUmOZbxQ0UZLFvM285Eb8SlkVRZahF5BrvjBnGVmy6dFZ9QZvvJF4Q967BC7Q/zcN5uM 0VE+oZTCQmzGp1CQvESG0XJXfnNI+TQg== X-Google-Smtp-Source: AGHT+IEyH2XmBvCzg2ijOwcjrIaoCy2e3N1FgVWpa9pBlwZWSeWw3cgu90bvQVoFAh+RzYhSFVTp0joX X-Received: from wmbep9.prod.google.com ([2002:a05:600c:8409:b0:439:65f0:b039]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:154a:b0:38f:50fd:55a8 with SMTP id ffacd0b85a97d-38f70783eeamr9304935f8f.6.1740403314458; Mon, 24 Feb 2025 05:21:54 -0800 (PST) Date: Mon, 24 Feb 2025 14:21:35 +0100 In-Reply-To: <20250224132132.1765115-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250224132132.1765115-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5903; i=ardb@kernel.org; h=from:subject; bh=l0XPdsqmrGbazu6TBBLLKaLD6j8WwrwleHZjQt9SLHk=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIX1PUcLlhUx3xDe9fZG2eUvuX8l1N7u/t61Zu09hbvnm5 VkJE6bM7ihlYRDjYJAVU2QRmP333c7TE6VqnWfJwsxhZQIZwsDFKQATEd3OyLBD/LmTf+jMnyLa wnnnIkwtXQ9dPf8+9m3Mn5nJX5ZPWx/N8L/006XoyoLw1k/r1p669uDYOd9KFY5fBTtbvYLnrdq kz8AEAA== X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250224132132.1765115-8-ardb+git@google.com> Subject: [RFC PATCH 2/4] Kbuild: Introduce Kconfig symbol for linking vmlinux with relocations From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Some architectures build vmlinux with static relocations preserved, but strip them again from the final vmlinux image. Arch specific tools consume these static relocations in order to construct relocation tables for KASLR. The fact that vmlinux is created, consumed and subsequently updated goes against the typical, declarative paradigm used by Make, which is based on rules and dependencies. So as a first step towards cleaning this up, introduce a Kconfig symbol to declare that the arch wants to consume the static relocations emitted into vmlinux. This will be wired up further in subsequent patches. Signed-off-by: Ard Biesheuvel --- Makefile | 4 ++++ arch/Kconfig | 7 +++++++ arch/mips/Kconfig | 1 + arch/mips/Makefile | 4 ---- arch/riscv/Kconfig | 1 + arch/riscv/Makefile | 2 +- arch/s390/Kconfig | 1 + arch/s390/Makefile | 2 +- arch/x86/Kconfig | 1 + arch/x86/Makefile | 6 ------ 10 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 30dab4c8b012..a3302dce56de 100644 --- a/Makefile +++ b/Makefile @@ -1119,6 +1119,10 @@ ifdef CONFIG_LD_ORPHAN_WARN LDFLAGS_vmlinux +=3D --orphan-handling=3D$(CONFIG_LD_ORPHAN_WARN_LEVEL) endif =20 +ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),) +LDFLAGS_vmlinux +=3D --emit-relocs --discard-none +endif + # Align the bit size of userspace programs with the kernel KBUILD_USERCFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) KBUILD_USERLDFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) diff --git a/arch/Kconfig b/arch/Kconfig index b8a4ff365582..101a13fcde8e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1695,6 +1695,13 @@ config ARCH_HAS_KERNEL_FPU_SUPPORT Architectures that select this option can run floating-point code in the kernel, as described in Documentation/core-api/floating-point.rst. =20 +config ARCH_VMLINUX_NEEDS_RELOCS + bool + help + Whether the architecture needs vmlinux to be built with static + relocations preserved. This is used by some architectures to + construct bespoke relocation tables for KASLR. + source "kernel/gcov/Kconfig" =20 source "scripts/gcc-plugins/Kconfig" diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 1924f2d83932..5aedbd7afadb 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -2617,6 +2617,7 @@ config RELOCATABLE CPU_MIPS32_R6 || CPU_MIPS64_R6 || \ CPU_P5600 || CAVIUM_OCTEON_SOC || \ CPU_LOONGSON64 + select ARCH_VMLINUX_NEEDS_RELOCS help This builds a kernel image that retains relocation information so it can be loaded someplace besides the default 1MB. diff --git a/arch/mips/Makefile b/arch/mips/Makefile index be8cb44a89fd..d9057e29bc62 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -100,10 +100,6 @@ LDFLAGS_vmlinux +=3D -G 0 -static -n -nostdlib KBUILD_AFLAGS_MODULE +=3D -mlong-calls KBUILD_CFLAGS_MODULE +=3D -mlong-calls =20 -ifeq ($(CONFIG_RELOCATABLE),y) -LDFLAGS_vmlinux +=3D --emit-relocs -endif - cflags-y +=3D -ffreestanding =20 cflags-$(CONFIG_CPU_BIG_ENDIAN) +=3D -EB diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7612c52e9b1e..6f5800114416 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -1077,6 +1077,7 @@ config RELOCATABLE bool "Build a relocatable kernel" depends on MMU && 64BIT && !XIP_KERNEL select MODULE_SECTIONS if MODULES + select ARCH_VMLINUX_NEEDS_RELOCS help This builds a kernel as a Position Independent Executable (PIE), which retains all relocation metadata required to relocate the diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 13fbc0f94238..6ef0d10e0c50 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -8,7 +8,7 @@ =20 LDFLAGS_vmlinux :=3D -z norelro ifeq ($(CONFIG_RELOCATABLE),y) - LDFLAGS_vmlinux +=3D -shared -Bsymbolic -z notext --emit-relocs + LDFLAGS_vmlinux +=3D -shared -Bsymbolic -z notext KBUILD_CFLAGS +=3D -fPIE endif ifeq ($(CONFIG_DYNAMIC_FTRACE),y) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 9c9ec08d78c7..ea67b7317138 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -630,6 +630,7 @@ endchoice =20 config RELOCATABLE def_bool y + select ARCH_VMLINUX_NEEDS_RELOCS help This builds a kernel image that retains relocation information so it can be loaded at an arbitrary address. diff --git a/arch/s390/Makefile b/arch/s390/Makefile index 5fae311203c2..d5f4be440879 100644 --- a/arch/s390/Makefile +++ b/arch/s390/Makefile @@ -15,7 +15,7 @@ KBUILD_CFLAGS_MODULE +=3D -fPIC KBUILD_AFLAGS +=3D -m64 KBUILD_CFLAGS +=3D -m64 KBUILD_CFLAGS +=3D -fPIC -LDFLAGS_vmlinux :=3D -no-pie --emit-relocs --discard-none +LDFLAGS_vmlinux :=3D -no-pie extra_tools :=3D relocs aflags_dwarf :=3D -Wa,-gdwarf-2 KBUILD_AFLAGS_DECOMPRESSOR :=3D $(CLANG_FLAGS) -m64 -D__ASSEMBLY__ diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index be2c311f5118..2005d80ff8d1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2199,6 +2199,7 @@ config RANDOMIZE_BASE config X86_NEED_RELOCS def_bool y depends on RANDOMIZE_BASE || (X86_32 && RELOCATABLE) + select ARCH_VMLINUX_NEEDS_RELOCS =20 config PHYSICAL_ALIGN hex "Alignment value to which kernel should be aligned" diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5b773b34768d..f65ed6dcd6fb 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -251,12 +251,6 @@ endif =20 KBUILD_LDFLAGS +=3D -m elf_$(UTS_MACHINE) =20 -ifdef CONFIG_X86_NEED_RELOCS -LDFLAGS_vmlinux :=3D --emit-relocs --discard-none -else -LDFLAGS_vmlinux :=3D -endif - # # The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=3D0x200= 000 to # the linker to force 2MB page size regardless of the default page size us= ed --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Apr 10 06:22:25 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47A0E24EF6F for ; Mon, 24 Feb 2025 13:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403320; cv=none; b=cOE6wjUQFex1uROZq3oLreR4h3HacS/j1aJHVbkW27QXcLR6BzExmu4SvwrFsRDEvK61DqHNN0FQgaxvAoAbyn5PXPVw7fOyPIjB2AnPMMhhtldPv45ySkXjT32YL00Rq0GTq4AHNBGb16yNbdL5Zgj4O0sz/Buogv4E23zi3KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403320; c=relaxed/simple; bh=sYx0U6dKdy9Z8hm6YI8HSfPtgU8dm5FNWnUJKigRqyw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jCcyuNRjF74TQdV4xWRlx/Gpyz7jejSSyFiUf2F4vXUVRTbeFhB4LqEy4sd1YVRqpBhsD1vN3VumoyISXcjuEEWK4Z155vkBv1/yQKtybDOZERISx7bkdO2J9BkRDVGFRQl3QXors31CrG8GkKYh/jfQ9LTbng2gOkWSvBqqaZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oTYW7Pxv; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oTYW7Pxv" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4399c5ba9e4so24300525e9.3 for ; Mon, 24 Feb 2025 05:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740403316; x=1741008116; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K3Lxf+Mt6Upf1dwmmRpB6u+V8v32vkZJiilK04eXPBU=; b=oTYW7PxvlaUGjXgY+cAhrKpDL0OwwGpfO3ILK0SQvAShIOSAjG/4Ee+ZkEN06vymsp etSlHJtgQhl3ER8GGXSPefxWdKG8T+pY1vNgb5WOhHyMSJ3ypHAz1bdUWxCK/9JU8BaV nF2dIq5Pt+Y0VnFpNER6VvI66SDBXW0eCdik24JAQhuDCw/TDDy0QrNsHjMWwN2eYJLj 5NltNf1gMleviPNtwFp/5AYUUeiC1x+OqOvFOCmqHp01pw5xZCXUrSD88S5SDpji4vfz iOjRmtXQshEfMf5KEj3uyTFqJJTgyrsR6eS1IdCHK5H11iQKZdIRXVh2+wUjCgpJmVDk f5Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740403316; x=1741008116; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K3Lxf+Mt6Upf1dwmmRpB6u+V8v32vkZJiilK04eXPBU=; b=Suy2AwKhV6LOs5xkC34fX3hDVJvNffNC26UWzMg5p178vY0w9cTMqmOocyKKwC3vgL rwKpH4IiO4BAxBnSrhfY//ZC61dOIFIYglZMtxwv8ID5oSUTgm1XYNEQaoU3xkoFVjoF 8TKtVFEmPHU+SrqURmLn370F0Z0c5FFS63qkwDtv47I0jSI+eLFl8EB2IyB6iucjCzHP KfXLW1MO3QxSIAPVIJ2IxtLoDbXku63V+U0hFFKDomzgmiE1Npxs9TKydK3gLnYm/Kra kjYIT1dMBjjL4Bq4i/IIC7TY2svRKOxLZYtbGNz+ued5AcrqqaOtwV1Gbc/R7aIWXu24 AvEA== X-Gm-Message-State: AOJu0Ywt0Lct69mAzqkMQ5ocwnOCrbdLzp8CwjMsvc1h4Wpx5q/CVL9N PL6yAUIqi83LjpLnA5zwwBDaq7J9WPVPPrYgVU4fWhFdP3unL/a68KkSJP5MjHoFafrnCpDvr2l IbyNzTpByX0iRxFcDzInAHgMQdzDlD9smpX7rc6IiZhhCZg92pSaBXcFtrEeMSSLSSUwnoO1wIK n6HBJG9N1hGDXxWzd7vyXdXLIGFXIe1Q== X-Google-Smtp-Source: AGHT+IG33+Xh8ssyQ1nJslAs6tRKw3YdmrlDrYBBqDT59wRm3YzOuPRvynP8l8ixy2gY9jLphYyZImsw X-Received: from wmbek12.prod.google.com ([2002:a05:600c:3ecc:b0:439:93e2:dc87]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1e10:b0:439:88bb:d035 with SMTP id 5b1f17b1804b1-439aecf3404mr110519385e9.5.1740403316831; Mon, 24 Feb 2025 05:21:56 -0800 (PST) Date: Mon, 24 Feb 2025 14:21:36 +0100 In-Reply-To: <20250224132132.1765115-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250224132132.1765115-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7868; i=ardb@kernel.org; h=from:subject; bh=OqJ5393/FS9cobJ3jWOwWHVsfGfjPgQpup4iA5mMahA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIX1PUaLz7nZuy00PP2hdf+nYz3I/Zo1CMp+HhrLvgX09t heeR4V3lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIm4tTL8D5XPjHI0Cpp9+sXs aQ1tn9z/mmarrKvKenq2c8PV4OX7FjIy/OMW9J0lr7LV5WRYo3bP2bxf9w/dj1D+y3h7rW1h88I FnAA= X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250224132132.1765115-9-ardb+git@google.com> Subject: [RFC PATCH 3/4] Kbuild: Create intermediate vmlinux build with relocations preserved From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The imperative paradigm used to build vmlinux, extract some info from it or perform some checks on it, and subsequently modify it again goes against the declarative paradigm that is usually employed for defining make rules. In particular, the Makefile.postlink files that consume their input via an output rule result in some dodgy logic in the decompressor makefiles for RISC-V and x86, given that the vmlinux.relocs input file needed to generate the arch-specific relocation tables may not exist or be out of date, but cannot be constructed using the ordinary Make dependency based rules, because the info needs to be extracted while vmlinux is in its ephemeral, non-stripped form. So instead, for architectures that require the static relocations that are emitted into vmlinux when passing --emit-relocs to the linker, and are subsequently stripped out again, introduce an intermediate vmlinux target called vmlinux.unstripped, and organize the reset of the build logic accordingly: - vmlinux.unstripped is created only once, and not updated again - build rules under arch/*/boot can depend on vmlinux.unstripped without running the risk of the data disappearing or being out of date - the final vmlinux generated by the build is not bloated with static relocations that are never needed again after the build completes. Signed-off-by: Ard Biesheuvel --- arch/mips/Makefile.postlink | 2 +- arch/riscv/Makefile.postlink | 11 +-------- arch/riscv/boot/Makefile | 5 +--- arch/s390/Makefile.postlink | 4 +--- arch/x86/Makefile.postlink | 8 +++---- scripts/Makefile.lib | 2 +- scripts/Makefile.vmlinux | 25 ++++++++++++++------ 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/arch/mips/Makefile.postlink b/arch/mips/Makefile.postlink index 6cfdc149d3bc..ea0add7d56b2 100644 --- a/arch/mips/Makefile.postlink +++ b/arch/mips/Makefile.postlink @@ -22,7 +22,7 @@ quiet_cmd_relocs =3D RELOCS $@ =20 # `@true` prevents complaint when there is nothing to be done =20 -vmlinux: FORCE +vmlinux vmlinux.unstripped: FORCE @true ifeq ($(CONFIG_CPU_LOONGSON3_WORKAROUNDS),y) $(call if_changed,ls3_llsc) diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink index 6b0580949b6a..0e4cf8ad2f14 100644 --- a/arch/riscv/Makefile.postlink +++ b/arch/riscv/Makefile.postlink @@ -10,26 +10,17 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib =20 quiet_cmd_relocs_check =3D CHKREL $@ cmd_relocs_check =3D \ $(CONFIG_SHELL) $(srctree)/arch/riscv/tools/relocs_check.sh "$(OBJDUMP)" = "$(NM)" "$@" =20 -ifdef CONFIG_RELOCATABLE -quiet_cmd_cp_vmlinux_relocs =3D CPREL vmlinux.relocs -cmd_cp_vmlinux_relocs =3D cp vmlinux vmlinux.relocs - -endif - # `@true` prevents complaint when there is nothing to be done =20 -vmlinux: FORCE +vmlinux vmlinux.unstripped: FORCE @true ifdef CONFIG_RELOCATABLE $(call if_changed,relocs_check) - $(call if_changed,cp_vmlinux_relocs) - $(call if_changed,strip_relocs) endif =20 clean: diff --git a/arch/riscv/boot/Makefile b/arch/riscv/boot/Makefile index b25d524ce5eb..bfc3d0b75b9b 100644 --- a/arch/riscv/boot/Makefile +++ b/arch/riscv/boot/Makefile @@ -32,10 +32,7 @@ $(obj)/xipImage: vmlinux FORCE endif =20 ifdef CONFIG_RELOCATABLE -vmlinux.relocs: vmlinux - @ (! [ -f vmlinux.relocs ] && echo "vmlinux.relocs can't be found, please= remove vmlinux and try again") || true - -$(obj)/Image: vmlinux.relocs FORCE +$(obj)/Image: vmlinux.unstripped FORCE else $(obj)/Image: vmlinux FORCE endif diff --git a/arch/s390/Makefile.postlink b/arch/s390/Makefile.postlink index 1ae5478cd6ac..c2b737500a91 100644 --- a/arch/s390/Makefile.postlink +++ b/arch/s390/Makefile.postlink @@ -11,7 +11,6 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib =20 CMD_RELOCS=3Darch/s390/tools/relocs OUT_RELOCS =3D arch/s390/boot @@ -20,9 +19,8 @@ quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/relocs.S mkdir -p $(OUT_RELOCS); \ $(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S =20 -vmlinux: FORCE +vmlinux.unstripped: FORCE $(call cmd,relocs) - $(call cmd,strip_relocs) =20 clean: @rm -f $(OUT_RELOCS)/relocs.S diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink index 8b8a68162c94..445fce66630f 100644 --- a/arch/x86/Makefile.postlink +++ b/arch/x86/Makefile.postlink @@ -11,23 +11,21 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib =20 CMD_RELOCS =3D arch/x86/tools/relocs OUT_RELOCS =3D arch/x86/boot/compressed -quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/$@.relocs +quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/vmlinux.relocs cmd_relocs =3D \ mkdir -p $(OUT_RELOCS); \ - $(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \ + $(CMD_RELOCS) $@ > $(OUT_RELOCS)/vmlinux.relocs; \ $(CMD_RELOCS) --abs-relocs $@ =20 # `@true` prevents complaint when there is nothing to be done =20 -vmlinux: FORCE +vmlinux vmlinux.unstripped: FORCE @true ifeq ($(CONFIG_X86_NEED_RELOCS),y) $(call cmd,relocs) - $(call cmd,strip_relocs) endif =20 clean: diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index cad20f0e66ee..7a023f17a21d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -377,7 +377,7 @@ quiet_cmd_objcopy =3D OBJCOPY $@ cmd_objcopy =3D $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ =20 quiet_cmd_strip_relocs =3D RSTRIP $@ -cmd_strip_relocs =3D $(OBJCOPY) --remove-section=3D'.rel*' $@ +cmd_strip_relocs =3D $(OBJCOPY) --remove-section=3D'.rel*' $< $@ =20 # Gzip # ------------------------------------------------------------------------= --- diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 3523ce3ce3dc..1e3ea8e4b4b0 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -9,6 +9,17 @@ include $(srctree)/scripts/Makefile.lib =20 targets :=3D =20 +ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS +vmlinux-final :=3D vmlinux.unstripped + +vmlinux: $(vmlinux-final) FORCE + $(call if_changed,strip_relocs) + +targets +=3D vmlinux +else +vmlinux-final :=3D vmlinux +endif + %.o: %.c FORCE $(call if_changed_rule,cc_o_c) =20 @@ -47,7 +58,7 @@ targets +=3D .builtin-dtbs-list =20 ifdef CONFIG_GENERIC_BUILTIN_DTB targets +=3D .builtin-dtbs.S .builtin-dtbs.o -vmlinux: .builtin-dtbs.o +$(vmlinux-final): .builtin-dtbs.o endif =20 # vmlinux @@ -55,11 +66,11 @@ endif =20 ifdef CONFIG_MODULES targets +=3D .vmlinux.export.o -vmlinux: .vmlinux.export.o +$(vmlinux-final): .vmlinux.export.o endif =20 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX -vmlinux: arch/$(SRCARCH)/tools/vmlinux.arch.o +$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o =20 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE $(Q)$(MAKE) $(build)=3Darch/$(SRCARCH)/tools $@ @@ -72,11 +83,11 @@ cmd_link_vmlinux =3D \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) =20 -targets +=3D vmlinux -vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +targets +=3D $(vmlinux-final) +$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +$(call if_changed_dep,link_vmlinux) ifdef CONFIG_DEBUG_INFO_BTF -vmlinux: $(RESOLVE_BTFIDS) +$(vmlinux-final): $(RESOLVE_BTFIDS) endif =20 # module.builtin.ranges @@ -92,7 +103,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_buil= tin_ranges.awk \ modules.builtin vmlinux.map vmlinux.o.map FORCE $(call if_changed,modules_builtin_ranges) =20 -vmlinux.map: vmlinux +vmlinux.map: $(vmlinux-final) @: =20 endif --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Apr 10 06:22:25 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B37D724EF96 for ; Mon, 24 Feb 2025 13:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403322; cv=none; b=uUynrzM20lkCNs4DsUJ9b41tlUOhur50pJ7AmzNGc204clM4DQ4ciT29srGpP6ks8AdtoXLDAZUBKRnNVIvyZ6bMgEDN6EJ9zoE4UMuzbNj3XrrHh6tagJJtGnsdB3YWrACk88eByaEKSyfiDs3Oux0ELT/LiMF3slIdeuR2BpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403322; c=relaxed/simple; bh=FzJmDucmnQefwM4+rIcbAg9V3khuaZlVJrpghKSzANk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dp/pWrqB07nlBmMzrMzYPGfwmfs3hqJByUagbwTV3Rfjlg/MyPVxmKvzMAbsiPxkeweOOVFRoY7qFyKNsn4oY+K8ZIrLe+C0Rj377t9heSFLU2G0+mihmQpsARkR6W2Fr4zp9H5LA8aQkYYYwaArr2O3D0ApQGDpsf8K+rh8Oa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q80JJEiF; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q80JJEiF" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4399c5baac3so31166095e9.2 for ; Mon, 24 Feb 2025 05:22:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740403319; x=1741008119; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0JdvJJa3M4LYnibjLYKa/KT7qCNB3WnDnqZX3OVSW+o=; b=Q80JJEiFg11HKPbJESV42lgXqH6Jr9qfbDq8Yv3KTmY0DNeodBtQcPvW03VeNlTCPF aJDqgTVbDEZDNOLW0MGd4JDRh8uoGQQWL9fZ4zL7ycYFdErC7TMIrcyNAFjnWrILSRRo 9H9KIrC3lib4wDa7HOWg5KeA3sla+gZmKPprB6346zdaauUTIZhh1kR/4xV2dH43Q1Fp en/8f9jHBvJTQkIXyj8+LFHSYhKipAhGCk5gV+6x5Uq06nouldjHmii8ie3iJmJc41/p QxvILN12yJhykJb48MjkUlabiojLRmDdQtt5T/qGjH3QdNeV9pRkltyY0zdTHltEoRAG p1kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740403319; x=1741008119; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0JdvJJa3M4LYnibjLYKa/KT7qCNB3WnDnqZX3OVSW+o=; b=tqRVPGdndVzpzJX1yvAEwm1y2GU1q5s9tw6w1JxuJWB5V+HzMzcIHhYB21YJclbvuh Es0nvdD8YdebT2+lxOh8wq7lZ1wr6HDcE46J7v7UbomRYWz5aw3BMTnajdO4+MlbZqDr jG6996oDsbWU5hMps1Vv2+bsb9VAEW0pSTZTqsbEuHNGb4cLlbXX2oCGfMR4MZamCbnd sKejRwc1+6Xq0ZM3PDII3dKF4WC/EfZTAYG7mSd2vhXscnM2xr5PUFkP+ngXYje4kRhV qBKLDgfm6AMcDqaT+9RByquBHvrayVPVUa4AiQ7Jp7xnMB1/nrG3IWz4jIiFc3Yp20KJ Uftg== X-Gm-Message-State: AOJu0YxQUuMlclR58/4Zg29LfCMuXpTpwBXI4gSLSRTrywU248otB9+9 n6n2O/bO/eB++4E3WbVa4eKhZCFz5IrhwE4jlaZk10QTLt+1GHmeZkWr6+UAcV4NKSOj4As1/Ai eGN42MjOWzb5ZdwFlcbqU9K7eOMT/ZZk/pO6+2svkqBacX90gCcpC++QeWUWh07Zo8V4COuLdzd oE5ggZi5vVlLIC5yHXVjKjg4771f0wMg== X-Google-Smtp-Source: AGHT+IH8EsSz7YpGtLB5T+cKqeQzM1bWhm0j04NiPLFE1u6JFMsI+orP8qOpxbzS3asdhrsksTiCSV/J X-Received: from wmqa19.prod.google.com ([2002:a05:600c:3493:b0:439:894e:1bf]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e8d:b0:439:643a:c8d5 with SMTP id 5b1f17b1804b1-439ae189b90mr121285395e9.0.1740403319046; Mon, 24 Feb 2025 05:21:59 -0800 (PST) Date: Mon, 24 Feb 2025 14:21:37 +0100 In-Reply-To: <20250224132132.1765115-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250224132132.1765115-6-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2834; i=ardb@kernel.org; h=from:subject; bh=jhCwY9ZD49KKgO6u3ta5BOC2uEjg61kStk0V3/YyhQk=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIX1PUVLDoxt7Frb6fLsixrbszUm9+9nHSl04tL6ynn+Sk ta+qq2ho5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzkMC8jw+sohh2ebQ+TRdgr Y3qOrDUPUTHrXuLA59DSKGR34M0bIUaGPfn3ZtyYrX3/Qu5e/obZj1xKCx4fDVnqILXBVSjb+8o UJgA= X-Mailer: git-send-email 2.48.1.601.g30ceb7b040-goog Message-ID: <20250224132132.1765115-10-ardb+git@google.com> Subject: [RFC PATCH 4/4] x86: Get rid of Makefile.postlink From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Instead of generating the vmlinux.relocs file (needed by the decompressor build to construct the KASLR relocation tables) as a vmlinux postlink step, which is dubious because it depends on data that is stripped from vmlinux before the build completes, generate it from vmlinux.unstripped, which has been introduced specifically for this purpose. This ensures that each artifact is rebuilt as needed, rather than as a side effect of another build rule. This effectively reverts commit 9d9173e9ceb6 ("x86/build: Avoid relocation information in final vmlinux") Signed-off-by: Ard Biesheuvel --- arch/x86/Makefile.postlink | 38 -------------------- arch/x86/boot/compressed/Makefile | 8 +++-- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink deleted file mode 100644 index 445fce66630f..000000000000 --- a/arch/x86/Makefile.postlink +++ /dev/null @@ -1,38 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D -# Post-link x86 pass -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D -# -# 1. Separate relocations from vmlinux into vmlinux.relocs. -# 2. Strip relocations from vmlinux. - -PHONY :=3D __archpost -__archpost: - --include include/config/auto.conf -include $(srctree)/scripts/Kbuild.include - -CMD_RELOCS =3D arch/x86/tools/relocs -OUT_RELOCS =3D arch/x86/boot/compressed -quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/vmlinux.relocs - cmd_relocs =3D \ - mkdir -p $(OUT_RELOCS); \ - $(CMD_RELOCS) $@ > $(OUT_RELOCS)/vmlinux.relocs; \ - $(CMD_RELOCS) --abs-relocs $@ - -# `@true` prevents complaint when there is nothing to be done - -vmlinux vmlinux.unstripped: FORCE - @true -ifeq ($(CONFIG_X86_NEED_RELOCS),y) - $(call cmd,relocs) -endif - -clean: - @rm -f $(OUT_RELOCS)/vmlinux.relocs - -PHONY +=3D FORCE clean - -FORCE: - -.PHONY: $(PHONY) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index 606c74f27459..8b7da3fc3f03 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -117,9 +117,11 @@ $(obj)/vmlinux.bin: vmlinux FORCE =20 targets +=3D $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmli= nux.relocs =20 -# vmlinux.relocs is created by the vmlinux postlink step. -$(obj)/vmlinux.relocs: vmlinux - @true +CMD_RELOCS =3D arch/x86/tools/relocs +quiet_cmd_relocs =3D RELOCS $@ + cmd_relocs =3D $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< +$(obj)/vmlinux.relocs: vmlinux.unstripped FORCE + $(call if_changed,relocs) =20 vmlinux.bin.all-y :=3D $(obj)/vmlinux.bin vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) +=3D $(obj)/vmlinux.relocs --=20 2.48.1.601.g30ceb7b040-goog