[PATCH] D19995: Optimize access to global variable references in PIE mode when linker supports copy relocations for PIE

Joerg Sonnenberger via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 05:52:05 PDT 2016


On Mon, May 09, 2016 at 07:04:04PM -0400, Rafael EspĂ­ndola via llvm-commits wrote:
> Using this email to note that I think there is a point that was missed
> in some messages in this thread:
> 
> Using copy relocations is *not* what is making the program faster.

Thanks, that is one of my core points.

> What is making the program faster is that it is not accessing its own
> variables with a got. The way copy relocations come into the picture
> is that they allow the compiler guess to be wrong in the case of the
> main program. If it is, the dynamic linker produces a copy.

Correct.

> So you could get the same (even a bit better maybe) performance by either
> 
> * Marking every decl in the main program protected (or hidden if
> doesn't take plugins)
> * Marking every library decl with dllimport and keeping the default of
> assuming externals are local to this DSO.

I want to add one more point to the list as way forward:

* Provide a warning on the clang side for -fPIE, if a non-static
  definition does not have an explicit visiblity attribute.

The assumption here is simple, almost all definitions of the main
program are from C/C++ code. The warning allows a user to decide on a
case by case base whether the symbol should be visible to plugins (when
using -rdynamic / -Wl,--export-dynamic) or interpose a definition from a
shared library or even provice the only global definitions. If it is not
meant to be used by something else, hidden allows the full optimisation
potential. Otherwise, protected or default can be used.

Joerg


More information about the llvm-commits mailing list