[lld] [ELF] Orphan placement: prefer the last similar section when its rank <= orphan's rank (PR #94099)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 11:20:12 PDT 2024


================
@@ -935,14 +935,18 @@ findOrphanPos(SmallVectorImpl<SectionCommand *>::iterator b,
       return i;
   }
 
-  // Find the first element that has as close a rank as possible.
   if (b == e)
     return e;
+  // Select the most similar output section. In case of ties, select the first
+  // section with a rank > the orphan's rank, or the last one with a rank <= the
+  // orphan's rank.
   int proximity = getRankProximity(sec, *b);
   auto i = b;
   for (auto j = b; ++j != e;) {
-    int p = getRankProximity(sec, *j);
-    if (p > proximity) {
+    auto p = getRankProximity(sec, *j);
----------------
MaskRay wrote:

Done

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


More information about the llvm-commits mailing list