Hi,

On Mon, 18 Jul 2016, Jakub Jelinek wrote:

> On Mon, Jul 18, 2016 at 02:32:40PM +0200, Richard Biener wrote:
> > While eliding ranlib sounds like a no-brainer the real benefit (I/O wise) is
> > when you get rid of the archive or save link time by creating a (partially)
> > linked DSO.  ISTR Michael Matz has patches to do that.  Whether it's
> 
> DSO?  Then we'd have to build everything with -fpic (which we only do when
> building gccjit).  Did you mean just a relocatable object (ld -r) instead?

Yes, a real DSO, and yes with -fpic.  I had hacks in the compiler to make 
functions be protected visibility (and only those, as protected data is a 
PITA) to retain inlining effects to not lose too much performance (and 
some hackery in binutils to make this work as intended).  At that time 
(years ago) a cc1 with shared libbackend.so was even faster than a static 
cc1 (!).

When dusting off that stuff I realized that -fPIE has similar effects 
(symbols aren't preemptable, so inlining still happens, and the code is 
mostly appropriate for a shared object).  But I ran into the same binutils 
artifacts again and haven't found time to really continue with that.  
Some quick hack in binutils to not error out on direct PC-relative 
references to data symbols (for fear of copy relocs) shows that a 
sort-of-shared cc1+libbackend.so is about 1% slower than a static one (on 
some fold-const.i file I had) on x86-64.  These cc1 were built with -O0 
and checking enabled.

If you want to play with that, attached are two diffs, one for GCC, one 
for binutils.  configure with --enabled-backend-shared, and then play with 
the two BACKENDPICFLAG and NO_PIE_CFLAGS flags (the latter should contain 
-fPIE so that no copy relocs are created when BACKENDPICFLAGS contains 
-fvisibility=protected).  The binutils hack is only needed if 
libbackend.so is built with -fPIE.

The above timing is with BACKENDPICFLAGS="-fPIE -fvisibility=protected" 
and NO_PIE_CFLAGS=-fPIE and the binutils hack.

I still wanted to reimplement the visibility for functions only flag and 
remeasure.  Then the binutils part wouldn't be necessary.


Ciao,
Michael.
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 235171)
+++ Makefile.in	(working copy)
@@ -150,6 +150,7 @@ LDFLAGS = @LDFLAGS@
 
 # Should we build position-independent host code?
 PICFLAG = @PICFLAG@
+BACKENDPICFLAG = @BACKENDPICFLAG@
 
 # Flags to determine code coverage. When coverage is disabled, this will
 # contain the optimization flags, as you normally want code coverage
@@ -382,6 +383,7 @@ PLUGINLIBS = @pluginlibs@
 enable_plugin = @enable_plugin@
 
 enable_host_shared = @enable_host_shared@
+enable_backend_shared = @enable_backend_shared@
 
 enable_as_accelerator = @enable_as_accelerator@
 
@@ -1563,7 +1566,12 @@ ALL_HOST_BACKEND_OBJS = $(GCC_OBJS) $(OB
 # compilation or not.
 ALL_HOST_OBJS = $(ALL_HOST_FRONTEND_OBJS) $(ALL_HOST_BACKEND_OBJS)
 
-BACKEND = libbackend.a main.o libcommon-target.a libcommon.a \
+ifeq ($(enable_backend_shared),yes)
+LIBBACKEND = libbackend.so
+else
+LIBBACKEND = libbackend.a
+endif
+BACKEND = $(LIBBACKEND) main.o libcommon-target.a libcommon.a \
 	$(CPPLIB) $(LIBDECNUMBER)
 
 # This is defined to "yes" if Tree checking is enabled, which roughly means
@@ -1587,7 +1595,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-con
  gcc-ranlib$(exeext) \
  gcov-iov$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
- gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
+ gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c $(LIBBACKEND) \
  libcommon-target.a libcommon.a libgcc.mk
 
 # This symlink makes the full installation name of the driver be available
@@ -1842,12 +1850,20 @@ rest.cross: specs
 # This is used only if the user explicitly asks for it.
 compilations: $(BACKEND)
 
+ifeq ($(enable_backend_shared),yes)
+$(OBJS): INTERNAL_CFLAGS += $(BACKENDPICFLAG)
+endif
+
 # This archive is strictly for the host.
 libbackend.a: $(OBJS)
 	-rm -rf libbackend.a
 	$(AR) $(AR_FLAGS) libbackend.a $(OBJS)
 	-$(RANLIB) $(RANLIB_FLAGS) libbackend.a
 
+libbackend.so: $(OBJS)
+	-rm -rf libbackend.so
+	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS)
+
 libcommon-target.a: $(OBJS-libcommon-target)
 	-rm -rf libcommon-target.a
 	$(AR) $(AR_FLAGS) libcommon-target.a $(OBJS-libcommon-target)
