Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3004269ybf; Mon, 2 Mar 2020 20:49:22 -0800 (PST) X-Google-Smtp-Source: ADFU+vvgnStlJ3bv0hjURUwJlEdajD+2rrnq7IWcXy8StbYzfGyfYwfcIQfuFRi7/Lk0S/lSaQDv X-Received: by 2002:a05:6830:1e9c:: with SMTP id n28mr1939790otr.107.1583210961954; Mon, 02 Mar 2020 20:49:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583210961; cv=none; d=google.com; s=arc-20160816; b=YAcCKZ3/TKcmaqdUkrnqVdfY/JmvjAvrGN4zhvUQfxdcnRB9cWHv8bI+nnb2tBfvs/ WuKgZ5NrREtSTmGT6XqNR5a6VQ09ELq5lfgnHbPHGaL8Ra9ElVsACWC8v+UkHEZLhS0r 4yIWeWKtJZ0pkNq9kQYqMWs9AoARd6JX3ZCuR7LRPBlJ+uCxGT4r4b6JpHdVzeh9MdeT icT168p3auUasqvzsrE8LFH3vsDrqeF4Kg2lGoNIhO7DtiJPsA9+Flx9++fL4dmuxu9J iKcHS2ZOZA0kbD7AXq1Mrt3UHLFdp5e9OG7WYdTJ9sZnU324YByL8l2lusgy/EgSZ0U2 1dgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Sics0B7EoHCtat3/CO1pwyp/swYRXD7UJx80Cjp454c=; b=GBzs4vHzxlKhjVNlET5soAl9AdDqQwQ2jbIzP+FaWvfUuewtymXJOYOGKdemI/C9GK 3uO5Vf+6VX3tpT5vlvIpPRtI112kmxmyRCN/cMqMZ+HZR7W3NV/Gq+meku1bxiPXpUiX mtje11dqloczxlaoYUQb8iWp1Kx1YfNnczldQk7YV7JiLNk/38W6gt8K+0e/ncTSIKw/ P7KrZu9zY0bo+th5Bt+PA9OQYTyUFvgD/1JFHT1pDIl0C38kymCzu8Ce9AoaMf+34E6+ gaiaD4Bmf4P5vwnajM+oo9xQAZayYXtdB/EBkDHT9ltP5ifAND6lqI+R51mUNJN5mCwp rWLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iHnPg7Bc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si6828377oti.22.2020.03.02.20.49.09; Mon, 02 Mar 2020 20:49:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iHnPg7Bc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727095AbgCCEs7 (ORCPT + 99 others); Mon, 2 Mar 2020 23:48:59 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39786 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726859AbgCCEs7 (ORCPT ); Mon, 2 Mar 2020 23:48:59 -0500 Received: by mail-pg1-f195.google.com with SMTP id s2so924953pgv.6 for ; Mon, 02 Mar 2020 20:48:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Sics0B7EoHCtat3/CO1pwyp/swYRXD7UJx80Cjp454c=; b=iHnPg7BcPecEdHYB95AV1YGmFaTE8e6ruVjUoK73IQbKQmU1NJROEx6/7ho6yrgcVX plBRasUX+u9rqCk4siHPbGty2/YnfeBVzIAx+ckfm8TTZvumSLIIwdkS9803ZCkUgIZz OPdz/MnVjYzXW3pMqrOU9QbDB7LjmXePfmKgs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Sics0B7EoHCtat3/CO1pwyp/swYRXD7UJx80Cjp454c=; b=goxXhmNjtPfzptb1ozdt7YaLH2SBzxW1cuN+3dqsdDOL2EmwKWmxKpjzKudj/XRq6R VhywuN86ysBNxC4x7rwCgtMwd1q/6KcqCWGfP6jWpgnLhrv2MRjd9TZPqWRNXE+iYEFo KlvKLv0B5LrK5MNupYnQVU1njOP17YKDI5xhVFP7mN6fN1zP1ysBXMvUjpnNH3a90rkP 2jKirE/XN5KDc9G423osNw2YW70eI7ktzMRd1qANLulUXgfCgUilEGbUXWSUGq+8RzAW ZnuB7vwcYmxl+UtuKUKihjAQpvVzqRNBj0kVUFnvtWEfZjkcaqTusmXyrLM80p/8ovNJ jXOA== X-Gm-Message-State: ANhLgQ3hwQejJa2vHDerTXDkwzXkOaZcDVZea7SkyXMW4Gj4rN6DIcxw /eDB40f8dhmLdeaU6ERCChLzeA== X-Received: by 2002:a62:342:: with SMTP id 63mr2377981pfd.19.1583210938225; Mon, 02 Mar 2020 20:48:58 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q3sm13264664pgj.92.2020.03.02.20.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 20:48:57 -0800 (PST) Date: Mon, 2 Mar 2020 20:48:56 -0800 From: Kees Cook To: Masahiro Yamada Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , bpf@vger.kernel.org Subject: Re: [PATCH] kbuild: Remove debug info from kallsyms linking Message-ID: <202003022046.4185359A@keescook> References: <202002242114.CBED7F1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202002242114.CBED7F1@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 24, 2020 at 09:16:17PM -0800, Kees Cook wrote: > When CONFIG_DEBUG_INFO is enabled, the two kallsyms linking steps spend > time collecting and writing the dwarf sections to the temporary output > files. kallsyms does not need this information, and leaving it off > halves their linking time. This is especially noticeable without > CONFIG_DEBUG_INFO_REDUCED. The BTF linking stage, however, does still > need those details. > > Refactor the BTF and kallsyms generation stages slightly for more > regularized temporary names. Skip debug during kallsyms links. > > For a full debug info build with BTF, my link time goes from 1m06s to > 0m54s, saving about 12 seconds, or 18%. > > Signed-off-by: Kees Cook Ping. Masahiro what do you think of this? It saves me a fair bit of time on the link stage... I bet the BPF folks would be interested too. :) -Kees > --- > scripts/link-vmlinux.sh | 28 +++++++++++++++++++--------- > 1 file changed, 19 insertions(+), 9 deletions(-) > > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh > index dd484e92752e..ac569e197bfa 100755 > --- a/scripts/link-vmlinux.sh > +++ b/scripts/link-vmlinux.sh > @@ -63,12 +63,18 @@ vmlinux_link() > local lds="${objtree}/${KBUILD_LDS}" > local output=${1} > local objects > + local strip_debug > > info LD ${output} > > # skip output file argument > shift > > + # The kallsyms linking does not need debug symbols included. > + if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then > + strip_debug=-Wl,--strip-debug > + fi > + > if [ "${SRCARCH}" != "um" ]; then > objects="--whole-archive \ > ${KBUILD_VMLINUX_OBJS} \ > @@ -79,6 +85,7 @@ vmlinux_link() > ${@}" > > ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ > + ${strip_debug#-Wl,} \ > -o ${output} \ > -T ${lds} ${objects} > else > @@ -91,6 +98,7 @@ vmlinux_link() > ${@}" > > ${CC} ${CFLAGS_vmlinux} \ > + ${strip_debug} \ > -o ${output} \ > -Wl,-T,${lds} \ > ${objects} \ > @@ -106,6 +114,8 @@ gen_btf() > { > local pahole_ver > local bin_arch > + local bin_format > + local bin_file > > if ! [ -x "$(command -v ${PAHOLE})" ]; then > echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available" > @@ -118,8 +128,9 @@ gen_btf() > return 1 > fi > > - info "BTF" ${2} > vmlinux_link ${1} > + > + info "BTF" ${2} > LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1} > > # dump .BTF section into raw binary file to link with final vmlinux > @@ -127,11 +138,12 @@ gen_btf() > cut -d, -f1 | cut -d' ' -f2) > bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \ > awk '{print $4}') > + bin_file=.btf.vmlinux.bin > ${OBJCOPY} --change-section-address .BTF=0 \ > --set-section-flags .BTF=alloc -O binary \ > - --only-section=.BTF ${1} .btf.vmlinux.bin > + --only-section=.BTF ${1} $bin_file > ${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \ > - --rename-section .data=.BTF .btf.vmlinux.bin ${2} > + --rename-section .data=.BTF $bin_file ${2} > } > > # Create ${2} .o file with all symbols from the ${1} object file > @@ -166,8 +178,8 @@ kallsyms() > kallsyms_step() > { > kallsymso_prev=${kallsymso} > - kallsymso=.tmp_kallsyms${1}.o > - kallsyms_vmlinux=.tmp_vmlinux${1} > + kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1} > + kallsymso=${kallsyms_vmlinux}.o > > vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o} > kallsyms ${kallsyms_vmlinux} ${kallsymso} > @@ -190,7 +202,6 @@ cleanup() > { > rm -f .btf.* > rm -f .tmp_System.map > - rm -f .tmp_kallsyms* > rm -f .tmp_vmlinux* > rm -f System.map > rm -f vmlinux > @@ -257,9 +268,8 @@ tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | > > btf_vmlinux_bin_o="" > if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then > - if gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then > - btf_vmlinux_bin_o=.btf.vmlinux.bin.o > - else > + btf_vmlinux_bin_o=.btf.vmlinux.bin.o > + if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then > echo >&2 "Failed to generate BTF for vmlinux" > echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" > exit 1 > -- > 2.20.1 > > > -- > Kees Cook -- Kees Cook