From patchwork Thu Dec 2 23:58:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 74077 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 E4C76B70AF for ; Fri, 3 Dec 2010 10:59:19 +1100 (EST) Received: (qmail 16487 invoked by alias); 2 Dec 2010 23:59:12 -0000 Received: (qmail 16476 invoked by uid 22791); 2 Dec 2010 23:59:09 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Dec 2010 23:58:56 +0000 Received: by qyk8 with SMTP id 8so162686qyk.20 for ; Thu, 02 Dec 2010 15:58:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.224.80.202 with SMTP id u10mr618983qak.65.1291334334299; Thu, 02 Dec 2010 15:58:54 -0800 (PST) Received: by 10.220.61.13 with HTTP; Thu, 2 Dec 2010 15:58:54 -0800 (PST) In-Reply-To: <4CF825E4.1080005@gnu.org> References: <4CF825E4.1080005@gnu.org> Date: Thu, 2 Dec 2010 15:58:54 -0800 Message-ID: Subject: Re: Add gcc-ar, gcc-nm, gcc-ranlib From: "H.J. Lu" To: Paolo Bonzini Cc: Andi Kleen , Ralf Wildenhues , gcc-patches@gcc.gnu.org, Andi Kleen X-IsSubscribed: yes 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 On Thu, Dec 2, 2010 at 3:04 PM, Paolo Bonzini wrote: >> --- /dev/null >> +++ b/gcc/lto/gcc-ar.in >> @@ -0,0 +1,18 @@ >> +#!/bin/sh >> +# wrapper for ar with GCC LTO support >> +# requires binutils 2.21+ >> + >> +BASE=`readlink -f $0` > > Portable? > >> +BINDIR=`dirname $BASE` >> + >> +if [ -x "$BINDIR/xgcc" ] ; then >> +     GCC=xgcc >> +     ARG=-B$BINDIR >> +else >> +     GCC=gcc >> +     ARG= >> +fi >> + >> +AR=${AR:-`"$BINDIR/$GCC" -print-prog-name=ar`} >> + >> +exec $AR --plugin `$BINDIR/$GCC $ARG -print-prog-name=@LTOPLUGINSONAME@` "$@" > > Missing quotes around $AR, $BINDIR/$GCC and @LTOPLUGINSONAME@. > >> +NM=${NM:-`"$BINDIR/$GCC" -print-prog-name=nm`} >> + >> +exec $NM --plugin `$BINDIR/$GCC $ARG -print-prog-name=@LTOPLUGINSONAME@` "$@" > > Likewise. > >> +AR=${AR:-`"$BINDIR/$GCC" -print-prog-name=ar`} >> + >> +exec $AR -s --plugin `$BINDIR/$GCC $ARG -print-prog-name=@LTOPLUGINSONAME@` "$@" > > Likewise. Done. > Mentions of the script in the docs would need to say that they are > scripts and so they are not necessarily available on non-POSIX > platforms.  Give the amount of duplication, it would probably have > been easiest to do in C, I still believe. We already have exec-tool.in. I don't believe new ones make it much worse. Here is the updated patch. diff --git a/gcc/configure b/gcc/configure index e1866a4..394115e 100755 --- a/gcc/configure +++ b/gcc/configure @@ -670,6 +670,7 @@ subdirs slibdir dollar gcc_tooldir +LTOPLUGINSONAME enable_lto MAINT zlibinc @@ -17286,7 +17287,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17289 "configure" +#line 17290 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -17392,7 +17393,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17395 "configure" +#line 17396 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -25691,6 +25692,14 @@ $as_echo "#define ENABLE_LTO 1" >>confdefs.h enable_lto=yes + LTOPLUGINSONAME="${host_lto_plugin_soname}" + + ac_config_files="$ac_config_files lto/gcc-ar:lto/lto-tools.in" + + ac_config_files="$ac_config_files lto/gcc-nm:lto/lto-tools.in" + + ac_config_files="$ac_config_files lto/gcc-ranlib:lto/lto-tools.in" + ;; *) ;; esac @@ -26769,6 +26778,9 @@ do "as") CONFIG_FILES="$CONFIG_FILES as:exec-tool.in" ;; "collect-ld") CONFIG_FILES="$CONFIG_FILES collect-ld:exec-tool.in" ;; "nm") CONFIG_FILES="$CONFIG_FILES nm:exec-tool.in" ;; + "lto/gcc-ar") CONFIG_FILES="$CONFIG_FILES lto/gcc-ar:lto/lto-tools.in" ;; + "lto/gcc-nm") CONFIG_FILES="$CONFIG_FILES lto/gcc-nm:lto/lto-tools.in" ;; + "lto/gcc-ranlib") CONFIG_FILES="$CONFIG_FILES lto/gcc-ranlib:lto/lto-tools.in" ;; "$all_outputs") CONFIG_FILES="$CONFIG_FILES $all_outputs" ;; "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; @@ -27352,6 +27364,9 @@ $as_echo "$as_me: executing $ac_file commands" >&6;} "as":F) chmod +x as ;; "collect-ld":F) chmod +x collect-ld ;; "nm":F) chmod +x nm ;; + "lto/gcc-ar":F) chmod +x lto/gcc-ar ;; + "lto/gcc-nm":F) chmod +x lto/gcc-nm ;; + "lto/gcc-ranlib":F) chmod +x lto/gcc-ranlib ;; "default":C) case ${CONFIG_HEADERS} in *auto-host.h:config.in*) diff --git a/gcc/configure.ac b/gcc/configure.ac index dace19c..43e1f83 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4474,6 +4474,11 @@ changequote([,])dnl AC_DEFINE(ENABLE_LTO, 1, [Define to enable LTO support.]) enable_lto=yes AC_SUBST(enable_lto) + LTOPLUGINSONAME="${host_lto_plugin_soname}" + AC_SUBST(LTOPLUGINSONAME) + AC_CONFIG_FILES(lto/gcc-ar:lto/lto-tools.in, [chmod +x lto/gcc-ar]) + AC_CONFIG_FILES(lto/gcc-nm:lto/lto-tools.in, [chmod +x lto/gcc-nm]) + AC_CONFIG_FILES(lto/gcc-ranlib:lto/lto-tools.in, [chmod +x lto/gcc-ranlib]) ;; *) ;; esac diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 94e8160..5fe4bd8 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7610,6 +7610,10 @@ lead to improved optimization opportunities. Use of @option{-fwhole-program} is not needed when linker plugin is active (see @option{-fuse-linker-plugin}). +In some cases, you may need to use the @command{gcc-ar}, +@command{gcc-nm} and @command{gcc-ranlib} commands to manage LTO +object files. + 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 16b0f35..ae448b0 100644 --- a/gcc/lto/Make-lang.in +++ b/gcc/lto/Make-lang.in @@ -28,16 +28,32 @@ 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)') +NM_INSTALL_NAME := $(shell echo gcc-nm|sed '$(program_transform_name)') +RANLIB_INSTALL_NAME := $(shell echo gcc-ranlib|sed '$(program_transform_name)') + +ifeq ($(enable_plugin),yes) +LTO_WRAPPERS = lto/gcc-ar lto/gcc-nm 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) + $(mkinstalldirs) $(DESTDIR)$(bindir) + $(INSTALL_SCRIPT) lto/gcc-ar $(DESTDIR)$(bindir)/$(AR_INSTALL_NAME) + $(INSTALL_SCRIPT) lto/gcc-nm $(DESTDIR)$(bindir)/$(NM_INSTALL_NAME) + $(INSTALL_SCRIPT) lto/gcc-ranlib $(DESTDIR)$(bindir)/$(RANLIB_INSTALL_NAME) +endif + lto.install-man: lto.install-info: lto.dvi: diff --git a/gcc/lto/lto-tools.in b/gcc/lto/lto-tools.in new file mode 100644 index 0000000..0426593 --- /dev/null +++ b/gcc/lto/lto-tools.in @@ -0,0 +1,38 @@ +#!/bin/sh +# binutils wrapper with GCC LTO support +# requires binutils 2.21+ + +invoked=`basename "$0"` +BINDIR=`dirname "$0"` + +if [ -x "$BINDIR/../xgcc" ] ; then + GCC=$BINDIR/../xgcc + ARG=-B$BINDIR/../ +else + ARG= + if [ -x "$BINDIR/gcc" ] ; then + GCC=$BINDIR/gcc + else + GCC=gcc + fi +fi + +case "$invoked" in + gcc-ar) + PROG=ar + PROG_ENV=AR + ;; + gcc-nm) + PROG=nm + PROG_ENV=NM + ;; + gcc-ranlib) + PROG=ranlib + PROG_ENV=RANLIB + ;; +esac + +eval prog="\${$PROG_ENV}" +PROG=${prog:-`"$GCC" -print-prog-name=$PROG`} + +exec "$PROG" --plugin `"$GCC" $ARG -print-prog-name="@LTOPLUGINSONAME@"` "$@"