[lld] ELF: Store EhInputSection relocations to simplify code. NFC (PR #161041)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 29 03:41:30 PDT 2025


================
@@ -1358,20 +1358,21 @@ SyntheticSection *EhInputSection::getParent() const {
 // .eh_frame is a sequence of CIE or FDE records.
 // This function splits an input section into records and returns them.
 template <class ELFT> void EhInputSection::split() {
-  const RelsOrRelas<ELFT> rels = relsOrRelas<ELFT>(/*supportsCrel=*/false);
+  const RelsOrRelas<ELFT> elfRels = relsOrRelas<ELFT>();
+  if (elfRels.areRelocsCrel())
+    preprocessRelocs<ELFT>(elfRels.crels);
+  else if (elfRels.areRelocsRel())
+    preprocessRelocs<ELFT>(elfRels.rels);
+  else
+    preprocessRelocs<ELFT>(elfRels.relas);
+  auto cmp = [](const Relocation &a, const Relocation &b) {
+    return a.offset < b.offset;
+  };
+  if (!llvm::is_sorted(rels, cmp))
+    llvm::stable_sort(rels, cmp);
+
----------------
smithp35 wrote:

The comment below looks to be stale. Should it be moved above the stable_sort, possibly updated to mention offset rather than r_offset.

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


More information about the llvm-commits mailing list