From patchwork Tue Jul 19 00:39:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 649856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rth5V4GRsz9sC3 for ; Tue, 19 Jul 2016 10:39:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PSYo6uLJ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=ee79jhdUT/Fb1WuA 3pklW/vQHQVQ4A7w+8Dek4cVznOVx9JRFmDy9MFygMn5tzJWRu3Hprm4oxEeaxij WQ6vpvGydRpZiY6mjcogFliGNu4+yBugQKD257Qw4/zxMNZWEn8mEccWI0U9Ggjt ZowyqpCts2w3dxQEcFvxxkR2H0E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=Oy4+n2/ACx4bn8haDfXP5U 0sLbY=; b=PSYo6uLJj+R3ePfuRYlx7jnGEzgXah9W1x58qKae4OU/qOtyegEyeT M4xVrO0b3ZFKrswbnoimubz/GpFnSzPpCcWBodZ9XGrJMfDO2jsNAyoxheQQv/jL aLo0qBZcifzZNWKSdcjqm4xv9XIt2Xw6qwIA7zLoUC1XwYB3GEGpI= Received: (qmail 25243 invoked by alias); 19 Jul 2016 00:39:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25231 invoked by uid 89); 19 Jul 2016 00:39:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=rct, ifeq, AC_SUBST, LINKER X-HELO: mail-qk0-f193.google.com Received: from mail-qk0-f193.google.com (HELO mail-qk0-f193.google.com) (209.85.220.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Jul 2016 00:39:38 +0000 Received: by mail-qk0-f193.google.com with SMTP id q62so267247qkf.2 for ; Mon, 18 Jul 2016 17:39:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=uhXeNFuzbtEBdGmx5qAq8KtzQRwWhwB8Av6ah7X0Kzo=; b=dqrf8A2Lw3CaGTSWktEuuPFOY2W9dAv1VOSK0VQtl8bYoIS67pLwQGrjW0wNCOXrrK YqMCFCfWG4u6aH4J23CBjDsAArxiDcqghBO9OeBXKZLLEbo8Uq1tvVOR96tegl4W5guO 8ApN9ZOebNgqfLu1jtd9Uggm8+JdvTB1Q3n/Cs4oqh63ryXdpT+oak+ozNx5YQgaqtCZ Pf2wohNRkTbcMufxx/HEgu4cAIUDL5yM/8etGj2qeYRC3GsVrrJ4vNAkmVJ5Z2CIGRqp xFr47l3mNq0lqd5cC4/3K0HoQR1zOiIsDDliIYaAtDRRgg9wEr4uaI+xZcJ6dODEyhiI ly/g== X-Gm-Message-State: ALyK8tJ0v7VQGfoOrNN8FUnJFH/8TEoodc7VMuWjM/Wgg+xVVwLtpBMSaQrZAn+6R9qapA== X-Received: by 10.55.3.143 with SMTP id 137mr49175285qkd.154.1468888776481; Mon, 18 Jul 2016 17:39:36 -0700 (PDT) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id n32sm340835qkh.20.2016.07.18.17.39.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2016 17:39:35 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 18 Jul 2016 20:39:34 -0400 (EDT) To: Segher Boessenkool cc: Patrick Palka , David Edelsohn , GCC Patches Subject: Re: [PATCH] Avoid invoking ranlib on libbackend.a In-Reply-To: <20160718124406.GB14108@gate.crashing.org> Message-ID: References: <20160718113511.GA32392@gate.crashing.org> <20160718124406.GB14108@gate.crashing.org> User-Agent: Alpine 2.20.13 (DEB 116 2015-12-14) MIME-Version: 1.0 On Mon, 18 Jul 2016, Segher Boessenkool wrote: > On Mon, Jul 18, 2016 at 06:35:11AM -0500, Segher Boessenkool wrote: > > Or, if using GNU ar, you can even use -S, if that helps (after testing > > for it in configure, of course). > > I meant -T. Some day I will learn how to type, promise! According to the documentation of GNU ar, "gnu ar can optionally create a thin archive, which contains a symbol index and references to the original copies of the member files of the archive. This is useful for building libraries for use within a local build tree, where the relocatable objects are expected to remain available, and copying the contents of each object would only waste time and space." Since the objects which libbackend.a is composed of remain available throughout the build process I think it should be safe to make libbackend.a a thin archive. So here's a patch which builds libbackend.a as a thin archive if the toolchain supports it. The time it takes to rebuild a --disable-bootstrap tree after touching a single source file is now 7.5s instead of 35+s -- a much better speedup than when simply eliding the call to ranlib since the archive is now 1-5MB in size instead of 450MB. Instead of changing AR_FLAGS, only the invocation of ar on libbackend.a is changed because that is by far the largest archive (by a factor of 20x) and it seems less risky this way. One thing that was not clear to me is whether the object file paths stored in a thin archive are relative or absolute paths. If they are absolute paths then that would be a problem due to how the build system moves build directories in between stages (gcc/ -> prev-gcc/ etc). But it looks like the object file paths are relative to the location of the archive which is compatible. Bootstrapped on x86_64-pc-linux-gnu. Thoughts? -- >8 -- Subject: [PATCH] Build libbackend.a as a thin archive if possible gcc/ChangeLog: * configure.ac (thin_archive_support): New variable. AC_SUBST it. * configure: Regenerate. * Makefile.in (THIN_ARCHIVE_SUPPORT): New variable. (USE_THIN_ARCHIVES): New variable. (libbackend.a): If USE_THIN_ARCHIVES then pass T to ar to build this archive as a thin archive. --- gcc/Makefile.in | 17 +++++++++++++++++ gcc/configure | 20 ++++++++++++++++++-- gcc/configure.ac | 13 +++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 0786fa3..15a879b 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -275,6 +275,17 @@ else LLINKER = $(LINKER) endif +THIN_ARCHIVE_SUPPORT = @thin_archive_support@ + +USE_THIN_ARCHIVES = no +ifeq ($(THIN_ARCHIVE_SUPPORT),yes) +ifeq ($(AR_FLAGS),rc) +ifeq ($(RANLIB_FLAGS),) +USE_THIN_ARCHIVES = yes +endif +endif +endif + # ------------------------------------------- # Programs which operate on the build machine # ------------------------------------------- @@ -1882,8 +1893,14 @@ compilations: $(BACKEND) # This archive is strictly for the host. libbackend.a: $(OBJS) -rm -rf libbackend.a + @# Build libbackend.a as a thin archive if possible, as doing so + @# significantly reduces build times. +ifeq ($(USE_THIN_ARCHIVES),yes) + $(AR) $(AR_FLAGS)T libbackend.a $(OBJS) +else $(AR) $(AR_FLAGS) libbackend.a $(OBJS) -$(RANLIB) $(RANLIB_FLAGS) libbackend.a +endif libcommon-target.a: $(OBJS-libcommon-target) -rm -rf libcommon-target.a diff --git a/gcc/configure b/gcc/configure index ed44472..81c81b3 100755 --- a/gcc/configure +++ b/gcc/configure @@ -679,6 +679,7 @@ zlibinc zlibdir HOST_LIBS enable_default_ssp +thin_archive_support libgcc_visibility gcc_cv_readelf gcc_cv_objdump @@ -18475,7 +18476,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18478 "configure" +#line 18479 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18581,7 +18582,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18584 "configure" +#line 18585 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -27846,6 +27847,21 @@ $as_echo "#define HAVE_AS_LINE_ZERO 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking support for thin archives" >&5 +$as_echo_n "checking support for thin archives... " >&6; } +thin_archive_support=no +echo 'int main (void) { return 0; }' > conftest.c +if ($AR --version | sed 1q | grep "GNU ar" \ + && $CC $CFLAGS -c conftest.c \ + && $AR rcT conftest.a conftest.o \ + && $CC -o conftest conftest.a) >/dev/null 2>&1; then + thin_archive_support=yes +fi +rm -f conftest.c conftest.o conftest.a conftest +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $thin_archive_support" >&5 +$as_echo "$thin_archive_support" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker PT_GNU_EH_FRAME support" >&5 $as_echo_n "checking linker PT_GNU_EH_FRAME support... " >&6; } gcc_cv_ld_eh_frame_hdr=no diff --git a/gcc/configure.ac b/gcc/configure.ac index 086d0fc..63052ba 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4899,6 +4899,19 @@ if test "x$gcc_cv_as_line_zero" = xyes; then [Define if the assembler won't complain about a line such as # 0 "" 2.]) fi +AC_MSG_CHECKING(support for thin archives) +thin_archive_support=no +echo 'int main (void) { return 0; }' > conftest.c +if ($AR --version | sed 1q | grep "GNU ar" \ + && $CC $CFLAGS -c conftest.c \ + && $AR rcT conftest.a conftest.o \ + && $CC -o conftest conftest.a) >/dev/null 2>&1; then + thin_archive_support=yes +fi +rm -f conftest.c conftest.o conftest.a conftest +AC_MSG_RESULT($thin_archive_support) +AC_SUBST(thin_archive_support) + AC_MSG_CHECKING(linker PT_GNU_EH_FRAME support) gcc_cv_ld_eh_frame_hdr=no if test $in_tree_ld = yes ; then