Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2422962lqo; Mon, 20 May 2024 05:42:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU7YvdIer5eY8/GhZDxAdlVTNU+XM969maHCyhnVMVxGgCbt29D0xFDtcOF/nEMtJs+74+k9Hfd6VhOGVizUvt5YFhd2QmyTlRw5aTHdw== X-Google-Smtp-Source: AGHT+IHBSrEjnkKrJZVsxdzOOuzxOzxV9mKunocN9D6eQwApAiqsj3ZulxjS+cA/XYPC9cciW8Ny X-Received: by 2002:a50:bac4:0:b0:572:9f40:514d with SMTP id 4fb4d7f45d1cf-5734d67aadbmr18086018a12.29.1716208964951; Mon, 20 May 2024 05:42:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716208964; cv=pass; d=google.com; s=arc-20160816; b=m3aH84M1yWLfOT7D9gvFLFvamnB7wPCSEfeSnLD2C7WUi+uVFyv/U9VQAzpY3j+BZh YjjogFoOhgnuKZwUnBi6l8xwID5NRpGp8TRK4WW71C+rWFv12SdwoGDbTFwJMDpl5VVs AxPc+ahmmaWl2OsP/IYr0UPx28+mNaH7nw3AEOFNM/nLN5LmmuHlWoryv9qhk0xu65eK wkizrzfUbt+hXyA6v2+Me0llQbodFmTMd81YW7lkZLXFq4uUB5dr3LVLxjdHbD6zG1HX fqMwR2WtYo94KDBDXhKm2MZSId4+6UucJ6BR3SHgbJu61kzV8cRqVKgFHJMLQFWZ1uai j15A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JEidgsXZ6LtrUUilCHa++mP589a9agdQ7sEGUwxzKuE=; fh=z0EzB2zjyUNVJLTSmYmPzejwrB/mx9ayFZBbNA27/pU=; b=fTRrbaPzMdp8Vk6aN6DA1wphpP8VF5g6Ne4unRD4ndIn3Yyij6CrD2uc7qG9KsRD0r fYbRErCnYKaNQWa6ctcp7wZLgr8HkhfREJXsMIFZkhl5UQTNWyeQ2W+Z1SOrEhgrUYxk O4tVjYkMjborc9nrfNny4Twq0CQiuXGXpLFEHqgXO95tG9iy+Icb2c5A7ZQin/PSzaEC M7hC7zLNoFxk7fU2Hi7rSF8reoGOG+UYhC54hQgbIQSY970Ifnqqk1zC+oIlHJUM0FNj eBYF90sYGa7ViGOckEd6xUo9mbSXA21vRdu3j9hLXiUK9kKFeBPAe3y7J7j80NaGXf5m 7O3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UvM4nX1g; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c36d77fsi12714147a12.543.2024.05.20.05.42.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 05:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UvM4nX1g; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9549F1F216AC for ; Mon, 20 May 2024 12:42:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AEBA50275; Mon, 20 May 2024 12:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UvM4nX1g" 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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) " -- 2.40.1