From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8739 Path: news.gmane.org!not-for-mail From: Denys Vlasenko Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] configure: add gcc flags for better link-time optimization Date: Fri, 23 Oct 2015 14:30:26 +0200 Message-ID: <1445603426-4827-1-git-send-email-vda.linux@googlemail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1445603466 25569 80.91.229.3 (23 Oct 2015 12:31:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Oct 2015 12:31:06 +0000 (UTC) Cc: Denys Vlasenko , musl To: Rich Felker Original-X-From: musl-return-8752-gllmg-musl=m.gmane.org@lists.openwall.com Fri Oct 23 14:30:57 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 1ZpbUZ-0000uO-SR for gllmg-musl@m.gmane.org; Fri, 23 Oct 2015 14:30:43 +0200 Original-Received: (qmail 11929 invoked by uid 550); 23 Oct 2015 12:30:42 -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 11909 invoked from network); 23 Oct 2015 12:30:41 -0000 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Xref: news.gmane.org gmane.linux.lib.musl.general:8739 Archived-At: libc.so size reduction: text data bss dec hex filename 564099 1944 11768 577811 8d113 libc.so.before 562277 1924 11576 575777 8c921 libc.so Signed-off-by: Denys Vlasenko CC: musl --- configure | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/configure b/configure index 4564ad8..a9ed159 100755 --- a/configure +++ b/configure @@ -440,6 +440,44 @@ tryflag CFLAGS_AUTO -fno-unwind-tables tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables # +# When linker merges sections, a tiny section (such as one resulting +# from "static char flag_var") with no alignment restrictions +# can end up logded between two more strongly aligned ones (say, +# "static int global_cnt1/2", both of which want 32-bit alignment). +# Then this byte-sized "flag_var" gets 3 bytes of padding. +# +# With section sorting by alignment, one-byte flag variables have +# higher chance of being grouped together and not require padding. +# (It can be made even better. Linker is too dumb. +# ld needs to grow -Wl,--pack-sections-optimally) +# +# For us, this affects the size of only one file: libc.so +# +tryldflag LDFLAGS_AUTO -Wl,--sort-section=alignment +tryldflag LDFLAGS_AUTO -Wl,--sort-common + +# +# 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 + +# # The GNU toolchain defaults to assuming unmarked files need an # executable stack, potentially exposing vulnerabilities in programs # linked with such object files. Fix this. -- 1.8.1.4