Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp654944pxb; Thu, 25 Feb 2021 11:30:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcAzsfcAAIXxfa9IwUYPuEBcL2Xy56AvIAzhitBLTaC9ZUj1SWJCAIU3cXvw6+Y5cosskO X-Received: by 2002:aa7:c717:: with SMTP id i23mr4563308edq.81.1614281419334; Thu, 25 Feb 2021 11:30:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614281419; cv=none; d=google.com; s=arc-20160816; b=NX+3d88qiec1/4uk4iJJf0YGycmF26buiaJmzomlTf4uE7PmFD1ilsQ29ZAwC41LFd GiBqGtlYADZtggDYHhb/oWaNCXbHkyf3X8t/301rZgbFuNSkKPflVdk1HJF9H3GqwC7E N/xMO9oFbo+5iPXS2KcyWbFIxovTDDyIzAkFudVR+SFuMB7HWW7YiQjUcFfPTxyrXAnf cWa7u90h4zV4beIG/9WxLYuGtUcuDVdvlyYvN5jk9KzNtlXqHpbXVCvx5NhPr6EVH4i2 q20dM4WFzOpaT2m+wYdkJOmQ/ahpmf1vuoLe+BTBHmhvcMJb8745lkQWoM18LV+Bkex9 81yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=jXSaUR/xi2n0/gPdP2+clcF7RYooGztNntOqXiwEAn4=; b=NaQh8bkC9mtXPl17ORkMYne1aSxhtSqwjmUckLQ5yi7vJX9GO+kdRn0MKNjcPnLAiy XvQpbtmI0crgag7VSmMVzmDW9xKUhjro+tnug8oJ9uCzM7lvLFQ7jLhuRGhY2XevOZqo hXmLJXvW4rvU7X+n+KFnFph3/6aJNGVwoaa9wra8FJgT1QHoOx5SCUMLI4vg3/UAWm0A hui6euhe1tlocAv1BpmTypMZhhO7c2rPWP6TNvVK8mJ7Wu1prer6MDmF95IYUR1N1K+n l/1sbpOVKqtZB1pb3Q5fgb8Cc+46DV76NIqQAgjWl+lswYEUMTpv+rtTlZ3B6Q5RioUT FzJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=tXx7qXBA; dkim=pass header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=fe30QbMo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr20si3705226ejc.23.2021.02.25.11.29.56; Thu, 25 Feb 2021 11:30:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=tXx7qXBA; dkim=pass header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=fe30QbMo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234635AbhBYT2E (ORCPT + 99 others); Thu, 25 Feb 2021 14:28:04 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:54574 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbhBYTZh (ORCPT ); Thu, 25 Feb 2021 14:25:37 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 9D580B0DA2; Thu, 25 Feb 2021 14:24:47 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:in-reply-to:message-id:references:mime-version :content-type; s=sasl; bh=uSGDWbeu4QMXFL3jz4yLuixZbF0=; b=tXx7qX BARdHwAJ75iVXzgZlY6u4vpDfGdSZ6r5bPhjtks4bGNrErpsxE8fj2AyvWEqCuIb 4d3jL41jhETZ4N7zRJeVZV+J3J0D86r5cyMRB/yhLlhUfKiH1q5prStUh74QR3w3 XPCvDl1iVEbJtRBA/1rq+K6rgVJ1g8drG0nCU= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 921DEB0DA1; Thu, 25 Feb 2021 14:24:47 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:in-reply-to:message-id:references:mime-version:content-type; s=2016-12.pbsmtp; bh=Ysam7wogkyEXkA86e6mQ/AkpZlWP1KiBxHidywtJQ1U=; b=fe30QbMoPbpvOPzZjlkywaicUYMfC2C4XrgufMymzkfdY8ANd6Kns/Obkc/IjnZJ8EqmuA30/aPhWzVPKbeLATRRRZ7wI2KgmBFVB/fEXDco209bZHneRrIbFO3A2Lg2cVaengsq2mJ7GzPBEewFFANRVg24I6SOsRya7lwi2YE= Received: from yoda.home (unknown [24.203.50.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 088CFB0DA0; Thu, 25 Feb 2021 14:24:47 -0500 (EST) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTPSA id 12C962DA0082; Thu, 25 Feb 2021 14:24:46 -0500 (EST) Date: Thu, 25 Feb 2021 14:24:45 -0500 (EST) From: Nicolas Pitre To: Masahiro Yamada cc: Linux Kbuild mailing list , Christoph Hellwig , Linus Torvalds , Jessica Yu , Sami Tolvanen , Linux Kernel Mailing List , linux-arch Subject: Re: [PATCH 0/4] kbuild: build speed improvment of CONFIG_TRIM_UNUSED_KSYMS In-Reply-To: Message-ID: <46506ns0-1477-n7nq-9qq4-9pn48634oq4@syhkavp.arg> References: <20210225160247.2959903-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: 1F1ECEFE-779F-11EB-BCD7-D152C8D8090B-78420484!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 26 Feb 2021, Masahiro Yamada wrote: > On Fri, Feb 26, 2021 at 2:20 AM Nicolas Pitre wrote: > > > > On Fri, 26 Feb 2021, Masahiro Yamada wrote: > > > > > > > > Now CONFIG_TRIM_UNUSED_KSYMS is revived, but Linus is still unhappy > > > about the build speed. > > > > > > I re-implemented this feature, and the build time cost is now > > > almost unnoticeable level. > > > > > > I hope this makes Linus happy. > > > > :-) > > > > I'm surprised to see that Linus is using this feature. When disabled > > (the default) this should have had no impact on the build time. > > Linus is not using this feature, but does build tests. > After pulling the module subsystem pull request in this merge window, > CONFIG_TRIM_UNUSED_KSYMS was enabled by allmodconfig. If CONFIG_TRIM_UNUSED_KSYMS is enabled then build time willincrease. That comes with the feature. > > This feature provides a nice security advantage by significantly > > reducing the kernel input surface. And people are using that also to > > better what third party vendor can and cannot do with a distro kernel, > > etc. But that's not the reason why I implemented this feature in the > > first place. > > > > My primary goal was to efficiently reduce the kernel binary size using > > LTO even with kernel modules enabled. > > > Clang LTO landed in this MW. > > Do you think it will reduce the kernel binary size? > No, opposite. LTO ought to reduce binary size. It is rather broken otherwise. Having a global view before optimizing allows for the compiler to do project wide constant propagation and dead code elimination. > CONFIG_LTO_CLANG cannot trim any code even if it > is obviously unused. > Hence, it never reduces the kernel binary size. > Rather, it produces a bigger kernel. Then what's the point? > The reason is Clang LTO was implemented against > relocatable ELF (vmlinux.o) . That's not true LTO then. > I pointed out this flaw in the review process, but > it was dismissed. > > This is the main reason why I did not give any Ack > (but it was merged via Kees Cook's tree). > So, the help text of this option should be revised: > > This option allows for unused exported symbols to be dropped from > the build. In turn, this provides the compiler more opportunities > (especially when using LTO) for optimizing the code and reducing > binary size. This might have some security advantages as well. > > Clang LTO is opposite to your expectation. Then Clang LTO is a misnomer. That is the option to revise not this one. > > Each EXPORT_SYMBOL() created a > > symbol dependency that prevented LTO from optimizing out the related > > code even though a tiny fraction of those exported symbols were needed. > > > > The idea behind the recursion was to catch those cases where disabling > > an exported symbol within a module would optimize out references to more > > exported symbols that, in turn, could be disabled and possibly trigger > > yet more code elimination. There is no way that can be achieved without > > extra compiler passes in a recursive manner. > > I do not understand. > > Modules are relocatable ELF. > Clang LTO cannot eliminate any code. > GCC LTO does not work with relocatable ELF > in the first place. I don't think I follow you here. What relocatable ELF has to do with LTO? I've successfully used gcc LTO on the kernel quite a while ago. For a reference about binary size reduction with LTO and CONFIG_TRIM_UNUSED_KSYMS please read this article: https://lwn.net/Articles/746780/ Nicolas