[lld] [lld][ELF] Extend profile guided function ordering to ELF binaries (PR #117514)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 10:12:14 PST 2024


================
@@ -123,13 +124,17 @@ class BPSectionMacho : public BPSectionBase {
   static bool classof(const BPSectionBase *s) { return true; }
 
 private:
-  static uint64_t getRelocHash(const Reloc &reloc,
-                               const BPSectionMacho *section) {
+  static uint64_t getRelocHash(
+      const Reloc &reloc,
+      const llvm::DenseMap<const BPSectionBase *, uint64_t> &sectionToIdx) {
     auto *isec = reloc.getReferentInputSection();
     std::optional<uint64_t> sectionIdx;
-    if (isec && isec == section->getSection())
-      sectionIdx = section->getSectionIdx();
-
+    for (const auto &entry : sectionToIdx)
+      if (const auto *bpSection = llvm::dyn_cast<BPSectionMacho>(entry.first))
+        if (bpSection->getSection() == isec) {
+          sectionIdx = entry.second;
+          break;
+        }
----------------
ellishg wrote:

Yeah the key type needs to be 'InputSection'

https://github.com/llvm/llvm-project/pull/117514


More information about the llvm-commits mailing list