From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicholas Piggin Subject: Re: [PATCH 2/5] kbuild: allow archs to select build for link dead code/data elimination Date: Mon, 8 Aug 2016 13:42:35 +1000 Message-ID: <20160808134235.6f20eacb@roar.ozlabs.ibm.com> References: <1470399123-8455-1-git-send-email-npiggin@gmail.com> <1470399123-8455-3-git-send-email-npiggin@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-kbuild-owner@vger.kernel.org To: Nicolas Pitre Cc: linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Stephen Rothwell , Arnd Bergmann , Segher Boessenkool , Alan Modra List-Id: linux-arch.vger.kernel.org On Sun, 7 Aug 2016 01:33:45 -0400 (EDT) Nicolas Pitre wrote: > On Fri, 5 Aug 2016, Nicholas Piggin wrote: > > > Introduce LINKER_DCE option for architectures to select if they want > > to build with -ffunction-sections, -fdata-sections, and link with > > --gc-sections. It requires some work (documented) to ensure all > > unreferenced entrypoints are live, and requires toolchain and > > build verification, so it is made a per-arch option for now. > > > > On a random powerpc64le build, this yelds a significant size saving, > > it boots and runs fine, but there is a lot I haven't tested as yet, > > so these savings may be reduced if there are bugs in the link. > > > > text data bss dec filename > > 11169741 1180744 1923176 14273661 vmlinux > > 10445269 1004127 1919707 13369103 vmlinux.dce > > > > ~700K text, ~170K data, 6% removed from kernel image size. > > > > Signed-off-by: Nicholas Piggin > > I played with that too. However this needs distinct sections for > exception tables and the like otherwise the backward references from the > final exception table to those functions responsible for those exception > entries has the effect of pulling in all those functions even if their > entry point is never referenced, making --gc-sections less effective. > I managed to fix this only with a change to gas (accepted upstream). > > But once that is solved, you then have the missing forward reference > problem i.e. nothing actually references those individual exception > entry sections and ld happily drops them all. Having a KEEP() on each of > them is unworkable and defeats the purpose anyway. That requires a > dummy reloc to trick ld into pulling in those sections when the parent > section is also pulled in. Right, although we don't *need* those things just for enabling --gc-sections, do we? It may not be 100% optimal, but it's enough to avoid the regression when switching to --whole-archive build option. > Please see attached a subset of the slides I presented at ELC and Linaro > Connect last year to illustrate those issues. > > Also attached a sample patch partially implementing those changes. > > In short I'm very glad to see that this might steer interest across > multiple architectures. I felt like this was becoming much more > intrusive than I expected and that maybe LTO was a better bet after all. > But LTO has its evils too and I'm willing to look at gc-sections again > if there is interest from others as well. Your results are impressive, and I don't want to stand in the way of either LTO or improving accuracy of --gc-sections. But both are things that can be built on top of this patch, I think. We don't need to do the entire intrusive changes all at once. Thanks, Nick From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:32781 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbcHHDmo (ORCPT ); Sun, 7 Aug 2016 23:42:44 -0400 Date: Mon, 8 Aug 2016 13:42:35 +1000 From: Nicholas Piggin Subject: Re: [PATCH 2/5] kbuild: allow archs to select build for link dead code/data elimination Message-ID: <20160808134235.6f20eacb@roar.ozlabs.ibm.com> In-Reply-To: References: <1470399123-8455-1-git-send-email-npiggin@gmail.com> <1470399123-8455-3-git-send-email-npiggin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Nicolas Pitre Cc: linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Stephen Rothwell , Arnd Bergmann , Segher Boessenkool , Alan Modra Message-ID: <20160808034235.QBtKvOusB56DXyhsj-LzlvLAFYkRnkEvy8rHYo4Bc2g@z> On Sun, 7 Aug 2016 01:33:45 -0400 (EDT) Nicolas Pitre wrote: > On Fri, 5 Aug 2016, Nicholas Piggin wrote: > > > Introduce LINKER_DCE option for architectures to select if they want > > to build with -ffunction-sections, -fdata-sections, and link with > > --gc-sections. It requires some work (documented) to ensure all > > unreferenced entrypoints are live, and requires toolchain and > > build verification, so it is made a per-arch option for now. > > > > On a random powerpc64le build, this yelds a significant size saving, > > it boots and runs fine, but there is a lot I haven't tested as yet, > > so these savings may be reduced if there are bugs in the link. > > > > text data bss dec filename > > 11169741 1180744 1923176 14273661 vmlinux > > 10445269 1004127 1919707 13369103 vmlinux.dce > > > > ~700K text, ~170K data, 6% removed from kernel image size. > > > > Signed-off-by: Nicholas Piggin > > I played with that too. However this needs distinct sections for > exception tables and the like otherwise the backward references from the > final exception table to those functions responsible for those exception > entries has the effect of pulling in all those functions even if their > entry point is never referenced, making --gc-sections less effective. > I managed to fix this only with a change to gas (accepted upstream). > > But once that is solved, you then have the missing forward reference > problem i.e. nothing actually references those individual exception > entry sections and ld happily drops them all. Having a KEEP() on each of > them is unworkable and defeats the purpose anyway. That requires a > dummy reloc to trick ld into pulling in those sections when the parent > section is also pulled in. Right, although we don't *need* those things just for enabling --gc-sections, do we? It may not be 100% optimal, but it's enough to avoid the regression when switching to --whole-archive build option. > Please see attached a subset of the slides I presented at ELC and Linaro > Connect last year to illustrate those issues. > > Also attached a sample patch partially implementing those changes. > > In short I'm very glad to see that this might steer interest across > multiple architectures. I felt like this was becoming much more > intrusive than I expected and that maybe LTO was a better bet after all. > But LTO has its evils too and I'm willing to look at gc-sections again > if there is interest from others as well. Your results are impressive, and I don't want to stand in the way of either LTO or improving accuracy of --gc-sections. But both are things that can be built on top of this patch, I think. We don't need to do the entire intrusive changes all at once. Thanks, Nick