diff mbox

Add gcc-ar, gcc-nm, gcc-ranlib

Message ID AANLkTikaBvf_hEf0Okm6dXWwn5uWiDL4xTM3Dns=mWnb@mail.gmail.com
State New
Headers show

Commit Message

H.J. Lu Dec. 2, 2010, 11:58 p.m. UTC
On Thu, Dec 2, 2010 at 3:04 PM, Paolo Bonzini <bonzini@gnu.org> 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.

Comments

Paolo Bonzini Dec. 3, 2010, 8:54 a.m. UTC | #1
On 12/03/2010 12:58 AM, H.J. Lu wrote:
>> 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.

exec-tool.in is not installed, these ones are.

Paolo
diff mbox

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@"` "$@"