[PATCH] D13566: [ELF2] PPC64 needs to delay local-call relocations until after the function-descriptor values are known

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 10:53:43 PDT 2015


ruiu added a comment.

Writer<ELFT>::writeSections() {


================
Comment at: ELF/Target.cpp:401-407
@@ -400,1 +400,9 @@
+
+    if (!ForPltEntry) {
+      // If this is a local call, and we currently have the address of a
+      // function-descriptor, get the underlying code address instead.
+      auto ARI = Addr64Relocs.find(R);
+      if (ARI != Addr64Relocs.end())
+        R = ARI->second;
+    }
 
----------------
You may be able to eliminate the hash table by reading back previous relocatino results for R_PPC64_ADDR64 from Buf.

  if (!ForPltEntry)
    R = read64be(Buf + R - BaseAddr);

================
Comment at: ELF/Target.h:96
@@ -91,1 +95,3 @@
+  // to resolve local calls.
+  mutable llvm::DenseMap<uint64_t, uint64_t> Addr64Relocs;
 };
----------------
Mutable memebers are not generally good, so I'd avoid using that.

================
Comment at: ELF/Writer.cpp:654-664
@@ -653,5 +653,13 @@
 template <class ELFT> void Writer<ELFT>::writeSections() {
+  // PPC64 needs to process relocations in the .opd section before processing
+  // relocations in code-containing sections.
+  for (OutputSectionBase<ELFT::Is64Bits> *&Sec : OutputSections)
+    if (Sec->getName() == ".opd") {
+      std::swap(OutputSections[0], Sec);
+      break;
+    }
+
   uint8_t *Buf = Buffer->getBufferStart();
   for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
     Sec->writeTo(Buf + Sec->getFileOff());
 }
----------------
Changing the order of the vector could have significant impact because that's not supposed to happen. Please do like this

  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
    if (Sec->getName() == ".opd")
      Sec->writeTo(Buf + Sec->getFileOff();
  for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections)
    if (Sec->getName() != ".opd")
      Sec->writeTo(Buf + Sec->getFileOff();



http://reviews.llvm.org/D13566





More information about the llvm-commits mailing list