From patchwork Fri Oct 29 11:46:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 69574 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]) by ozlabs.org (Postfix) with SMTP id 21665B70E0 for ; Fri, 29 Oct 2010 22:47:22 +1100 (EST) Received: (qmail 13960 invoked by alias); 29 Oct 2010 11:47:19 -0000 Received: (qmail 13862 invoked by uid 22791); 29 Oct 2010 11:47:16 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (213.235.205.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Oct 2010 11:47:04 +0000 Received: from basil.firstfloor.org (p5B3C9619.dip0.t-ipconnect.de [91.60.150.25]) by one.firstfloor.org (Postfix) with ESMTP id 892F01A98052; Fri, 29 Oct 2010 13:47:00 +0200 (CEST) Received: by basil.firstfloor.org (Postfix, from userid 1000) id CE134B1574; Fri, 29 Oct 2010 13:46:59 +0200 (CEST) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/2] Add gcc-ar, gcc-ranlib, gcc-ld wrappers Date: Fri, 29 Oct 2010 13:46:57 +0200 Message-Id: <1288352817-24819-3-git-send-email-andi@firstfloor.org> In-Reply-To: <1288352817-24819-2-git-send-email-andi@firstfloor.org> References: <1288352817-24819-1-git-send-email-andi@firstfloor.org> <1288352817-24819-2-git-send-email-andi@firstfloor.org> 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 From: Andi Kleen Earlier review resulted in a request for having gcc-... wrappers to handle the LTO symbol tables for ranlib/ar. This is needed for slim lto files, because these tools cannot read the symbol table otherwise. Essentially they just call binutils with the LTO plugin specified. Other compilers with LTO support tend to have similar tools. This patch implements those wrappers. I also added a wrapper for ld because I needed one for a large existing Makefile with a lot of complicated ld calls. It turns an ld command line into a gcc command line suitable for lto. The wrappers are also needed for a LTO slim of gcc. Right now they have to be manually specified for that. The wrappers require uptodate binutils (the upcoming release) with plugin support enabled. There is currently no autoconf support to detect that. The wrappers query the gcc driver in an attempt to handle cross compilation and so naming everywhere. gcc/lto/ 2010-10-26 Andi Kleen * Make-lang.in (AR_INSTALL_NAME, RANLIB_INSTALL_NAME, LD_INSTALL_NAME, LTO_WRAPPERS): Add. (lto.all.cross, lto.start.cross): Add dependency to LTO_WRAPPERS. (lto.install.common): Install wrappers. (lto.mostlyclean): Clean wrappers. (gcc-ar, gcc-ranlib, gcc-ld): Add. * config-lang.in (outputs): Add. * gcc-ar.in, gcc-ld.in, gcc-ranlib.in: Add. gcc/ 2010-10-26 Andi Kleen * doc/invoke.texi (gcc-ar, gcc-ld, gcc-ranlib): Document. --- gcc/doc/invoke.texi | 5 ++++ gcc/lto/Make-lang.in | 31 +++++++++++++++++++++++++++-- gcc/lto/config-lang.in | 2 + gcc/lto/gcc-ar.in | 8 +++++++ gcc/lto/gcc-ld.in | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ gcc/lto/gcc-ranlib.in | 8 +++++++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 gcc/lto/gcc-ar.in create mode 100644 gcc/lto/gcc-ld.in create mode 100644 gcc/lto/gcc-ranlib.in diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d6784ad..0810e77 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7565,6 +7565,11 @@ be exported, it is possible to combine @option{-flto} and interprocedural optimizers to use more aggressive assumptions which may lead to improved optimization opportunities. +In some cases you may need to use the @command{gcc-ar} and +@command{gcc-ranlib} commands to manage ar files of LTO objects. +@command{gcc-ld} can be also used to turn a @command{ld} command +line into one suitable for LTO. + Regarding portability: the current implementation of LTO makes no attempt at generating bytecode that can be ported between different types of hosts. The bytecode files are versioned and there is a diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in index 2dc6409..55fb83a 100644 --- a/gcc/lto/Make-lang.in +++ b/gcc/lto/Make-lang.in @@ -28,16 +28,31 @@ LTO_H = lto/lto.h $(HASHTAB_H) LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h LTO_TREE_H = lto/lto-tree.h $(LINKER_PLUGIN_API_H) +AR_INSTALL_NAME := $(shell echo gcc-ar|sed '$(program_transform_name)') +RANLIB_INSTALL_NAME := $(shell echo gcc-ranlib|sed '$(program_transform_name)') +LD_INSTALL_NAME := $(shell echo gcc-ld|sed '$(program_transform_name)') + +ifeq ($(enable_plugin),yes) +LTO_WRAPPERS = lto/gcc-ar lto/gcc-ld lto/gcc-ranlib +else +LTO_WRAPPERS = +endif # Rules # These hooks are used by the main GCC Makefile. Consult that # Makefile for documentation. -lto.all.cross: $(LTO_EXE) -lto.start.encap: $(LTO_EXE) +lto.all.cross: $(LTO_EXE) $(LTO_WRAPPERS) +lto.start.encap: $(LTO_EXE) $(LTO_WRAPPERS) lto.rest.encap: lto.tags: lto.install-common: +ifeq ($(enable_plugin),yes) + $(INSTALL_SCRIPT) lto/gcc-ar $(DESTDIR)$(bindir)/$(AR_INSTALL_NAME) + $(INSTALL_SCRIPT) lto/gcc-ld $(DESTDIR)$(bindir)/$(LD_INSTALL_NAME) + $(INSTALL_SCRIPT) lto/gcc-ranlib $(DESTDIR)$(bindir)/$(RANLIB_INSTALL_NAME) +endif + lto.install-man: lto.install-info: lto.dvi: @@ -54,7 +69,7 @@ lto.srcinfo: lto.install-plugin: lto.mostlyclean: - rm -f $(LTO_OBJS) $(LTO_EXE) + rm -f $(LTO_OBJS) $(LTO_EXE) lto/gcc-ar lto/gcc-ranlib lto/gcc-ld lto.clean: lto.distclean: @@ -75,6 +90,16 @@ $(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIBDEPS) +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ $(LTO_OBJS) $(BACKEND) $(BACKENDLIBS) $(LIBS) $(LTO_USE_LIBELF) +# generate plugin calling toolchain wrappers +lto/gcc-ar: lto/gcc-ar.in + CONFIG_FILES=lto/gcc-ar CONFIG_HEADERS= ./config.status + +lto/gcc-ranlib: lto/gcc-ranlib.in + CONFIG_FILES=lto/gcc-ranlib CONFIG_HEADERS= ./config.status + +lto/gcc-ld: lto/gcc-ld.in + CONFIG_FILES=lto/gcc-ld CONFIG_HEADERS= ./config.status + # Dependencies lto/lto-lang.o: lto/lto-lang.c $(CONFIG_H) coretypes.h debug.h \ flags.h $(GGC_H) langhooks.h $(LANGHOOKS_DEF_H) $(SYSTEM_H) \ diff --git a/gcc/lto/config-lang.in b/gcc/lto/config-lang.in index 72ed2dd..c125408 100644 --- a/gcc/lto/config-lang.in +++ b/gcc/lto/config-lang.in @@ -33,3 +33,5 @@ build_by_default=no # Add LTO to boot language if it is enabled. boot_language=$enable_lto + +outputs="lto/gcc-ar lto/gcc-ld lto/gcc-ranlib" diff --git a/gcc/lto/gcc-ar.in b/gcc/lto/gcc-ar.in new file mode 100644 index 0000000..6246446 --- /dev/null +++ b/gcc/lto/gcc-ar.in @@ -0,0 +1,8 @@ +#!/bin/sh +# wrapper for ar with GCC LTO support +prefix=@prefix@ +exec_prefix=@exec_prefix@ +GCC_BINDIR=${GCC_LIBEXEC:-@bindir@} +AR=${AR:-`$GCC_BINDIR/gcc -print-prog-name=ar`} + +exec $AR --plugin `$GCC_BINDIR/gcc -print-lto-plugin` "$@" diff --git a/gcc/lto/gcc-ld.in b/gcc/lto/gcc-ld.in new file mode 100644 index 0000000..f204764 --- /dev/null +++ b/gcc/lto/gcc-ld.in @@ -0,0 +1,49 @@ +#!/bin/sh +# run gcc with ld options +# used as a wrapper to execute link time optimizations for +# makefiles that want to call the linker directly +# this runs ld or gold as needed + +ARGS="" +R="" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +GCC=${GCCBINDIR:-@bindir@}/gcc + +while test "x$1" != "x" ; do + case "$1" in + -r) R=1 + N="$1" + ;; + -[olvO]|-f*|-nostdlib) + N="$1" + ;; + --end-group|--start-group) + N="-Wl,$1" + ;; + -[RTFGhIezcbmyYu]*|\ +--script|--defsym|-init|-Map|--oformat|-rpath|\ +-rpath-link|--sort-section|--section-start|-Tbss|-Tdata|-Ttext|\ +--version-script|--dynamic-list|--version-exports-symbol|--wrap) + A="$1" + shift + N="-Wl,$A,$1" + ;; + -*) N="-Wl,$1" + ;; + *) N="$1" + ;; + esac + ARGS="$ARGS $N" + shift +done + +if test "x$R" != "x" ; then + # work around gold bug, -r and -fuse-linker-plugin + # do not interact well. It's not needed anyways. + # the gold bug has been fixed, but still keep this. + ARGS=`echo $ARGS | sed -e s/-fuse-linker-plugin//` +fi + +exec $GCC $ARGS diff --git a/gcc/lto/gcc-ranlib.in b/gcc/lto/gcc-ranlib.in new file mode 100644 index 0000000..4222ae9 --- /dev/null +++ b/gcc/lto/gcc-ranlib.in @@ -0,0 +1,8 @@ +#!/bin/sh +# wrapper for ranlib with GCC LTO support +prefix=@prefix@ +exec_prefix=@exec_prefix@ +GCC_BINDIR=${GCC_BINDIR:-@bindir@} +AR=${AR:-`$GCC_BINDIR/gcc -print-prog-name=ar`} + +exec $AR -s --plugin `$GCC_BINDIR/gcc -print-lto-plugin` "$@"