[PATCH] D85973: [PowerPC] Fix thunk alignment issue when using pc-rel instruction

Victor Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 07:33:25 PDT 2020


NeHuang created this revision.
NeHuang added reviewers: nemanjai, Sean, stefanp, hfinkel.
NeHuang added a project: LLVM.
Herald added subscribers: llvm-commits, shchenz, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: MaskRay.
NeHuang requested review of this revision.

Thunk alignment is needed when using pc-rel instructions to avoid crossing the 64 byte boundary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85973

Files:
  lld/ELF/SyntheticSections.cpp
  lld/ELF/Thunks.cpp


Index: lld/ELF/Thunks.cpp
===================================================================
--- lld/ELF/Thunks.cpp
+++ lld/ELF/Thunks.cpp
@@ -301,7 +301,7 @@
 // callee's global entry point into r12 without a save of R2.
 class PPC64R12SetupStub final : public Thunk {
 public:
-  PPC64R12SetupStub(Symbol &dest) : Thunk(dest, 0) {}
+  PPC64R12SetupStub(Symbol &dest) : Thunk(dest, 0) { alignment = 16; }
   uint32_t size() override { return 16; }
   void writeTo(uint8_t *buf) override;
   void addSymbols(ThunkSection &isec) override;
@@ -316,7 +316,7 @@
 // 2) Transferring control to the target function through an indirect branch.
 class PPC64PCRelPLTStub final : public Thunk {
 public:
-  PPC64PCRelPLTStub(Symbol &dest) : Thunk(dest, 0) {}
+  PPC64PCRelPLTStub(Symbol &dest) : Thunk(dest, 0) { alignment = 16; }
   uint32_t size() override { return 16; }
   void writeTo(uint8_t *buf) override;
   void addSymbols(ThunkSection &isec) override;
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -3527,8 +3527,8 @@
 }
 
 ThunkSection::ThunkSection(OutputSection *os, uint64_t off)
-    : SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 4,
-                       ".text.thunk") {
+    : SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS,
+                       config->emachine == EM_PPC64 ? 16 : 4, ".text.thunk") {
   this->parent = os;
   this->outSecOff = off;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85973.285650.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200814/fcc60dd4/attachment.bin>


More information about the llvm-commits mailing list