[PATCH] D86706: [LLD][PowerPC] Add pc-rel based long branch thunks

Sean Fertile via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 07:18:25 PDT 2020


sfertile added inline comments.


================
Comment at: lld/ELF/Thunks.cpp:375
+// call must be local (a non-local call will have a PCRelPltCallStub instead)
+// the table stores the address of the callee's local entry point. For
+// position-independent code a corresponding relative dynamic relocation is
----------------
IIUC If there is a call between a pc-rel based caller and a toc-based callee (so that callee has global and local entry points) then we will have emitted an `PPC64R12SetupoStub`. Likewise, if its a toc-based caller and pc-rel based callee we use an R2SaveStub. So its only between pc-rel based caller and callee that we can have a pc rel based long branch thunk.


================
Comment at: lld/ELF/Thunks.cpp:993
+
+void PPC64PCRelLongBranchThunk::writeTo(uint8_t *buf) {
+  int64_t offset = in.ppc64LongBranchTarget->getEntryVA(&destination, addend) -
----------------
The R12Setup stub calculates the address of the callee relative to the program counter.

```
  writePrefixedInstruction(buf + 0, paddi); // paddi r12, 0, func at pcrel, 1
  write32(buf + 8, MTCTR_R12);              // mtctr r12
  write32(buf + 12, BCTR);                  // bctr
```

The toc-based long branch thunks have to use a table in the data segment because of limited address-ability. The pc-rel instructions and ABI doesn't have the same limitation, so why use the branch linkage table intead of doing the same thing the R12Setup stubs do?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86706/new/

https://reviews.llvm.org/D86706



More information about the llvm-commits mailing list