From patchwork Mon Feb 24 13:21:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13988042 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 AFD9A248896 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=1740403315; cv=none; b=V61pbcu68ZCYbAOg/+1MvRK3AUMQs1hi1+ILYvexn8QBDCgOHe+6VILX8iJo0tKGv7W31lR9qN40JPdU+B27q7hEcC7S15q74QL7NMbIYHfgdHv/SgB9Un6rNlAotWl1JVXWaVuWZADmo4ZAeW7QRDbwggCC6kvIvHMgM6QN1H8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740403315; c=relaxed/simple; bh=dRq0U8z9TE+qNLNwYD7S40TkyqyC8cws+VNe0sBWZT4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ORB3lJTiBXuo0+Hg/wsi8K4d75jQvV9+piu2l4wdGX8eGCR3iKXXTGOVJnDaI0dhTbSYTYI57+SdqoXDml6DaQZTKNRqNZo8BadnGNmMX0EoPn17/Qvfs5J9UnK8ZQncVvNo9pBuSmbMmIW2Z/PdrDTIdSrRWtU2T/Hrmh9n4NI= 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-38f42f21f54so1686672f8f.1 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=ZRl8+8w47X6BD1n84tjW4eA1XacZxlRzcfDGZfX38cPVQF+kM+TolkIDWpuVljo2jA gDl1naeCKHUIr8Jot0Oocv8anof6OR6wAL0b1A5gmzQtHpY8w7qAs3Xmi+e+vj03d74a rpfO77XBWZOI6SRfISR2DR7pJnoR6G9mInvMR1TmekzL32DYLDxwvZrJpLU6m+wTcOPg n3pI1UIVHDWsJXvXJ6Dc3N1uhNtETjkcvPJlya8dJHUs7nNAoZsGn6hr2v47WIbz229H POaKFT1APCF2E8jWIHYRBFdcgIgScy7YK0gUPb5rklNUvKY9quSsDUptp6iti5O+R5n6 IojA== X-Forwarded-Encrypted: i=1; AJvYcCXtYrx7AgNpmXCpWPiCnJFyHznLgwE+8lkmk0DK4uyypdYf7PHuhSpi1dHjepttrsOz4zjxwZ2Ieov6WgY=@vger.kernel.org X-Gm-Message-State: AOJu0YzXl2BuDH6HKMBwsGnPy/sgvR03h4ptwRi6C3dAiDUWXIA05uhr +//Mg7Fo6dmg1ICl4JgJdAYXq5s7tejP14cO0EkXZUoI27fsc+z+EgHOVKiV2m0lnnGJZQ== 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-kbuild@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 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 Mon Feb 24 13:21:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13988043 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 22DA824EF6F 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-38f62a0ec3fso3374652f8f.2 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=gOTLru2RT78Vs62HYpZYD2avhkHdYTgkAkoWABX+wT0rQCbp59k2crkylenm0AEOOY LkVorBEHe1iH35YMtmOjldbgmfz6oiW702B5mZPWTpOAB9AotT5lzu1HjecF4LmevaWZ Hph0/uPhSPW1lnyTwywKu6AqS7psAHEcMbIc0a2cmXUN/+L6CsTjpyvp74ESXHHtyt9F ZhjOpvVPB/CCve2u4UIbgs+Ab3l1KZimipLll4WMMvXfiVfl07TykCOq73v69Y/8bX9x 5ntcM9XnY1kpo6agsLNBECfya0GAMvmR8SWUJ3rs4nKjg2uiV7HgHH0Jtq+KkTHoyw/d pFNA== X-Forwarded-Encrypted: i=1; AJvYcCUxvMKoeiQMTazpZD6Gg2T/l9v1wi/9+WeyIy30phuv6YTQNYUvXrURb899FTFnIXGoRzDA18c26ZFRkdE=@vger.kernel.org X-Gm-Message-State: AOJu0YyUeR+hXWMpEdkBOSJRrQgU0xg0R4xE6Fj69209Uo5Rgnp6QAdB Q1f1lPCMB7HmPgrBOoDfcpDbFjsLAxjmNVWa3lHB5BraX1v0Qg5AxNXNYWjDQ3NY/8Tw/Q== 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-kbuild@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 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 Mon Feb 24 13:21:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13988044 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 4BBF524EF7D for ; Mon, 24 Feb 2025 13:21:58 +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=1740403320; cv=none; b=kJT5USGzQj1Mjtrf0ToKxi0KAovz3nVcA378siAQc2bGpMKhZy6u3gNpXw5qLGcn3jn8yhOR8pn/Y6YXZiH9KbUCXQoBbn6xU7EyTetSBa9KWREWzbLM+Q86Kv6zxecp+1yxo2ayyhHRKnQZm72JazBCTVU9Ct7p2fKbh5akvq8= 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.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="oTYW7Pxv" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4394c489babso24355205e9.1 for ; Mon, 24 Feb 2025 05:21:57 -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=kUCuT9wB5frZqUyvwsITSSNMzdQlp+fj6tP1kGOug+/Pg0P2iLuRI4JIdp+6F7mlKg NldKlfKGtDk71EteHF4IQGNPSPJ96sJRj+8xVWT3oDSDlwSJAWG3SNq5qYLLhFbPXryr QXLCdAcaCybJU+tpgIwGwL+qynTvW5NBhbnDTh2cwhKgihsZ6fAWX6SjlsNEAK5UFGRT 6fF+m24soG7A8ZB7u2DudgJ1MSXjmNs+LriWY3uVw03srolH2JWWTbf2CJ7LY070y8bB gvhTUs9rDzFc7IV7cvl7K87LJ419oTst9A/JwgFJtI6AHcv7MtJBv/Z+PQ49OqKAcTNV EySA== X-Forwarded-Encrypted: i=1; AJvYcCXED3K/A3ZJ+Gu9wdC6zlNKlOaaUJhXOEvdnwaSlpxBmLGgHWVDRsxABdEREUNRXySbyeMYC4oGpxeBP68=@vger.kernel.org X-Gm-Message-State: AOJu0YxsaJAZvLDxZSM1Te4IDC7RDvyWNojYcuHvFrU9QXHDeKYpIK7h FK+YEDNhx3+1mtW+GHWeizEAq8EjHyaKNZoAmbpQilJZ74NYzbA3LL1BuXvn0ouc3ZuWUg== 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-kbuild@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 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 = 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..7a023f17a21d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -377,7 +377,7 @@ quiet_cmd_objcopy = OBJCOPY $@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ quiet_cmd_strip_relocs = RSTRIP $@ -cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@ +cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $< $@ # 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 targets := +ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS +vmlinux-final := vmlinux.unstripped + +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 +58,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 +66,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 +83,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 +103,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 Mon Feb 24 13:21:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13988045 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 A3B7D24EF92 for ; Mon, 24 Feb 2025 13:22:00 +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=1740403322; cv=none; b=chkfvV+17mUFNRWHWalA33h891zPPq5VyMEF8WqHSY7epeSUI24tOFPfFrIi6mEHO//S5tityRsT6j99kq+yZAO3p9IJV7Sh32X6348yV5RVPfiGH426VKp+Tzejfe0qVP+0kKtrMsuU/3bOtpFc8a/bJa520hgLKmFXKPIsfsw= 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.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="Q80JJEiF" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4399c5baac3so31166085e9.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=eruUjcySe3xGUdOSsV5bPOoE3UiVb7X/zj/N+Z0WZWQYX/cbMrCw8IhIZdKuFFF3jk xnvxYh6b5I7Bzz6wFO9LtMqX3tjzAG7OEwAE2TVAUbO2eFdPB5XiTx67uwuLM6+gx0IV wOePzsqejXAVrELJKqUY1eXbt96/YOLTcDHeYLtzT49IIc4Je3Z1LnaOM0gLkvY9JeQK o9WLHaAZz4vKXt12stiDOnmWueRa3og9SNAB8oDSrbhtI5q9fqRoaBqw8aqnTML/XQSV 7mZiIvcLbQkeaC7RUjGIQQ7mynhnPwvWprhIG2RCTWOMfFD5TnV509lkpjojGkuDtgn7 CXVA== X-Forwarded-Encrypted: i=1; AJvYcCUONydHbNepvwJAvi1k2u3cw1F15PxCKxG4AAuxFYmHemb21Pe1QdRHECJ8WUb8d8p7wqBSURdUrzYlY0s=@vger.kernel.org X-Gm-Message-State: AOJu0YxLpvFdks3w+hDFaO3pN0hP4KOI7VbIMPrZcitwazFXJtyyDklo Zg+69oKI71sks5Q3V3a8S9Jb8T2czrrG0517spEOhCi3qjgzarUsjBKsEtxDMuBplpDQBw== 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-kbuild@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 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 -# =========================================================================== -# 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..8b7da3fc3f03 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -117,9 +117,11 @@ $(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