[lld] [ELF] Orphan placement: remove hasInputSections condition (PR #93761)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 23:53:31 PDT 2024


MaskRay wrote:

> Basically, the linker now takes into account sections defined in a linker script when placing orphans, right?

Yes.

> What if some kind of padding/filler section is defined in the script? It looks like it will attract orphan data sections when placed before actual data sections.

We rely on `SHF_ALLOC | SHF_WRITE` inference for output sections without an input section.
```cpp
// adjustOutputSections
    if (isEmpty) {
      sec->flags =
          flags & ((sec->nonAlloc ? 0 : (uint64_t)SHF_ALLOC) | SHF_WRITE);
      sec->sortRank = getSectionRank(*sec);
    }
```

> Do you think a new `RankFlag` can be added to make real sections more preferable?

Orphan placement seems primarily focused on choosing a suitable region (R/RX/RW/non-ALLOC).
`findOrphanPos` appears to be effective in achieving this.

A `RankFlag` might allow for more precise placement within the chosen region, but I suspect it may not be necessary.
That said, I think this is a quite good suggestion and worth exploring if we run into a case where such a granularity is needed.
Out orphan placement rule is quite complex. Without further evidence I want to hold off adding a new `RankFlag`.


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


More information about the llvm-commits mailing list