From patchwork Sat Aug 24 17:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13776455 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF2334CB5B; Sat, 24 Aug 2024 17:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724521468; cv=none; b=YqUByIktpw1UGpn8Wych819DrBHIhbW/PLyv8PZtkRec38MuXJWZdE9U5iNfYx8aah89Yno9CjJh6/Pyv+2JuOZa8REV04EmwWJjkHORFFsTsS2wR9rKvYs99DtYL1rFQRtH9NBjqBJs+9U9b55ZlbpeVt+w2uJMZ1TRQh4YRH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724521468; c=relaxed/simple; bh=IUmNRQEtWfRqPXvD++QujEJNnvCeXoDLdw9P2RX7x/c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=R5NSoyFtBIEx1gn6fBiVyHoagyb1kHUxqmQA9P5PsZHv4wIVPWfxBdCfA4Uaj0PZ/N4xI8vPu8ZMHKHHQ+6h2gD7GrjCJ8YGBNTUxIgq02U3ZrSF9FC8zZhdfynhXAIIc7/WJJUug+qmgo09B/wxKB9hklcUUvgrG07CKMs0/8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=jH+uXp3F; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="jH+uXp3F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1724521455; bh=IUmNRQEtWfRqPXvD++QujEJNnvCeXoDLdw9P2RX7x/c=; h=From:Date:Subject:To:Cc:From; b=jH+uXp3FvXmePuA9GLa0qkVROdUDt1jcmcwC58WudEwjdr96v2EPuqVA2qtjSJDQU +mVlRvkngsBTtWvroNdRAn0Jy2se/oo/bSQaNvw9fsBmsZWjxsXJKkzwqAV0rOszA/ nCki+qLrZUyzXoUzAB9hXScgz4KQOQWxXwuH22Lk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 24 Aug 2024 19:44:11 +0200 Subject: [PATCH RFC] modpost: compile constant module information only once Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240824-modinfo-const-v1-1-485f9c64b868@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAOobymYC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDCyMT3dz8lMy8tHzd5Py84hJdszSDFDPzVKMkYwNDJaCegqLUtMwKsHn RSkFuzkqxtbUAGY7by2QAAAA= To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, =?utf-8?q?Th?= =?utf-8?q?omas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724521455; l=5978; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=IUmNRQEtWfRqPXvD++QujEJNnvCeXoDLdw9P2RX7x/c=; b=S1c1kqezDqisSkB9v3/fhM1O0/dI+eUUJtP46u5zwlzT4CqkvgZHNd12ynOZwpyWqvpKw5gWn bThGefa7hJ/CyE915Da+VavXHswwkrHRVz7Hrvvu58eCnCn4mxCbv/n X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Various information about modules is compiled into the info sections. For that a dedicated .mod.c file is generated by modpost for each module and then linked into the module. However most of the information in the .mod.c is the same for all modules, internal and external. Split the shared information into a dedicated source file that is compiled once and then linked into all modules. This avoids frequent rebuilds for all .mod.c files when using CONFIG_LOCALVERSION_AUTO because the local version ends up in .mod.c through UTS_RELEASE and VERMAGIC_STRING. The modules are still relinked in this case. The code is also easier to maintain as it's now in a proper source file instead of an inline string literal. Signed-off-by: Thomas Weißschuh --- I came up with this while investigating something different. Not sure it's worth the effort. --- scripts/Makefile.modfinal | 9 +++++++-- scripts/mod/modinfo.c | 25 +++++++++++++++++++++++++ scripts/mod/modpost.c | 23 ----------------------- scripts/package/install-extmod-build | 3 ++- 4 files changed, 34 insertions(+), 26 deletions(-) --- base-commit: 184a282d540c3da03f6a229f4792a5f72d3dfc2a change-id: 20240824-modinfo-const-6f0d67e2b301 Best regards, diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 306a6bb86e4d..dde09dc4ba11 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -30,6 +30,11 @@ quiet_cmd_cc_o_c = CC [M] $@ %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) +ifeq ($(KBUILD_EXTMOD),) +scripts/mod/modinfo.o: scripts/mod/modinfo.c FORCE + $(call if_changed_dep,cc_o_c) +endif + quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ $(LD) -r $(KBUILD_LDFLAGS) \ @@ -54,13 +59,13 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE +%.ko: %.o %.mod.o scripts/module.lds scripts/mod/modinfo.o $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE +$(call if_changed_except,ld_ko_o,vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif -targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) +targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) scripts/mod/modinfo.o # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/mod/modinfo.c b/scripts/mod/modinfo.c new file mode 100644 index 000000000000..12fbc6d3aae8 --- /dev/null +++ b/scripts/mod/modinfo.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +/* + * Include build-salt.h after module.h in order to + * inherit the definitions. + */ +#define INCLUDE_VERMAGIC +#include +#include +#include + +#ifdef CONFIG_UNWINDER_ORC +#include +ORC_HEADER; +#endif + +BUILD_SALT; +BUILD_LTO_INFO; + +MODULE_INFO(vermagic, VERMAGIC_STRING); + +#ifdef CONFIG_MITIGATION_RETPOLINE +MODULE_INFO(retpoline, "Y"); +#endif diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c8cd5d822bb6..107393a8c48a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1755,26 +1755,9 @@ static void check_modname_len(struct module *mod) static void add_header(struct buffer *b, struct module *mod) { buf_printf(b, "#include \n"); - /* - * Include build-salt.h after module.h in order to - * inherit the definitions. - */ - buf_printf(b, "#define INCLUDE_VERMAGIC\n"); - buf_printf(b, "#include \n"); - buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); - buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "\n"); - buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n"); - buf_printf(b, "#include \n"); - buf_printf(b, "ORC_HEADER;\n"); - buf_printf(b, "#endif\n"); - buf_printf(b, "\n"); - buf_printf(b, "BUILD_SALT;\n"); - buf_printf(b, "BUILD_LTO_INFO;\n"); - buf_printf(b, "\n"); - buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); buf_printf(b, "\n"); buf_printf(b, "__visible struct module __this_module\n"); @@ -1792,12 +1775,6 @@ static void add_header(struct buffer *b, struct module *mod) if (!external_module) buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); - buf_printf(b, - "\n" - "#ifdef CONFIG_MITIGATION_RETPOLINE\n" - "MODULE_INFO(retpoline, \"Y\");\n" - "#endif\n"); - if (strstarts(mod->name, "drivers/staging")) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); diff --git a/scripts/package/install-extmod-build b/scripts/package/install-extmod-build index d2c9cacecc0c..15fab6d5dd56 100755 --- a/scripts/package/install-extmod-build +++ b/scripts/package/install-extmod-build @@ -37,6 +37,7 @@ mkdir -p "${destdir}" echo include/config/auto.conf echo include/config/kernel.release echo include/generated + echo scripts/mod/modinfo.o find_in_scripts if is_enabled CONFIG_GCC_PLUGINS; then @@ -78,4 +79,4 @@ if [ "${CC}" != "${HOSTCC}" ] && is_enabled CONFIG_CC_CAN_LINK; then rm -f "${destdir}/Kbuild" "${destdir}/scripts/Kbuild" fi -find "${destdir}" \( -name '.*.cmd' -o -name '*.o' \) -delete +find "${destdir}" \( -name '.*.cmd' -o \( -name '*.o' -a -! -path '*/scripts/mod/modinfo.o' \) \) -delete