diff mbox

Shared libbackend.so (was: [PATCH] Avoid invoking ranlib on libbackend.a)

Message ID alpine.LSU.2.20.1607181457070.12287@wotan.suse.de
State New
Headers show

Commit Message

Michael Matz July 18, 2016, 2:12 p.m. UTC
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.
diff mbox

Patch

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.  */