Index: configure.ac
===================================================================
--- configure.ac	(revision 235171)
+++ configure.ac	(working copy)
@@ -5991,6 +5991,12 @@ AC_ARG_ENABLE(host-shared,
 AC_SUBST(enable_host_shared)
 AC_SUBST(PICFLAG)
 
+AC_ARG_ENABLE(backend-shared,
+[AS_HELP_STRING([--enable-backend-shared],
+		[build backend code as shared library])],
+[BACKENDPICFLAG=-fPIC], [BACKENDPICFLAG=])
+AC_SUBST(enable_backend_shared)
+AC_SUBST(BACKENDPICFLAG)
 
 AC_ARG_ENABLE(libquadmath-support,
 [AS_HELP_STRING([--disable-libquadmath-support],
Index: configure
===================================================================
--- configure	(revision 235171)
+++ configure	(working copy)
@@ -603,6 +603,8 @@ LIBOBJS
 NO_PIE_FLAG
 NO_PIE_CFLAGS
 enable_default_pie
+BACKENDPICFLAG
+enable_backend_shared
 PICFLAG
 enable_host_shared
 enable_plugin
@@ -944,6 +946,7 @@ enable_link_mutex
 enable_version_specific_runtime_libs
 enable_plugin
 enable_host_shared
+enable_backend_shared
 enable_libquadmath_support
 with_linker_hash_style
 with_diagnostics_color
@@ -1683,6 +1686,7 @@ Optional Features:
                           in a compiler-specific directory
   --enable-plugin         enable plugin support
   --enable-host-shared    build host code as shared libraries
+  --enable-backend-shared build backend code as shared library
   --disable-libquadmath-support
                           disable libquadmath support for Fortran
   --enable-default-pie    enable Position Independent Executable as default
@@ -29241,6 +29245,15 @@ fi
 
 
 
+# Check whether --enable-backend-shared was given.
+if test "${enable_backend_shared+set}" = set; then :
+  enableval=$enable_backend_shared; BACKENDPICFLAG=-fPIC
+else
+  BACKENDPICFLAG=
+fi
+
+
+
 
 # Check whether --enable-libquadmath-support was given.
 if test "${enable_libquadmath_support+set}" = set; then :
Index: gcc.c
===================================================================
--- gcc.c	(revision 235171)
+++ gcc.c	(working copy)
@@ -3051,6 +3051,9 @@ execute (void)
     }
 #endif
 
+  /* XXX Look at paths of commands[].argv[0] only.  */
+  putenv_from_prefixes (&exec_prefixes, "LD_LIBRARY_PATH", false);
+
   /* Run each piped subprocess.  */
 
   pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index e80fd20..94b4680 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4520,7 +4520,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 		    || r_type == R_X86_64_PC32_BND)
 		   && is_32bit_relative_branch (contents, rel->r_offset));
 
-	      if (SYMBOL_REFERENCES_LOCAL (info, h))
+	      if (SYMBOL_CALLS_LOCAL (info, h))
 		{
 		  /* Symbol is referenced locally.  Make sure it is
 		     defined locally or for a branch.  */

Reply via email to