From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8801 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] configure: add gcc flags for better link-time optimization Date: Sun, 1 Nov 2015 14:56:58 -0500 Message-ID: <20151101195658.GL8645@brightrain.aerifal.cx> References: <1445603426-4827-1-git-send-email-vda.linux@googlemail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1446407850 9594 80.91.229.3 (1 Nov 2015 19:57:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Nov 2015 19:57:30 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8814-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 01 20:57:16 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Zsyke-00027Q-8f for gllmg-musl@m.gmane.org; Sun, 01 Nov 2015 20:57:16 +0100 Original-Received: (qmail 9294 invoked by uid 550); 1 Nov 2015 19:57:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9276 invoked from network); 1 Nov 2015 19:57:11 -0000 Content-Disposition: inline In-Reply-To: <1445603426-4827-1-git-send-email-vda.linux@googlemail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8801 Archived-At: On Fri, Oct 23, 2015 at 02:30:26PM +0200, Denys Vlasenko wrote: > +# > +# Put every function and data object into its own section: > +# .text.funcname, .data.var, .rodata.const_struct, .bss.zerovar > +# > +# Previous optimization isn't working too well by itself > +# because data objects aren't living in separate sections, > +# they are all grouped in one .data and one .bss section per *.o file. > +# With -ffunction/data-sections, section sorting eliminates more padding. > +# > +# Object files in static *.a files will also have their functions > +# and data objects each in its own section. > +# > +# This enables programs statically linked with -Wl,--gc-sections > +# to perform "section garbage collection": drop unused code and data > +# not on per-*.o-file basis, but on per-function and per-object basis. > +# This is a big thing: --gc-sections sometimes eliminates several percent > +# of unreachable code and data in final executable. > +# > +tryflag CFLAGS_AUTO -ffunction-sections > +tryflag CFLAGS_AUTO -fdata-sections > + > +# This is not just an optimization but going to save us from a horrible class of compiler/assembler bugs that threatened to force dropping support for all non-bleeding-edge toolchains: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68178 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66609 https://sourceware.org/bugzilla/show_bug.cgi?id=18561 By putting functions/objects in their own sections, the illegal but widespread assembler 'optimization' of resolving differences between symbols to a constant when one or both of the symbols has a weak definition is suppressed, simply because differences of this form are never constants when they cross sections. As such I want to go ahead and apply this regardless of optimization issues, but I think we should update the comments and commit message to reflect that this is also working around serious toolchain issues. I hope to get to it soon now; working on some other things at the moment. BTW thanks a lot for raising the idea of using these options. If it hadn't been for your pending patch I probably would never have thought of this as a solution to the toolchain problems above. Rich