This is the mail archive of the 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


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.

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.


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

Patch attached.



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]