[PATCH] D79625: [PowerPC] Extend .reloc directive on PowerPC

Stefan Pintilie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 04:15:33 PDT 2020


stefanp created this revision.
stefanp added reviewers: nemanjai, lei, PowerPC, hfinkel.
Herald added subscribers: steven.zhang, shchenz, kbarton, hiraditya.
Herald added a project: LLVM.

A linker optimization is available on PowerPC for GOT indirect PCRelative loads.

When the compiler generates a GOT indirect load it must generate two loads. One
that loads the address of the element from the GOT and a second to load the
actual element based on the address just loaded from the GOT. However, the
linker can optimize these two loads into one load if it knows that it is safe
to do so. The compiler can tell the linker that the optimization is safe
by using the R_PPC64_PCREL_OPT relocation. The relocation can be used as follows

    pld 3, vec at got@pcrel(0), 1
  .Lpcrel1:
      ... More instructions possible here ...
  .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
    lwa 3, 4(3)

The first load to get the address from the GOT has a label immediately following
it (in this case Lpcrel1) and then the second load has the .reloc directive that
actually attaches the relocation to the first load using the Lpcrel1-8. The end
result is that the first load from the GOT has a relocation on it that specifies
the offset in the text section to the second load so that the linker can perform
the optimization.
There is another possible form for this setup as follows:

    pld 3, vec at got@pcrel(0), 1
  .Lpcrel1=.-8
        ... More instructions possible here ...
  .reloc .Lpcrel1,R_PPC64_PCREL_OPT,.-.Lpcrel1
    lwa 3, 4(3)

In the second form the label is variable and contains the .-8.
This patch expands the .reloc directive to suport both of the above forms.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79625

Files:
  llvm/include/llvm/BinaryFormat/ELFRelocs/PowerPC64.def
  llvm/include/llvm/MC/MCExpr.h
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.h
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCFixupKinds.h
  llvm/test/MC/PowerPC/future-reloc-with-expr.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79625.262850.patch
Type: text/x-patch
Size: 21500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200508/8fa06e0b/attachment-0001.bin>


More information about the llvm-commits mailing list