Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3241344ybv; Mon, 24 Feb 2020 21:17:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwkZGJd4pIKoUJdOPi8qEYiV7MXhHt3a8wDyJR9fv1cXdQSRUKsGaCmbYvusZaYfD0MdwBY X-Received: by 2002:a9d:3e43:: with SMTP id h3mr41128030otg.84.1582607861797; Mon, 24 Feb 2020 21:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582607861; cv=none; d=google.com; s=arc-20160816; b=J9wzP0OKzGl7g1Jwz7mV9NJQjClv0EUbkUhqnvPmwMgd3SW3PGBP98EfCfUB4xxVCQ aujbzIRoTH+riu+fhFE4rpCCtUTz2TT2bxC1S425ud8mfdmcWHr7XPhlU/QFqegP2Ss7 7jgUh4z3bazJN5LfbXn4Kmf3GIMcvbrcN+pZ0C4immIUEEHP3peO03+w/LrIp72tvaKX helXqdDnN+9rcvD07n/7sEtGFe+O1+LU+VDXK3SNm5QADe2aK2XMzQvAi7UdKHcyXy3L X4215eNc6Wfk+3vmLSzGjoaF4F4YNJ69JBiH7YDBkUbYgoDcmxtbbqeI0oeJrrKU6oNv oJRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=U6Wt/LenosPR0Sx0SmEySrtroNHk0FTBlW4IV6YiiMg=; b=wvc3s6Qnk4UqJs2d3CKhhxCgYwhN3YlTG8ABZMEW8Ps66HKK0IxMo1ksmSbFIq2B1g lClfiIxsMwr/yff6b8BP99CjRVGnzriJ3rYurhYXHSK2viNBCVf3LxYsCz31s2Vlh5bZ 5xyiLxaaTZrisQvij39Q/CFvU4d328csMM8w4UczdnempHgxpiF0UuOWsFTvxkr5h68l M++Y196UrxvLt1BLQIr+zHhOgNgRjF8sx+Eqw8C9bfG0aBNbrdccKAlMRp0F1Xn6cc1C 7MU0O0WWuMfHdWsbMrl59FgS93d1u3C4KeDE0R4oRcJIIfeCLsazHnfmjLe44EvbOxk8 u86Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CjAlLRcC; 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 r10si7917935otn.241.2020.02.24.21.17.29; Mon, 24 Feb 2020 21:17:41 -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=CjAlLRcC; 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 S1726112AbgBYFQU (ORCPT + 99 others); Tue, 25 Feb 2020 00:16:20 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38701 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbgBYFQT (ORCPT ); Tue, 25 Feb 2020 00:16:19 -0500 Received: by mail-pg1-f194.google.com with SMTP id d6so6298256pgn.5 for ; Mon, 24 Feb 2020 21:16:19 -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:mime-version:content-disposition; bh=U6Wt/LenosPR0Sx0SmEySrtroNHk0FTBlW4IV6YiiMg=; b=CjAlLRcClG0VLkuNyIO9/QTuQ1crb4nJN7Ei+88NEFieNYHXTldlqvWRyC3yHQUUo7 Wg/5YaAStuyQ1MJGta9daj7RlBnPIPJ3aReGwAgeNQpWUZdkQTfiKw7DNVpjaHnu4XyE JhqVUYtujl/gVANQ91Gq143qIqyFwJLLxHKEI= 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:mime-version :content-disposition; bh=U6Wt/LenosPR0Sx0SmEySrtroNHk0FTBlW4IV6YiiMg=; b=aNwyx2TvKf7IY6Uldo74qdBPHXjAAjeJdG0fBE0Fi7KwRprUMYAzpaiuW79V5Y5hR/ jrdR79YI1cHf31R7h6VxCFCl1Z+wi5G1FOJGe18DtUgsZWW72BQZYvwz1x4UyvDwiZ5B 4gzveNTavHOIVJv+LSolavg3RXLNVTrt305w9maRKYOh2RJCBiA4XnWvYKVAVtsEmY1r v9I4znBTQDYMcmh6vwGQkDoU/B1IuSDJ3Z0P6Mv0D9QSr3YSnuKVtACwY2rZIidoHKH6 F9wnpUfNzrOhDhF5OCFQF8nqNNSQxvGnbDGl/pqvOrmUYLrhRM5A0XeAfILY3++E2hLz VsAQ== X-Gm-Message-State: APjAAAWM0ihFCfVrpwUqxuUFcG22scbFXKtCI/MeacSWlys2Hv6o64rq oTD+KEYra0glHWPCkPVX1Z8a9A== X-Received: by 2002:a63:8e44:: with SMTP id k65mr11985018pge.452.1582607778850; Mon, 24 Feb 2020 21:16:18 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r13sm1169792pjp.14.2020.02.24.21.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 21:16:18 -0800 (PST) Date: Mon, 24 Feb 2020 21:16:17 -0800 From: Kees Cook To: Masahiro Yamada Cc: Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] kbuild: Remove debug info from kallsyms linking Message-ID: <202002242114.CBED7F1@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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