Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp289250lqp; Mon, 10 Jun 2024 04:28:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV76KUU6V3ABSLSwGb0+GV35GwAItc7XcV2+NiG3X7KhawLGlZvg+yzVcq5R1fhdKt0VBFOFfJ5Itzbu1OYQa+A4wk+2ZfggDS7agBiWw== X-Google-Smtp-Source: AGHT+IFXytZXJGPMv7unCwJg645igFojjkdlTHcO90K88ptxEgtW5m+SmAvT4LhbBGDbLas+BQ8Z X-Received: by 2002:a05:6e02:1a28:b0:374:a90d:cf5f with SMTP id e9e14a558f8ab-37580363e2fmr110009825ab.24.1718018902117; Mon, 10 Jun 2024 04:28:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718018902; cv=pass; d=google.com; s=arc-20160816; b=SboMpI16sZquWo1P/DkC0axw6W4X7lhiTSJxBCy1htdj0hoO4jrdZAw+hLStpgxinR auYW8eAFNw6gAU0tWkq7Z712RKetN611MaFlvwNouEvk/oPJDmcvIcxFznreIPELaQbg +m+VbTJ1hIhZbbnmp8R0Zeq7tNTU9/zJKfgyS74xF4IeTkrpauTGSW9t96Tm3iHgpP2F hssMPqCjQ4TIbfbK2GGay1nHbe8YHdIKUo/6hQr2C7N3mCRalJK87Q4fpABEVUH1xWD5 R5yLl26L1D6hGa9q6li6m6iEUS3Tj/F2Oc/KVUpWc9bwModdbXnJk0sz+JbsFTyWVTcL mmpA== 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=M/87RHex8GTB0gz+52UKV3eIhY0GJG8a6RzQNW+w4Hk=; fh=QDMdxlIAeei7pPciqGEvD/iqt94AweiTDRrObeB4yyQ=; b=wMQWpKzhNMrHVj8rg4mC4FfcCQpHwfadv4y+jFXHUGW7D+//tWO0VchUqh4fqX9PXC O7Fog5HPuyNIPpasNdMN4O4CsNSx/ef1JC5NTHx2FVAVZF1dKbuY/DtBqc1HlgJ2G9HZ zIyHvRx9S3bHkmcVnsn7XQmLRiEuHZ4iX01vjGkKKr8JzXkBq0sRVOtINxqAwQeyC2dl FpIrjO0sg3dnjyhrl/9hsh/UUDey0dZFfIHnAhZPCzkH+N4oy/UMYhYCtpx8Hw6U372x a+mFYk9A9nN5MVcD63pfOp9BwiIP9m1Ft7wngZQuiuLb8WViNI2nggh5xfqoyIQUSsut aaRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NdDhpUuF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208080-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208080-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e9bb50f535si3085888a12.517.2024.06.10.04.28.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 04:28:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208080-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NdDhpUuF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208080-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208080-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BD71728390D for ; Mon, 10 Jun 2024 11:28:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 430BE80626; Mon, 10 Jun 2024 11:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NdDhpUuF" 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 4967880026; Mon, 10 Jun 2024 11:27:09 +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=1718018830; cv=none; b=HK6F4WrVYOrE38Cg/4WpJsxpGYEr8JkncSTED3hIE/kkSl9Ijdy1YbbV/FKsjqaijnO6truSTohrOXCGCDkdjaZ5nH+ymEPaYd08So08szxReiZCcYkNc29xiIwC1L9H2YeAieM1iItJcubWRL0IjEmdMloLmXjqJ96WiLXgg3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718018830; c=relaxed/simple; bh=8otrnDiqoQhgxvCkewI2dBjUDJnKxXquskHQT8fi5Mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UlQRoVD8EkWhlP7HaEdq7GL1g7bjIOXShlNbscF4hT5iqhBnerrlooNZGb0Fxq0L9pEX+TY0PTdqHwYMHULLB+sUyXI4/RqfbsuGL2+v77cxQb1x5urHuQY4rnR45b2HYuRuhCTdqArN/DgBTqShYv2E/TyGte1oeau1PYgBKgw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NdDhpUuF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DEEBC4AF1C; Mon, 10 Jun 2024 11:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718018829; bh=8otrnDiqoQhgxvCkewI2dBjUDJnKxXquskHQT8fi5Mw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdDhpUuFwd2D78wNnBZYki/Ofz/1V5Y3HSgbu/wnZAn5sDhgI2fRujor9V7RIz7ur O3tVLfvwdBFt2PX3c7XNEVCzmpLZvabEcLc3ccT19O1KfYOruquMjizTNsBFn7fp58 d1XZxWSejPAnc7QlMkavAKD2lIGL7G908vow+ikbjR/PqalO5s8nGXKN9TS8n5d3oa g/dyxy+hEWrf/JMVJr8u3PfitiSux+X7sIIQKDMXJ0fPVlReQ1HLZz9gSfslkOEb/p vmRvjmf37idJLLRh7gUUB16kdV/uKVIH/KKQXA7kZtgAW9woaLuSBF+jAk3ErFUp5s DUy85uNATH9Hg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Andrii Nakryiko , Nathan Chancellor , Nicolas Schier Subject: [PATCH v3 3/3] kbuild: merge temporary vmlinux for BTF and kallsyms Date: Mon, 10 Jun 2024 20:25:18 +0900 Message-ID: <20240610112657.602958-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240610112657.602958-1-masahiroy@kernel.org> References: <20240610112657.602958-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 CONFIG_DEBUG_INFO_BTF=y requires one additional link step. (.tmp_vmlinux.btf) CONFIG_KALLSYMS=y requires two additional link steps. (.tmp_vmlinux.kallsyms1 and .tmp_vmlinux.kallsyms2) Enabling both requires three additional link steps. When CONFIG_DEBUG_INFO_BTF=y and CONFIG_KALLSYMS=y, the current build process is as follows: KSYMS .tmp_vmlinux.kallsyms0.S AS .tmp_vmlinux.kallsyms0.o LD .tmp_vmlinux.btf # temporary vmlinux for BTF BTF .btf.vmlinux.bin.o LD .tmp_vmlinux.kallsyms1 # temporary vmlinux for kallsyms step 1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.o LD .tmp_vmlinux.kallsyms2 # temporary vmlinux for kallsyms step 2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.o LD vmlinux # final vmlinux This is redundant because the BTF generation and the kallsyms step 1 can be performed against the same temporary vmlinux. When both CONFIG_DEBUG_INFO_BTF and CONFIG_KALLSYMS are enabled, we can reduce the number of link steps by one. This commit changes the build process as follows: KSYMS .tmp_vmlinux0.kallsyms.S AS .tmp_vmlinux0.kallsyms.o LD .tmp_vmlinux1 # temporary vmlinux for BTF and kallsyms step 1 BTF .tmp_vmlinux1.btf.o NM .tmp_vmlinux1.syms KSYMS .tmp_vmlinux1.kallsyms.S AS .tmp_vmlinux1.kallsyms.o LD .tmp_vmlinux2 # temporary vmlinux for kallsyms step 2 NM .tmp_vmlinux2.syms KSYMS .tmp_vmlinux2.kallsyms.S AS .tmp_vmlinux2.kallsyms.o LD vmlinux # final vmlinux Signed-off-by: Masahiro Yamada Acked-by: Andrii Nakryiko --- Changes in v3: - Use ${strip_debug} for clean-up Changes in v2: - Fix the handling --strip-debug flag scripts/link-vmlinux.sh | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 83d605ba7241..c64158a04f82 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -105,11 +105,10 @@ vmlinux_link() # generate .BTF typeinfo from DWARF debuginfo # ${1} - vmlinux image -# ${2} - file to dump raw BTF data into gen_btf() { local pahole_ver - local btf_data=${2} + local btf_data=${1}.btf.o if ! [ -x "$(command -v ${PAHOLE})" ]; then echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available" @@ -122,8 +121,6 @@ gen_btf() return 1 fi - vmlinux_link ${1} - info BTF "${btf_data}" LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} @@ -177,15 +174,13 @@ kallsyms() kallsymso=${2}.o } -# Perform one step in kallsyms generation, including temporary linking of -# vmlinux. -kallsyms_step() +# Perform kallsyms for the given temporary vmlinux. +sysmap_and_kallsyms() { - kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1} + mksysmap "${1}" "${1}.syms" + kallsyms "${1}.syms" "${1}.kallsyms" - vmlinux_link "${kallsyms_vmlinux}" - mksysmap "${kallsyms_vmlinux}" "${kallsyms_vmlinux}.syms" - kallsyms "${kallsyms_vmlinux}.syms" "${kallsyms_vmlinux}" + kallsyms_sysmap=${1}.syms } # Create map file with all symbols from ${1} @@ -228,11 +223,21 @@ kallsymso= strip_debug= if is_enabled CONFIG_KALLSYMS; then - kallsyms /dev/null .tmp_vmlinux.kallsyms0 + kallsyms /dev/null .tmp_vmlinux0.kallsyms +fi + +if is_enabled CONFIG_KALLSYMS || is_enabled CONFIG_DEBUG_INFO_BTF; then + + # The kallsyms linking does not need debug symbols, but the BTF does. + if ! is_enabled CONFIG_DEBUG_INFO_BTF; then + strip_debug=1 + fi + + vmlinux_link .tmp_vmlinux1 fi if is_enabled CONFIG_DEBUG_INFO_BTF; then - if ! gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then + if ! gen_btf .tmp_vmlinux1; then echo >&2 "Failed to generate BTF for vmlinux" echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" exit 1 @@ -268,14 +273,16 @@ if is_enabled CONFIG_KALLSYMS; then # The kallsyms linking does not need debug symbols included. strip_debug=1 - kallsyms_step 1 + sysmap_and_kallsyms .tmp_vmlinux1 size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) - kallsyms_step 2 + vmlinux_link .tmp_vmlinux2 + sysmap_and_kallsyms .tmp_vmlinux2 size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then - kallsyms_step 3 + vmlinux_link .tmp_vmlinux3 + sysmap_and_kallsyms .tmp_vmlinux3 fi fi @@ -301,7 +308,7 @@ fi # step a (see comment above) if is_enabled CONFIG_KALLSYMS; then - if ! cmp -s System.map ${kallsyms_vmlinux}.syms; then + if ! cmp -s System.map "${kallsyms_sysmap}"; then echo >&2 Inconsistent kallsyms data echo >&2 'Try "make KALLSYMS_EXTRA_PASS=1" as a workaround' exit 1 -- 2.43.0