Unverified Commit 7b346357 authored by Fangrui Song's avatar Fangrui Song Committed by GitHub
Browse files

[ELF] Orphan placement: prefer the last similar section when its rank <= orphan's rank

`findOrphanPos` finds the most similar output section (that has input
sections). In the event of proximity ties, we select the first section.

However, when an orphan section's rank is equal to or larger than the
most similar sections's, it makes sense to prioritize the last similar
section. This new behavior matches GNU ld better.

```
// orphan placement for .bss (SHF_ALLOC|SHF_WRITE, SHT_NOBITS)

WA SHT_PROGBITS
(old behavior) <= here
A
WA SHT_PROGBITS
AX
WA (.data)
(new behavior) <= here
```

When the orphan section's rank is less, the current behavior
prioritizing the first section still makes sense.
```
// orphan with a smaller rank, e.g. .rodata

<= here
WA
AX
WA
```

Close #92987

Pull Request: https://github.com/llvm/llvm-project/pull/94099
parent 6ac5047a
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment