[X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local for…

Authored by Ben Dunbobbin <Ben.Dunbobbin@sony.com> on Aug 13 2020, 3:58 PM.


[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.


  • 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