[PATCH] D105217: [LLD] Adding support for RELA for CG Profile.

Alexander Yermolovich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 11:32:11 PDT 2021


ayermolo updated this revision to Diff 355643.
ayermolo added a comment.

removing header include that sneaked in somehow


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105217

Files:
  lld/ELF/Driver.cpp
  lld/ELF/InputFiles.cpp
  lld/ELF/InputFiles.h


Index: lld/ELF/InputFiles.h
===================================================================
--- lld/ELF/InputFiles.h
+++ lld/ELF/InputFiles.h
@@ -253,6 +253,8 @@
   ArrayRef<Elf_CGProfile> cgProfile;
   // SHT_LLVM_CALL_GRAPH_PROFILE relocations, always in the REL format.
   ArrayRef<Elf_Rel> cgProfileRel;
+  // SHT_LLVM_CALL_GRAPH_PROFILE relocations, always in the RELA format.
+  ArrayRef<Elf_Rela> cgProfileRela;
 
   // Get cached DWARF information.
   DWARFCache *getDwarf();
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -674,6 +674,8 @@
       if (cgProfileSectionIndex && sec.sh_info == cgProfileSectionIndex) {
         if (sec.sh_type == SHT_REL)
           cgProfileRel = CHECK(getObj().rels(sec), this);
+        else
+          cgProfileRela = CHECK(getObj().relas(sec), this);
       }
     }
 
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -855,22 +855,34 @@
   }
 }
 
+/// Retrieves symbol indices either from REL or RELA section.
+template <class ELFTRel>
+static void getIndices(SmallVector<uint32_t, 128> &symbolIndices,
+                       ArrayRef<ELFTRel> cgProfileRel) {
+  for (const ELFTRel &rel : cgProfileRel) {
+    symbolIndices.push_back(rel.getSymbol(config->isMips64EL));
+  }
+}
+
 template <class ELFT> static void readCallGraphsFromObjectFiles() {
-  auto getIndex = [&](ObjFile<ELFT> *obj, uint32_t index) {
-    const Elf_Rel_Impl<ELFT, false> &rel = obj->cgProfileRel[index];
-    return rel.getSymbol(config->isMips64EL);
-  };
+  SmallVector<uint32_t, 128> symbolIndices;
 
   for (auto file : objectFiles) {
     auto *obj = cast<ObjFile<ELFT>>(file);
-    if (obj->cgProfileRel.empty())
+    if (obj->cgProfileRel.empty() && obj->cgProfileRela.empty())
       continue;
-    if (obj->cgProfileRel.size() != obj->cgProfile.size() * 2)
+    symbolIndices.clear();
+    if (!obj->cgProfileRel.empty())
+      getIndices(symbolIndices, obj->cgProfileRel);
+    else
+      getIndices(symbolIndices, obj->cgProfileRela);
+
+    if (symbolIndices.size() != obj->cgProfile.size() * 2)
       fatal("number of relocations doesn't match Weights");
     for (uint32_t i = 0, size = obj->cgProfile.size(); i < size; ++i) {
       const Elf_CGProfile_Impl<ELFT> &cgpe = obj->cgProfile[i];
-      uint32_t fromIndex = getIndex(obj, i * 2);
-      uint32_t toIndex = getIndex(obj, i * 2 + 1);
+      uint32_t fromIndex = symbolIndices[i * 2];
+      uint32_t toIndex = symbolIndices[i * 2 + 1];
       auto *fromSym = dyn_cast<Defined>(&obj->getSymbol(fromIndex));
       auto *toSym = dyn_cast<Defined>(&obj->getSymbol(toIndex));
       if (!fromSym || !toSym)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105217.355643.patch
Type: text/x-patch
Size: 2807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210630/3c2d2690/attachment.bin>


More information about the llvm-commits mailing list