[lld] [ELF] Orphan placement: prefer the last similar section when its rank <= orphan's rank (PR #94099)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 08:15:36 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);
+ if (p > proximity ||
----------------
smithp35 wrote:
I'm trying to match this up with the comment:
```
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.
```
I can see the "or the last one with a rank <= orphan's rank" explicit in the condition. I think the first part is implicit because we already have a section selected "first section" and we don't update it.
Not entirely sure how to make this clearer though. Perhaps rewording the original comment to:
```
In the event of proximity ties, we select the first section, unless a later section with the same proximity has a rank <= the orphan's rank.
```
https://github.com/llvm/llvm-project/pull/94099
More information about the llvm-commits
mailing list