[PATCH] D73228: [AsmPrinter][ELF] Define local aliases (.Lfoo$local) for GlobalObjects

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 14:13:27 PST 2020


MaskRay created this revision.
MaskRay added reviewers: bd1976llvm, jyknight, peter.smith, rnk, sfertile.
Herald added subscribers: llvm-commits, kerbowa, hiraditya, nhaehnle, jvesely.
Herald added a project: LLVM.

For **certain** `MC_GlobalAddress` operands, we can lower them to a
STB_LOCAL alias to avoid costs brought by potential symbol interposition
(relocations in object files, PLT/GOT in executables/shared objects).

"certain" refers to GlobalObjects in the intersection of hasExactDefinition() and !isInterposable():
`external`, `appending`, `internal`, `private`. Lowering a reference to `internal` or `private`
does not have symbol interposition cost. `appending` is for very few objects LLVM interpret specially.
So the set just includes `external`.

This patch emits STB_LOCAL aliases (.Lfoo$local) for such GlobalObjects, so that targets can lower
MC_GlobalAddress operands to STB_LOCAL aliases if applicable.
We may extend the scope and include GlobalAlias in the future.

LLVM's existing -fno-semantic-interposition behaviors give us license to do such optimizations:

- Various optimizations (ipconstprop, inliner, sccp, sroa, etc) treat normal ExternalLinkage GlobalObjects as non-interposable.
- Before D72197 <https://reviews.llvm.org/D72197>, MC resolved a PC-relative VK_None fixup to a non-local symbol at assembly time (no outstanding relocation), if the target is defined in the same section. Put it simply, even if IR optimizations failed to optimize and allowed interposition for the function call in `void foo() {} void bar() { foo(); }`, the assembler would disallow it.

This patch sets up AsmPrinter infrastructure to make -fno-semantic-interposition more so.
With and without the patch, the object file output should be identical:
`.Lfoo$local` does not take a symbol table entry.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73228

Files:
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/AArch64/emutls.ll
  llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-sp-mod.ll
  llvm/test/CodeGen/AMDGPU/r600-constant-array-fixup.ll
  llvm/test/CodeGen/ARM/emutls.ll
  llvm/test/CodeGen/X86/emutls.ll
  llvm/test/CodeGen/X86/linux-preemption.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73228.239696.patch
Type: text/x-patch
Size: 7250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200122/59900f27/attachment.bin>


More information about the llvm-commits mailing list