[lld] [ELF] Orphan placement: remove hasInputSections condition (PR #93761)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 18:14:47 PDT 2024
igorkudrin wrote:
> > Basically, the linker now takes into account sections defined in a linker script when placing orphans, right?
> Yes.
My concerns are for cases like:
```
> cat test.s
.section ".text1","ax","progbits"; nop;
.section ".text2","ax","progbits"; nop;
.section ".rodata","a","progbits"; .long 0;
.section ".orphan","a","progbits"; .long 0;
> cat test.t
PHDRS { text PT_LOAD; rodata PT_LOAD; }
SECTIONS {
.text1 : { *(.text1) } : text
#.other : { foo = .; *(.other) }
.other : { LONG(0); *(.other) }
.text2 : { *(.text2) }
.rodata : { *(.rodata) } : rodata
}
> llvm-mc -filetype=obj test.s -o test.o
> ld.lld -shared test.o -T test.t -o test.so
> llvm-readelf -l test.so
...
LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000056 0x000056 R E 0x1000
LOAD 0x001056 0x0000000000000056 0x0000000000000056 0x00007a 0x00007a RW 0x1000
Section to Segment mapping:
Segment Sections...
00 .text1 .text .other .orphan .dynsym .gnu.hash .hash .dynstr .text2
01 .rodata .dynamic
...
```
Of course, this example is oversimplified, but I see something similar in our projects.
For this sample, GNU linkers and current `lld` place `.orphan` and the synthetic sections after `.rodata`, while the patched `lld` puts them in the middle of an executable segment. The problem is that output sections without input sections are usually unaware of their flags, as they normally inherit them from their input sections. With the new placement rules, such faint sections are used as anchors for orphans, moving them to unsuitable locations.
https://github.com/llvm/llvm-project/pull/93761
More information about the llvm-commits
mailing list