From patchwork Mon May 20 12:42:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13668320 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8558956759; Mon, 20 May 2024 12:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208945; cv=none; b=Nli/L3Q3MgVWfJqHMUpIERACcZaK+ADV6PLQ3VV8fnaRC1iB124i4B8SqPNAgPTUH6leCxWN49Bdlp6T8iCuqgSeCwNQiS0lbQLIQdBHj9MnHtx3qkV7hHqUhBqg+TkeDlfjnM4UMquDPFZo5JuL89N/wKUUC9VycDSucaAn6+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208945; c=relaxed/simple; bh=jG8mJDdrJlMoSFn5bZlZWm1nYCF73MzL4cCC6THUpac=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DC89GaaRxGvzhRmft7TMG6oRIBonp3GDno6s0xuCedumk24FViLGa1W2Wd4aVlFHTaXICJodq1iOohMkNdu/5ehAPb6wUtBSESo+zumsPLuXmR5Zf9g2ujr4xmW6EP+iFaysL6aFTiKc6keNVDe4yfMyjmzAHUUWzrVYjZtR2RA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UvM4nX1g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UvM4nX1g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C41BC4AF0B; Mon, 20 May 2024 12:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716208945; bh=jG8mJDdrJlMoSFn5bZlZWm1nYCF73MzL4cCC6THUpac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvM4nX1gI1FUddDgTp2bYJGuOsy10xKPa42i6sUuhKwE/SHNxwElEIii9FT6mG3W8 ewG+c4OhyrLwl2KRVPYOrVxKGpIQ7PVlL/KRPUMGhtEg9J87S0Re2iCG1hMQtvcxB6 bZuD0TIE5wxI8BNtNAST27njc9cGQFKLuihco54n7cMG9Ptc9QMaSIgzIBkzxhghWU ifYXNnCMUQ0712FmsQfRY5O6bb6hN6+5QHGoazy5OHEiu8CzZtyXNhjFvCYPWDozNy ddaEMKthxA12f2b1J5x0nrBcycRCDfvF8mTJDBouawfuP4+BbqUAvK0HO5CsiU3iHF BL39D9n+GMjYw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Masahiro Yamada , Arnd Bergmann , Kees Cook , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 1/4] kbuild: avoid unneeded kallsyms step 3 Date: Mon, 20 May 2024 21:42:09 +0900 Message-Id: <20240520124212.2351033-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240520124212.2351033-1-masahiroy@kernel.org> References: <20240520124212.2351033-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since commit 951bcae6c5a0 ("kallsyms: Avoid weak references for kallsyms symbols"), the kallsyms step 3 always occurs. You can compare the build logs. [Before 951bcae6c5a0] $ git checkout 951bcae6c5a0^ $ make defconfig all [ snip ] LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux [After 951bcae6c5a0] $ git checkout 951bcae6c5a0 $ make defconfig all [ snip ] LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD .tmp_vmlinux.kallsyms3 # should not happen NM .tmp_vmlinux.kallsyms3.syms # should not happen KSYMS .tmp_vmlinux.kallsyms3.S # should not happen AS .tmp_vmlinux.kallsyms3.S # should not happen LD vmlinux The resulting vmlinux is correct, but it always requires an additional linking step. The symbols produced by kallsyms are excluded from kallsyms itself because they were previously missing in step 1. With those symbols excluded, the numbers of symbols matched between step 1 and step 2, eliminating the need for step 3. Now, this has a negative effect. Since 951bcae6c5a0, the PROVIDE() directives provide the fallback definitions, which are not trimmed from the sysmap in step 1 because ${kallsymso_prev} is empty at this point. In step2, ${kallsymso_prev} is set, and the kallsyms_* symbols are trimmed again from the sysmap. Due to the table size difference between step 1 and step 2 (the former is larger due to the presence of kallsyms_*), step 3 is triggered. Now the kallsyms_* symbols are always linked, let's stop omitting them from kallsyms. This avoids unnecessary step 3. Fixes: 951bcae6c5a0 ("kallsyms: Avoid weak references for kallsyms symbols") Signed-off-by: Masahiro Yamada --- scripts/link-vmlinux.sh | 6 +++--- scripts/mksysmap | 11 +---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 7862a8101747..b0d39a927fbc 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -179,7 +179,7 @@ kallsyms_step() kallsyms_S=${kallsyms_vmlinux}.S vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o} - mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms ${kallsymso_prev} + mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms kallsyms ${kallsyms_vmlinux}.syms ${kallsyms_S} info AS ${kallsyms_S} @@ -193,7 +193,7 @@ kallsyms_step() mksysmap() { info NM ${2} - ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} ${3} + ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} } sorttable() @@ -282,7 +282,7 @@ if is_enabled CONFIG_DEBUG_INFO_BTF && is_enabled CONFIG_BPF; then ${RESOLVE_BTFIDS} vmlinux fi -mksysmap vmlinux System.map ${kallsymso} +mksysmap vmlinux System.map if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then info SORTTAB vmlinux diff --git a/scripts/mksysmap b/scripts/mksysmap index 57ff5656d566..e46bafe333bd 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -4,7 +4,7 @@ # tools to retrieve the actual addresses of symbols in the kernel. # # Usage -# mksysmap vmlinux System.map [exclude] +# mksysmap vmlinux System.map ##### @@ -92,13 +92,4 @@ ${NM} -n ${1} | sed >${2} -e " # ppc stub /\.long_branch\./d /\.plt_branch\./d - -# --------------------------------------------------------------------------- -# Ignored kallsyms symbols -# -# If the 3rd parameter exists, symbols from it will be omitted from the output. -# This makes kallsyms have the identical symbol lists in the step 1 and 2. -# Without this, the step2 would get new symbols generated by scripts/kallsyms.c -# when CONFIG_KALLSYMS_ALL is enabled. That might require one more pass. -$(if [ $# -ge 3 ]; then ${NM} ${3} | sed -n '/ U /!s:.* \([^ ]*\)$:/ \1$/d:p'; fi) " From patchwork Mon May 20 12:42:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13668321 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DF4725FBA0; Mon, 20 May 2024 12:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208948; cv=none; b=lo1RLE+7Jm1NY3Fi4qxg2MJsOiFW6scCkmVB/NEOQ/qJVF6Hjx5BRol9SVguv8f7jspLvZqV2U6+zF65wl98EkhdVeHC85DHfAv68iffK6WZLDnL2FfVDHFiINYqLD5dXvKPervqDyLp0EzykMZi1wgcGsy+Z2NWPdeQB2GI2RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208948; c=relaxed/simple; bh=xxfBrLnsF1A2xg6Jdz/kmz2DmtquNNmEmxzRupok00A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j3dE+m9GwEyOu04OV37lFu3J7jursC8mO4v1Z6bV4EPQ7OIx2MPMyWw+eTjnhiVE1/VqWhfqlTF0vXkifEdkP20rfjvrIfAOXeK5e62Sk1KpJCnCoeFzCoZRxX0SDQvd+xhNsziPufyojBjwXp4Z0BIlrbyjc3W9nzRFbtc1wi8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lJyYELBp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lJyYELBp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E37EFC4AF09; Mon, 20 May 2024 12:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716208947; bh=xxfBrLnsF1A2xg6Jdz/kmz2DmtquNNmEmxzRupok00A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lJyYELBp2Z83mPg8efMr9jQdaEsibHaSry6bprWwqtyrcFpHcH1fB8SZ+O4syblea bcjgR51BbvSlTubXRC+pjHSseAkC1OdVNGQe5rSdh3dumXXvn8kuRrLoc9Gj05fXVO +zCG1HYUe+b3B8M7a57pniEfIdeBTkcDN1XPZ4UqcYXLyYNJHFAYYtgdyYnlwPh7O7 RXw0btRjNTewyVJglU8I+/pRPa1D56Q8l9sBU+AbHh16HcHJv0pIhrZmiQAtxx8VSz X73yOZmzYkV8pE0U/BoDFaRtrIaO9NKu56jxl2Jlz0PaINxdRg/9nNdC5TCD7GeqTO 8bxH6nPVzJ2vw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nicolas Schier Subject: [PATCH 2/4] kbuild: change scripts/mksysmap into sed script Date: Mon, 20 May 2024 21:42:10 +0900 Message-Id: <20240520124212.2351033-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240520124212.2351033-1-masahiroy@kernel.org> References: <20240520124212.2351033-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The previous commit removed the subshell execution from scripts/mksysmap, which is now simple enough to become a sed script. Signed-off-by: Masahiro Yamada --- scripts/link-vmlinux.sh | 2 +- scripts/mksysmap | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index b0d39a927fbc..c22a213ea6a9 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -193,7 +193,7 @@ kallsyms_step() mksysmap() { info NM ${2} - ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} + ${NM} -n "${1}" | "${srctree}/scripts/mksysmap" > "${2}" } sorttable() diff --git a/scripts/mksysmap b/scripts/mksysmap index e46bafe333bd..c12723a04655 100755 --- a/scripts/mksysmap +++ b/scripts/mksysmap @@ -1,22 +1,16 @@ -#!/bin/sh -x -# Based on the vmlinux file create the System.map file +#!/bin/sed -f +# SPDX-License-Identifier: GPL-2.0-only +# +# sed script to filter out symbols that are not needed for System.map, +# or not suitable for kallsyms. The input should be 'nm -n '. +# # System.map is used by module-init tools and some debugging # tools to retrieve the actual addresses of symbols in the kernel. # -# Usage -# mksysmap vmlinux System.map - - -##### -# Generate System.map (actual filename passed as second argument) -# The following refers to the symbol type as per nm(1). - # readprofile starts reading symbols when _stext is found, and # continue until it finds a symbol which is not either of 'T', 't', # 'W' or 'w'. # - -${NM} -n ${1} | sed >${2} -e " # --------------------------------------------------------------------------- # Ignored symbol types # @@ -92,4 +86,3 @@ ${NM} -n ${1} | sed >${2} -e " # ppc stub /\.long_branch\./d /\.plt_branch\./d -" From patchwork Mon May 20 12:42:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13668322 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C164960EC4; Mon, 20 May 2024 12:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208949; cv=none; b=eKIbXg0cZ4kCv3ER7DKBabqvOsF3caz6xf8emSS2HvNt9lXhUpx/PY+r+SudoXTcA5ZORyLDYazAOYzJJlcSnGlyKvoWpf4c+qR1bQ2mDAB5d16wGA11oJG7QWf7M0CNovlVamhRG+Bxa90XLk3PH647ODA5a1JNreZzqkKcajQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208949; c=relaxed/simple; bh=TxFPGBAJwk5Wb8NrApnx3ozpKy0fGdYVURZX3jvxjMA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tSCx7Y93gB7WhIz2BXayzVhC76mpWzDIbuaV/CVomXFF0o8248yZvvdc+Crx1onawTPMHWYVZUZAVDOuyttE8wsGOHK+5AQmsqlNI0l5HP7UX2Jzsfc9bkz1gNvLShqTGYyJp47A5KnAXGcfsLCi5dIeJEAca02b5q293g+ZzyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jxbAJIqp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jxbAJIqp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EE4FC4AF0C; Mon, 20 May 2024 12:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716208949; bh=TxFPGBAJwk5Wb8NrApnx3ozpKy0fGdYVURZX3jvxjMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jxbAJIqpjjxAzP5cfKjuNqJtGsxPZQJ0dPYnkNbHAq3qZYJZm7Ecou/bT8u/upHcM Ylk5vXeBWs9U+E1kLzBetKzMNneBOuqSr8/PfcDG60EE47XB04ienKn7jmO95TVu5Q eleSkLfFyo80fx+JgaJ1AP3N3F/Rf8hxB6R0OvMC5Tqs8G39xMsWICKQhikdkfaJpc gMLcYj3NnDA9lIajVmeFgN09R+cX80WNXDnI6voM94xbB1MXT0t9Dh8fkhOAH3Odwc 6VeVBFW/2W1RqpxvUeC//ljlEaRlSbdPClQtgtoJlNL8AGLbtSGFlaBfOru3rWjN9o etKnC7G9CiMUQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nicolas Schier Subject: [PATCH 3/4] kbuild: fix shortlog for AS in link-vmlinux.sh Date: Mon, 20 May 2024 21:42:11 +0900 Message-Id: <20240520124212.2351033-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240520124212.2351033-1-masahiroy@kernel.org> References: <20240520124212.2351033-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In convention, the short log prints the output file, not the input file. Change the suffix for 'AS' since it assembles *.S into *.o. [Before] LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux [After] LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.o LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.o LD vmlinux Signed-off-by: Masahiro Yamada --- scripts/link-vmlinux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index c22a213ea6a9..7aca51b24e9f 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -182,7 +182,7 @@ kallsyms_step() mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms kallsyms ${kallsyms_vmlinux}.syms ${kallsyms_S} - info AS ${kallsyms_S} + info AS ${kallsymso} ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ -c -o ${kallsymso} ${kallsyms_S} From patchwork Mon May 20 12:42:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13668323 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AEAB56CDD5; Mon, 20 May 2024 12:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208953; cv=none; b=RfSchIMC4HYW1XiEhXVe3LqbR1WT1qaQKVxlB11Z1BL/SA9T/nWSl5N7Oa3NFHlONZCtOQc4+SAvGPe09yQYZJ01rOJr+piPFW7KCMnD3ZQPZhrFjvVN8V8SsyzUz4WajtaMwjt93BqnOq+1C2C79uyC6MgoO/1673Nx1356Dy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208953; c=relaxed/simple; bh=qk3nM/f5UNsXDM1W0TPogosoeVu0tHgz+zzN7497OSE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NQhoj2aD/tJxnlv6BFOUTQI0TOIZou0BOw+gVH79aKzLiJ7YpmdtAjNuUks3EeCqKWWLRpXsAqnZshYdligxgm1z4AuXBcp4E7QFFE6lUslMRn1TGME+Gzq8KOoaDgVb1udaZ2TqzrAw7w2edwyLF5AaiMWi7ukA51ogcEwBDT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YyBNcowk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YyBNcowk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59504C32786; Mon, 20 May 2024 12:42:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716208953; bh=qk3nM/f5UNsXDM1W0TPogosoeVu0tHgz+zzN7497OSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YyBNcowkR08Pvva3DQQQaiEwxnZnUx+kN1mQU0jtioTFXWWKsNcbTU/NJDobKCHpi G4gNLhmyWu3xXc+jouWTyEfRCVviOB0FBPuOERgBnNRPebrTK6Ohb+4SQgVdH81ZcR zErsQhS/IKbQbBfwXoAHzirERRlibrU40Vpn8YbatPxmg4ytJ1YSD39C0Y0wASc7ri ZWppDnOZszLi5QDEv+1q4C509KA2ubG6Yudb4GPTYeVMMn+0dO8Y44XirOKLrHSIZw 8bffSy8phNrrXDYmSnnsDP5fw1p063RTZeHQCEZp32eRat/TI3JjTZ1LS3BzjafWVS CXAM0M012rUTg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Masahiro Yamada , Arnd Bergmann , Nathan Chancellor , Nicolas Schier , linux-arch@vger.kernel.org Subject: [PATCH 4/4] kbuild: remove PROVIDE() for kallsyms symbols Date: Mon, 20 May 2024 21:42:12 +0900 Message-Id: <20240520124212.2351033-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240520124212.2351033-1-masahiroy@kernel.org> References: <20240520124212.2351033-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This reimplements commit 951bcae6c5a0 ("kallsyms: Avoid weak references for kallsyms symbols"). I am not a big fan of PROVIDE() because it always satisfies the linker even in situations that should result in a link error. In other words, it can potentially shift a compile-time error into a run-time error. Duplicating kallsyms_* in vmlinux.lds.h also reduces maintainability. I shuffled scripts/link-vmlinux.sh to prepend one more kallsyms step. The following logs illustrates how it works. [Before] LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.o LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.o LD vmlinux [After] KSYMS .tmp_vmlinux.kallsyms0.S # added AS .tmp_vmlinux.kallsyms0.o # added LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.o LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.o LD vmlinux Step 0 takes /dev/null as input, and generates .tmp_vmlinux.kallsyms0.o, which has a valid kallsyms format with zero symbols, and can be linked to vmlinux. Since it is really small, the added compile-time cost is negligible. Signed-off-by: Masahiro Yamada --- include/asm-generic/vmlinux.lds.h | 19 ------------- kernel/kallsyms_internal.h | 5 ---- scripts/kallsyms.c | 6 ----- scripts/link-vmlinux.sh | 45 ++++++++++++++++--------------- 4 files changed, 24 insertions(+), 51 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 870753fbb123..9752eb420ffa 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -448,30 +448,11 @@ #endif #endif -/* - * Some symbol definitions will not exist yet during the first pass of the - * link, but are guaranteed to exist in the final link. Provide preliminary - * definitions that will be superseded in the final link to avoid having to - * rely on weak external linkage, which requires a GOT when used in position - * independent code. - */ -#define PRELIMINARY_SYMBOL_DEFINITIONS \ - PROVIDE(kallsyms_addresses = .); \ - PROVIDE(kallsyms_offsets = .); \ - PROVIDE(kallsyms_names = .); \ - PROVIDE(kallsyms_num_syms = .); \ - PROVIDE(kallsyms_relative_base = .); \ - PROVIDE(kallsyms_token_table = .); \ - PROVIDE(kallsyms_token_index = .); \ - PROVIDE(kallsyms_markers = .); \ - PROVIDE(kallsyms_seqs_of_names = .); - /* * Read only Data */ #define RO_DATA(align) \ . = ALIGN((align)); \ - PRELIMINARY_SYMBOL_DEFINITIONS \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h index 85480274fc8f..925f2ab22639 100644 --- a/kernel/kallsyms_internal.h +++ b/kernel/kallsyms_internal.h @@ -4,11 +4,6 @@ #include -/* - * These will be re-linked against their real values during the second link - * stage. Preliminary values must be provided in the linker script using the - * PROVIDE() directive so that the first link stage can complete successfully. - */ extern const unsigned long kallsyms_addresses[]; extern const int kallsyms_offsets[]; extern const u8 kallsyms_names[]; diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 653b92f6d4c8..6b90f52fd707 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -246,12 +246,6 @@ static void shrink_table(void) } } table_cnt = pos; - - /* When valid symbol is not registered, exit to error */ - if (!table_cnt) { - fprintf(stderr, "No valid symbol.\n"); - exit(1); - } } static void read_map(const char *in) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 7aca51b24e9f..242a92e24f20 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -165,27 +165,25 @@ kallsyms() kallsymopt="${kallsymopt} --lto-clang" fi - info KSYMS ${2} - scripts/kallsyms ${kallsymopt} ${1} > ${2} + info KSYMS "${2}.S" + scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S" + + info AS "${2}.o" + ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ + ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ + -c -o "${2}.o" "${2}.S" + kallsymso=${2}.o } # Perform one step in kallsyms generation, including temporary linking of # vmlinux. kallsyms_step() { - kallsymso_prev=${kallsymso} kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1} - kallsymso=${kallsyms_vmlinux}.o - kallsyms_S=${kallsyms_vmlinux}.S - vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o} - mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms - kallsyms ${kallsyms_vmlinux}.syms ${kallsyms_S} - - info AS ${kallsymso} - ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ - ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ - -c -o ${kallsymso} ${kallsyms_S} + vmlinux_link "${kallsyms_vmlinux}" "${kallsymso}" "${btf_vmlinux_bin_o}" + mksysmap "${kallsyms_vmlinux}" "${kallsyms_vmlinux}.syms" + kallsyms "${kallsyms_vmlinux}.syms" "${kallsyms_vmlinux}" } # Create map file with all symbols from ${1} @@ -235,15 +233,15 @@ if is_enabled CONFIG_DEBUG_INFO_BTF; then fi kallsymso="" -kallsymso_prev="" -kallsyms_vmlinux="" if is_enabled CONFIG_KALLSYMS; then # kallsyms support # Generate section listing all symbols and add it into vmlinux - # It's a three step process: + # It's a four step process: + # 0) Generate a dummy __kallsyms, which has zero symbols, but a valid + # format. # 1) Link .tmp_vmlinux.kallsyms1 so it has all symbols and sections, - # but __kallsyms is empty. + # with a dummy __kallsyms. # Running kallsyms on that gives us .tmp_kallsyms1.o with # the right size # 2) Link .tmp_vmlinux.kallsyms2 so it now has a __kallsyms section of @@ -262,13 +260,18 @@ if is_enabled CONFIG_KALLSYMS; then # a) Verify that the System.map from vmlinux matches the map from # ${kallsymso}. - kallsyms_step 1 - kallsyms_step 2 + # step 0 + kallsyms /dev/null .tmp_vmlinux.kallsyms0 - # step 3 - size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso_prev}) + # step 1 + kallsyms_step 1 + size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) + + # step 2 + kallsyms_step 2 size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) + # step 3 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then kallsyms_step 3 fi