[PATCH] D24849: Make CanUseCopyRelocWithPIE a llvm option, -pie-copy-relocations

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 13:32:09 PDT 2016


tmsriram added a subscriber: rafael.
tmsriram added a comment.

In https://reviews.llvm.org/D24849#551075, @davide wrote:

> Can you give a little bit more context? How do you plan to use this option?


https://reviews.llvm.org/D19995 discusses this in detail but here is the quick summary:

- When linking executables in non-PIE mode, references to external globals do not use the GOT. They are treated as if the globals were defined in the executable.
- If it so happens that the global is not defined in the executable, a copy relocation is used to duplicate the definition in the executable.
- Currently, in PIE mode, all accesses to external globals use an extra load from the GOT to get its address which is then dereferenced.
- This is particularly inefficient if it turns out at link time that the global ends up being defined in the executable from a different compilation unit.
- Using GOT accesses for globals that end up defined in the executable regresses some of our benchmarks by a few percent.
- It turns out that copy relocations can be used here just like non-PIE mode to always avoid the extra load from the GOT and directly access the global.
- Gold and GNU ld started supporting copy relocations for pie only recently. Gold supports via this patch : https://sourceware.org/ml/binutils/2014-05/msg00092.html
- This option is meant to be used when the linker allows copy relocations for PIE. The default is off.
- GCC already does this, patch discussing this : https://gcc.gnu.org/ml/gcc-patches/2014-05/msg01215.html

This was discussed quite a bit and Rafael wanted something in the IR to tag globals as "extern local" is needed.  For "extern local" globals compiler would not use the GOT and instead the linker would emit a warning if the global ends up undefined in the executable.  For globals that are extern and not marked local, GOT would be used if copy relocations support is not available.


https://reviews.llvm.org/D24849





More information about the llvm-commits mailing list