[X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local for STV_DEFAULT...
authorBen Dunbobbin <Ben.Dunbobbin@sony.com>
Thu, 13 Aug 2020 22:58:40 +0000 (23:58 +0100)
committerBen Dunbobbin <Ben.Dunbobbin@sony.com>
Thu, 13 Aug 2020 23:09:15 +0000 (00:09 +0100)
commit4cb016cd2d8467c572b2e5c5d34f376ee79e4ac1
tree7c6a05f0abfd73dd10cb7902579921102f0c94d3
parent41f49736a9a06650d9d4f1ada21d051585ab7bbe
[X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local for STV_DEFAULT only

This patch restricts the behaviour of referencing via .Lfoo$local
local aliases, introduced in https://reviews.llvm.org/D73230, to
STV_DEFAULT globals only.

Hidden symbols via --fvisiblity=hidden (https://gcc.gnu.org/wiki/Visibility)
is an important scenario.

Benefits:

- Improves the size of object files by using fewer STT_SECTION symbols.

- The code reads a bit better (it was not obvious to me without going
  back to the code reviews why the canBenefitFromLocalAlias function
  currently doesn't consider visibility).

- There is also a side benefit in restoring the effectiveness of the
  --wrap linker option and making the behavior of --wrap consistent
  between LTO and normal builds for references within a translation-unit.
  Note: this --wrap behavior (which is specific to LLD) should not be
  considered reliable. See comments on https://reviews.llvm.org/D73230
  for more.

Differential Revision: https://reviews.llvm.org/D85782
llvm/lib/IR/Globals.cpp
llvm/test/CodeGen/AArch64/emutls.ll
llvm/test/CodeGen/ARM/emutls.ll
llvm/test/CodeGen/X86/2008-03-12-ThreadLocalAlias.ll
llvm/test/CodeGen/X86/linux-preemption.ll
llvm/test/CodeGen/X86/semantic-interposition-comdat.ll
llvm/test/CodeGen/X86/tailcallpic1.ll
llvm/test/CodeGen/X86/tailcallpic3.ll
llvm/test/CodeGen/X86/tailccpic1.ll