This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Allow copy relocations with pie links


Hi,

With -pie and x86, the linker complains if it sees a PC-relative relocation
to access a global as it expects a GOTPCREL relocation.  This is really not
necessary as the linker could use a copy relocation to get around it.  This
patch enables copy relocations with pie.

Context:
This is useful because the GCC compiler with option -fpie makes
every extern global access go through the GOT. That is because the compiler
cannot tell if a global will end up being defined in the executable or not
and is conservative. This ends up hurting performance when the binary is linked
as mostly static where most of the globals do end up being defined in the
executable.  By allowing copy relocs with fPIE, the compiler need not generate
a GOTPCREL(GOT access) for any global access.  It can safely assume that all
globals will be defined in the executable and generate a PC-relative access
instead.  Gold can then create a copy reloc for only the undefined globals.
This optimization helps improve a couple of Google benchmarks by 1-4%.  The
performance improvement is primarily from removing the additional memory
access to load the address of a variable using the GOT.

ChangeLog:

* symtab.h (may_need_copy_reloc): Extra default parameter to
indicate if this is a PC relative relocation.
* x86_64.cc (Target_x86_64<size>::Scan::global): Call
may_need_copy_reloc with parameter set to true.
* testsuite/pie_copyrelocs_test.cc: New file.
* testsuite/pie_copyrelocs_shared_test.cc: New file.
* Makefile.am (pie_copyrelocs_test): New test.
* Makefile.in: Regenerate.


Patch attached.

Comments?

Thanks
Sri

Attachment: gold_pie_patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]