From patchwork Tue Mar 11 11:06:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 14011509 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 5AF982528EB for ; Tue, 11 Mar 2025 11:06:32 +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=1741691194; cv=none; b=lGx5yKFU96iIL0O55e3SRRKgIluxdK0bT0ot3hk7r5z8MQgVyr8M2bohhtFFux5Cq+VOkF+IkX7sacjj28fXZi4kj8Ag2Y0qDJsaBvW+krdOo0KsC+mO9NMwA9Hdu2s8RyJvZSpfVGpiNbzHWjxutpJZbb6nmL0peFSvpPfTgjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741691194; c=relaxed/simple; bh=gVD0/fzhrleJz7qWjI+8Zc3sgv/qdPMRB6vrQfcnKH4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EnwcnVd/rJ1pQRGQYPeN6naSs3Vy5PjFRrP8/cQJScMQSITxre2CEqInzV33vUf7/puQk5CQZ7pfYVWjGVAjlPKTZYNtDRV1OxHW9o9hLZgIAgt/k3Rs8NLpFQ5NpRdI5v2kq++Wincd64DdWUIuc8n8/i+aokxn5DltPejAHg4= 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=TblQfrBQ; 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="TblQfrBQ" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3912fe32a30so2102308f8f.1 for ; Tue, 11 Mar 2025 04:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741691190; x=1742295990; 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=tV9KNmIji6xAM0Ucpo6ZsPi4ZsXCFqqr1ylqjFTDO+c=; b=TblQfrBQY1Hxe5fKIh+uSzzb6H4A66ym7YXwY0o+G80R3H4DZKUoWpV1xbBWosJF0c 4JRbolgBCM95CYUjTGBeTiAF/hjpdgJ61snW/iRfQ+ZeI+OJ31xgw9lTO6H25GKIb2AK lQ7Hvfs8p4qzvIg8kNaiRkZPqgiuQmCEKujP1TAMWhCjhgH2GDKpX3cj6vegtE8M6Gj+ K3knFkKaBIhowHtW7cSnb5JlaxFM4P63D7RmKcpt1HhPDAhnMWYDzk4GnFJSmIS/L9DG G+RsOEa0WMddJo+9BUH1tqEXvfIoQLhxkQWrKZIQSPMNzIiY1YivDRqArQZQgkpmKJeb f44Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741691190; x=1742295990; 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=tV9KNmIji6xAM0Ucpo6ZsPi4ZsXCFqqr1ylqjFTDO+c=; b=uVLwRoC8gMFmnl77tEHizIUkv90UnG5NnSARoppPpg7LRl48ALBnA9vaaAOVrokeVM X1m3cEPZTQmnmevXFJe/gLAOUccxsXdfHPhZfjoQ5rhwXDhZLVvUZMenKVs9lNlUZPJV c5AwKoNy4DyomChwDXKDVBKtPEJwx86emNWIwWAr0Wd50L/UHg8t2LCRnhGLz+tzw6Td HvuDdIO8FDKK07PTAhpjDpWPv5bdJ/Vcvrl8FYXH+GZmtiYSI42at0v9lrybthCw8Ew8 gyZ+lj1HfSF30E/GKIQIxg2HT7sw4Md0kLUr72JtMdjTng2Sd0j4C0igf4Mm/SCd+vyO VAzg== X-Gm-Message-State: AOJu0Yz50XRpJ2PAlja+YXSz4nKc5Qv+3R4/hrZlDtn5hN3fREOidL7m 7eBI6mtcvdnfZ+6Ioi+492kuK6BKwiU9cOdI9AF7Do4j6vxyAKohBO1JfiHYXE2ypXiNYA== X-Google-Smtp-Source: AGHT+IGx5sLNnKxVFCGhCCzaNKMvpj+hJ1CMgltFrMWRcriH1uhpFfBfRRlejgGSfIVVwI7xdZNOUNcl X-Received: from wrbgz25.prod.google.com ([2002:a05:6000:4819:b0:391:3213:f77f]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:64c5:0:b0:390:fdba:ac7 with SMTP id ffacd0b85a97d-3926c78f683mr4008136f8f.51.1741691190737; Tue, 11 Mar 2025 04:06:30 -0700 (PDT) Date: Tue, 11 Mar 2025 12:06:18 +0100 In-Reply-To: <20250311110616.148682-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250311110616.148682-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=2056; i=ardb@kernel.org; h=from:subject; bh=CGnv6V5I23eS/SExFYiNHZ+B0GmQlF8wLC6M1T8xHx4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2CpOb3sw3R948qlQYYiblGM+ulcO/2LdLm8N/Pz1PWn +974FtHKQuDGAeDrJgii8Dsv+92np4oVes8SxZmDisTyBAGLk4BmIiHMiPD08Mc70NvSuVs/VFZ vXSTUq/wq04HGf9emzihoqx3Kh6dDP8MWf5oHO+qXp/rxKExWX6Vl/O8H7qvp/UFL/hSs7NLrYE JAA== X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250311110616.148682-7-ardb+git@google.com> Subject: [PATCH v2 1/4] Kbuild/link-vmlinux.sh: Make output file name configurable From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar 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 := $(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" From patchwork Tue Mar 11 11:06:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 14011510 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 56B50253B6A for ; Tue, 11 Mar 2025 11:06:34 +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=1741691196; cv=none; b=f3WzIAcD0xmv4cAGe6Hl+ctxbdv7hOhdLPJzSTthG3GpnxJTjwjQcSmvw3mjW0byovAWDrz9qbsvS03oGJr8QrNumZDoZeFpJXe1/6ob0C5JKMMIyimhLlKOk2k2OTeV8VfZbBnrgEjXFd1chsxbayVz0yZNeNz05O3Ba5mKsXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741691196; c=relaxed/simple; bh=NSvLUGEJgrKoqVUvg8LwrQglJlxafOeNF7jb3TYBQww=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HnQqiYeukmlS9mG2lLgNHBUEwpS+ayaf+1c7jtoUx5AQXR3NroBqGQsq8Ht6g2D2DjrMEf8r0zQ44GahrLq/mCi3+x8xV/9QX2T8nGwSNFmHoqq51jR3cbxulQlQxbt+/uobcsEbEUm8UG2TK5HEqV9a1lDb7BOVF/HHugFBmaQ= 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=GAblWpas; 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="GAblWpas" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-391425471ddso1723702f8f.0 for ; Tue, 11 Mar 2025 04:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741691192; x=1742295992; 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=/Yf0bN3uKuHsi0gbwB2yWwKhMf1YwUtCAITC2D3AG+o=; b=GAblWpasHr/0+qvUJeHvvP37qu2yqiSbOUVNRxlhFdlubfb3PCn1N65zATRvWbuqPg I0ey+6gdN+W+IhtXJ56AJexcV61RyOYhP37sIn+36JR6udRuoUz5/T2NSJT9pxMffrIT LCLwRdbB8FuwP5ikxKLyJLCBpWI7i7ASN5l4wDbr7q/hVz/rmxQdXkETFFnEhsIOthkv pUZf/WR06A6RNkoxYW0oMABIyUHcCRLL/BjebgiQHPv5HUNkWQoXqhfAeGJM7Fbuz1Ee fl/C+PJz1jutzgUPzLQq4cEMHnf62v463eBgiX8OfDjVuZG2k4kCAoyrQ9mQbUScQ9bU GVFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741691192; x=1742295992; 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=/Yf0bN3uKuHsi0gbwB2yWwKhMf1YwUtCAITC2D3AG+o=; b=EQNJD3n2JnCCEORj8CeGhx3ZrSEk8JfiXVLjXTWDO3zYAOqiFHjkHXTwbC9SnIgZQv 2HUPdE0QJnxjB+3AF9z4tVLIdO9/iAmqnSp+zjXw7EdqZb+BpAPvul3v70EwFyVDiggf w8DQkVptr/FUdGr7TStsf/ruOpF3A2YC1exYeKeGXJBdGDxZtxtff8ErfRpoxljKjvSf gbJ0nWXMWlvZMA7j7ehiK1sKHiBWIdqvMlvWZfk8u8X6zpYVlFsMocZUQ40RB13F0VX8 Cf4eeMi89eZauvCgP3PwEEHpq6896T7HmW3mui+JD7LBxLNrpJKIv/EQHKY/HNr27j5j K/8A== X-Gm-Message-State: AOJu0YwDt6rzT8F5FcfN5lRmzgGKP5UnX7oYFPWcGIXFa4gP7WoQ+gBb IE35vH7+sAXKEyRxjxObxqGwQlo81vZM8oNvj6b86jool4FBukBLWtohJeXPkGXwgsWxtg== X-Google-Smtp-Source: AGHT+IH6q7l27zc7WjLkXADMZQsNPbgoWxbj8l31SeRAG5v7pCZB84Qs/sK/o+dml/OyzZBZUfJ8MxWb X-Received: from wmrn34.prod.google.com ([2002:a05:600c:5022:b0:43c:fe82:3a43]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b92:b0:43d:45a:8fc1 with SMTP id 5b1f17b1804b1-43d045a9163mr26861955e9.4.1741691192658; Tue, 11 Mar 2025 04:06:32 -0700 (PDT) Date: Tue, 11 Mar 2025 12:06:19 +0100 In-Reply-To: <20250311110616.148682-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250311110616.148682-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=5907; i=ardb@kernel.org; h=from:subject; bh=VQ+GQCTas1Zo3mtujHD75cbccTwWsmh8GGh8MvIAve8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2CpNZ/j5JMGZOffc6NUwzyk1R1Dxavs9xTbsA95cGNh xcOl/F2lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgInc2czI8KHt2K6wfXMYqm5+ Whi+ZGP6ahv+n3dXbJ3Tkrda2mtR3FFGhg1/W++bVjS8tXLN8kvOafNar+u1tfDOzuOziuuf6rI YcwIA X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250311110616.148682-8-ardb+git@google.com> Subject: [PATCH v2 2/4] Kbuild: Introduce Kconfig symbol for linking vmlinux with relocations From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar 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 += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) endif +ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),) +LDFLAGS_vmlinux += --emit-relocs --discard-none +endif + # Align the bit size of userspace programs with the kernel KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(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. +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" 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 += -G 0 -static -n -nostdlib KBUILD_AFLAGS_MODULE += -mlong-calls KBUILD_CFLAGS_MODULE += -mlong-calls -ifeq ($(CONFIG_RELOCATABLE),y) -LDFLAGS_vmlinux += --emit-relocs -endif - cflags-y += -ffreestanding cflags-$(CONFIG_CPU_BIG_ENDIAN) += -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 @@ LDFLAGS_vmlinux := -z norelro ifeq ($(CONFIG_RELOCATABLE),y) - LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs + LDFLAGS_vmlinux += -shared -Bsymbolic -z notext KBUILD_CFLAGS += -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 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 += -fPIC KBUILD_AFLAGS += -m64 KBUILD_CFLAGS += -m64 KBUILD_CFLAGS += -fPIC -LDFLAGS_vmlinux := -no-pie --emit-relocs --discard-none +LDFLAGS_vmlinux := -no-pie extra_tools := relocs aflags_dwarf := -Wa,-gdwarf-2 KBUILD_AFLAGS_DECOMPRESSOR := $(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 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 KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) -ifdef CONFIG_X86_NEED_RELOCS -LDFLAGS_vmlinux := --emit-relocs --discard-none -else -LDFLAGS_vmlinux := -endif - # # The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to # the linker to force 2MB page size regardless of the default page size used From patchwork Tue Mar 11 11:06:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 14011511 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 2FCAD254851 for ; Tue, 11 Mar 2025 11:06:36 +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=1741691198; cv=none; b=Bc+Ggg7tP3iRNxifNV8SF3mrl7FsjT+62F2mV5oh2VePpqlnhnzLRyl1b/8ZfGX7fgqfx34o7FMGzOes8KrZrDtAJHnlLxi4jVjSf+SfzJ47JCkFyIbYBM6sI/kRHdBoUs1weCq7C1cXCHWwqfnHCGKmdBcGEDKjJUvADhAE5Zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741691198; c=relaxed/simple; bh=fYVShNRhRRvjgjpqBNaT7nBmZtLTM8WQfXXA2LkV77I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AiWnDfkyiDNbXvxYvE8a9vF2obN62Hx2zl46LD/lsbe2KjL4h+oZkUfNh4iGPmhk08j9Y6HUbrv9KnkMkRRgnSR0IUQnXE0OapDVdkoYMOchoh10QXSvQa0tzTCNyk0szjJUQB0dTVPImZjwoBZ4wRvwtZGhODedColiaNBkt/8= 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=lWRYUF93; 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="lWRYUF93" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3913d8d7c3eso1634168f8f.0 for ; Tue, 11 Mar 2025 04:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741691195; x=1742295995; 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=i8MFH+i67GnmGnNC8lrUwJ/qqT7je+AVkRDqP4sbMvY=; b=lWRYUF93slmRjyr4U7nDU5ThrZHQ5OFtmzoS1XOKkbej0FSkzblI1Jstwpl9g/LCa5 dst5k+60irm5SOJ61/djlcLw6YAN7LTFowuoDgKtYKYZHpS4+EQAxxxqyHgEyJYWztFN KE2tbshFiQVQPBfnZRU48kQ5EULtmlPLkhjwghnSRCFQd247ub4qw3yq9YIOg+Zoswrx oZNCHqCFZX0M/nbIhBNw/K/UqZtPSPGPerFFxxYchDSG5cScExGTYn4HOILH6VaFBKnJ rlkgVVYs88hFR4r8ezQz2DtzcAOHGF/+CGkE/odCpgd/fWSk9YB7JnjR3i4CNBML5l1b 1W8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741691195; x=1742295995; 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=i8MFH+i67GnmGnNC8lrUwJ/qqT7je+AVkRDqP4sbMvY=; b=Zsxc77anDxijnV7tb3NrtGXEP3ePNEJSpB/BIKIlUml0BGaBFbN4KnH0b8RAblzNTT E9dwRk7aSYBjBvczQlYMX3M3qGgDzVpREfrXK8LvHjb1pQMi9fZeZIRF6DmlqHc1epoF yv5QO8o293IW6y+8wUNy/NNRQlVb7UxaYA63XMaV8cEk8xwt8iZp6bmdGDvArK7NugFW l6VXx3u9gRF+MAorIMaIlrHaF1X88GajyaddSozlzlLyhE63Kqm911+J+U2V19mGeo78 66dz+8M+1Pah9q686c+OBS5mbjvGyGdgioE0DPDwoVF+4n8xKWwW8Xx14tLzqmpy+ZP8 9cEw== X-Gm-Message-State: AOJu0Yz/6314f3sYQhQWMK77Nz38w2u2J04gnETBsaT6yVQfdGi21xo0 b9xUXhtvQiaE23aK0uCkt5DyNTg35hWBXFrkEG+v5X2+EIE+Vj/zH+Oo2rruMgCnqoRpUw== X-Google-Smtp-Source: AGHT+IGr4pBlREZRzI4udDWiMwtONQvCGuNBzOUGHy+3FRwj4HpKdXxCmicRA0i10u6oQ1mFMoPwhHqn X-Received: from wmsp32.prod.google.com ([2002:a05:600c:1da0:b0:43c:f3b7:f2d7]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:adf:8b1d:0:b0:391:1652:f0bf with SMTP id ffacd0b85a97d-39132d8dc66mr10651642f8f.33.1741691194886; Tue, 11 Mar 2025 04:06:34 -0700 (PDT) Date: Tue, 11 Mar 2025 12:06:20 +0100 In-Reply-To: <20250311110616.148682-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250311110616.148682-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=8886; i=ardb@kernel.org; h=from:subject; bh=mTEKuMK3k7KiZecHKGHf2bV38KclCiT+gr5VTPl7TVk=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2CpPaBm19Mnks4qR4/7ThpI7uZllzUyzOCr1e8uuv2Y gb/t5TujlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjARZnaGPxzz/pso3qw8am1c L2tmpfxklvTLFHNHXqe1jbuNt7z/z8fIsHvOuzeHzDl7BBf+C9R/fumAz4IwseuthqtWvtvKbKR dyQQA X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250311110616.148682-9-ardb+git@google.com> Subject: [PATCH v2 3/4] Kbuild: Create intermediate vmlinux build with relocations preserved From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar 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 --- .gitignore | 1 + Makefile | 2 +- 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 | 3 --- scripts/Makefile.vmlinux | 28 +++++++++++++++----- 9 files changed, 30 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 5937c74d3dc1..f2f63e47fb88 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,7 @@ modules.order /vmlinux.32 /vmlinux.map /vmlinux.symvers +/vmlinux.unstripped /vmlinux-gdb.py /vmlinuz /System.map diff --git a/Makefile b/Makefile index a3302dce56de..c07295a980a0 100644 --- a/Makefile +++ b/Makefile @@ -1560,7 +1560,7 @@ endif # CONFIG_MODULES # Directories & files removed with 'make clean' CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ - modules.builtin.ranges vmlinux.o.map \ + modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ compile_commands.json rust/test \ rust-project.json .vmlinux.objs .vmlinux.export.c \ .builtin-dtbs-list .builtin-dtb.S 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 = RELOCS $@ # `@true` prevents complaint when there is nothing to be done -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: -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib quiet_cmd_relocs_check = CHKREL $@ cmd_relocs_check = \ $(CONFIG_SHELL) $(srctree)/arch/riscv/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@" -ifdef CONFIG_RELOCATABLE -quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs -cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs - -endif - # `@true` prevents complaint when there is nothing to be done -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 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 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: -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib CMD_RELOCS=arch/s390/tools/relocs OUT_RELOCS = arch/s390/boot @@ -20,9 +19,8 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/relocs.S mkdir -p $(OUT_RELOCS); \ $(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S -vmlinux: FORCE +vmlinux.unstripped: FORCE $(call cmd,relocs) - $(call cmd,strip_relocs) 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: -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(srctree)/scripts/Makefile.lib CMD_RELOCS = arch/x86/tools/relocs OUT_RELOCS = arch/x86/boot/compressed -quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs +quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/vmlinux.relocs cmd_relocs = \ mkdir -p $(OUT_RELOCS); \ - $(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \ + $(CMD_RELOCS) $@ > $(OUT_RELOCS)/vmlinux.relocs; \ $(CMD_RELOCS) --abs-relocs $@ # `@true` prevents complaint when there is nothing to be done -vmlinux: FORCE +vmlinux vmlinux.unstripped: FORCE @true ifeq ($(CONFIG_X86_NEED_RELOCS),y) $(call cmd,relocs) - $(call cmd,strip_relocs) endif clean: diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index cad20f0e66ee..6abfefd1bd31 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -376,9 +376,6 @@ quiet_cmd_ar = AR $@ quiet_cmd_objcopy = OBJCOPY $@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ -quiet_cmd_strip_relocs = RSTRIP $@ -cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@ - # Gzip # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 3523ce3ce3dc..dd744551a896 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -9,6 +9,20 @@ include $(srctree)/scripts/Makefile.lib targets := +ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS +vmlinux-final := vmlinux.unstripped + +quiet_cmd_strip_relocs = RSTRIP $@ + cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $< $@ + +vmlinux: $(vmlinux-final) FORCE + $(call if_changed,strip_relocs) + +targets += vmlinux +else +vmlinux-final := vmlinux +endif + %.o: %.c FORCE $(call if_changed_rule,cc_o_c) @@ -47,7 +61,7 @@ targets += .builtin-dtbs-list ifdef CONFIG_GENERIC_BUILTIN_DTB targets += .builtin-dtbs.S .builtin-dtbs.o -vmlinux: .builtin-dtbs.o +$(vmlinux-final): .builtin-dtbs.o endif # vmlinux @@ -55,11 +69,11 @@ endif ifdef CONFIG_MODULES targets += .vmlinux.export.o -vmlinux: .vmlinux.export.o +$(vmlinux-final): .vmlinux.export.o endif ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX -vmlinux: arch/$(SRCARCH)/tools/vmlinux.arch.o +$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ @@ -72,11 +86,11 @@ cmd_link_vmlinux = \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) -targets += vmlinux -vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +targets += $(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 # module.builtin.ranges @@ -92,7 +106,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ modules.builtin vmlinux.map vmlinux.o.map FORCE $(call if_changed,modules_builtin_ranges) -vmlinux.map: vmlinux +vmlinux.map: $(vmlinux-final) @: endif From patchwork Tue Mar 11 11:06:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 14011512 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 5D74A2528E4 for ; Tue, 11 Mar 2025 11:06:38 +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=1741691200; cv=none; b=EkxKB/M8gz/GHMGll3V/X3+qaTxh/yChkZnp3ExsWbfUN0ckm1U3XIOQLt/vReJHpFTrUloCZBFkANxXuWlAbPQ8rrH4UCbddi6UWMaPxmJGyDNnZJmQ70zlvN5s3pTg1oC7/WvxZm24IxUSyu12SJSomuH6+TCrcsASkCekgw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741691200; c=relaxed/simple; bh=nuTXGI8ywBR/3DStlzvfiJ6kl4aJQpuqoliwSosW38g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K+kQg/vie4pWQjPPPkrSwwI7Jf2t/+qqdjNrEUWLZH68B4fXPKA8vrvFsC2kVlEogkUsTNBBFbxinkMe4BAwl3yG3AemX0SiiwSfTum0//+teZSGlEFy19BloWS1DnCp3MJDzkO/XTJRBvxKs1zEZSzeKIYCaF3zKSe06oSBI+I= 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=PlR7J/WN; 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="PlR7J/WN" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43bd8fd03a2so25801845e9.3 for ; Tue, 11 Mar 2025 04:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741691197; x=1742295997; 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=r0pOY4tofDembaukX9fn2OhaJHg8GDHRxWXDT4vsSWs=; b=PlR7J/WN5umb6RUjOSDAQBSprkPwCkxSHUbyzerHOAZf9BYZ6rbFBNcXsNLgQtRZO+ H9dE46trPmfF9JDAET+tJHJT452mwUmtneHWtqdD/v1G8PwXR8Aev8uRGp92om1FQ1hT DprL3Fy4Eb5eSG1BVhPuWRXtmHqzVGrumjhgtZx7lBh0TQlVNWYlH5LWO3R9KMSkf6di JKWp6KHiGpPp4yJasU6jGXs9ogGs8nhmqyLJLYy4H1iIOT5evbwERxqaLCxOvfZLp/ju Xw9iajkJpVoAAFsduPSEL50ZXLV5NwGy4dxjEL/hF3a1wkF83CK7PLHz0jrCSqIO33K2 by7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741691197; x=1742295997; 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=r0pOY4tofDembaukX9fn2OhaJHg8GDHRxWXDT4vsSWs=; b=PjVyUaCb3Ea1BjnyWc4yy5AYQVuUfpvOi9a8AdjuCXcsI55Ew+Bmjq0kfpVvhNQIu3 i5lewM9HkWA9MW/2W0BoAvBP60j285dC9Oor5az5izzK5hE1r2Epv2f0VikfsfNbqrBu lgmFAsKDUYw8YTDRFSB87fDgxbIsSPmaNB/HlcRo7qG2xYAt4LNu2PkUfhSmHXT95RKv SUaUhfGcfeQC8xEQyvQY+byfyZYcHUHZxXP3eU6MI/35mnF1sFhufcmD4/jFl98eaoyE DIHjh0QUHREqxt3QSgsmW75M2to+5fOAbeLs78KqnVnD9eSKlgNO1Z6vAURkUzxbHD/j dUig== X-Gm-Message-State: AOJu0Yyzcazf98Ny5ntWLw2QfN2BkvrGmLrW2gRluL26FHzKWjk49ipq 2I5KwHiNJLNfV5NnJkx72P5j+G/5lxdKnIu+1IwGn/rrnQGa/bKbDSas+dBwgaMtfs+0RQ== X-Google-Smtp-Source: AGHT+IGEhku/zIe1iRiual1cfIyrMt8hV8x/OqVBxxNoC4DFleOTRI8T74xBPdjh6IEwp0cNKkLMbwLi X-Received: from wmbg5.prod.google.com ([2002:a05:600c:a405:b0:43b:c967:2f53]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3545:b0:43b:c5a3:2e1a with SMTP id 5b1f17b1804b1-43c601cdb15mr136995565e9.2.1741691196808; Tue, 11 Mar 2025 04:06:36 -0700 (PDT) Date: Tue, 11 Mar 2025 12:06:21 +0100 In-Reply-To: <20250311110616.148682-6-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250311110616.148682-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=2841; i=ardb@kernel.org; h=from:subject; bh=B0+BjVhEqATZYwCtJhS5i7zD5aan/y8prf8aoEmbcyI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIf2CpM7pthSzu4aPvXpSPgev23Vu3YksQS/fCZVHG0VTQ szexq3qKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABP5Mofhn9JbttvH7X56cdzR mlCd7Xz88h23T2t33rvEMftuUoHRwq+MDMtWZDhuZt9YeMCW/Ubg7aPLrrmv0HwcyH4/qOzM7dq pB3kA X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250311110616.148682-10-ardb+git@google.com> Subject: [PATCH v2 4/4] x86: Get rid of Makefile.postlink From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Masahiro Yamada , Ingo Molnar 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 | 9 +++-- 2 files changed, 6 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 -# =========================================================================== -# Post-link x86 pass -# =========================================================================== -# -# 1. Separate relocations from vmlinux into vmlinux.relocs. -# 2. Strip relocations from vmlinux. - -PHONY := __archpost -__archpost: - --include include/config/auto.conf -include $(srctree)/scripts/Kbuild.include - -CMD_RELOCS = arch/x86/tools/relocs -OUT_RELOCS = arch/x86/boot/compressed -quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/vmlinux.relocs - cmd_relocs = \ - 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 += FORCE clean - -FORCE: - -.PHONY: $(PHONY) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 606c74f27459..5edee7a9786c 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -117,9 +117,12 @@ $(obj)/vmlinux.bin: vmlinux FORCE targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs -# vmlinux.relocs is created by the vmlinux postlink step. -$(obj)/vmlinux.relocs: vmlinux - @true +CMD_RELOCS = arch/x86/tools/relocs +quiet_cmd_relocs = RELOCS $@ + cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< + +$(obj)/vmlinux.relocs: vmlinux.unstripped FORCE + $(call if_changed,relocs) vmlinux.bin.all-y := $(obj)/vmlinux.bin vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs