Currently linker script support in lld is almost useless due to following reasons:
- First PT_LO`D segment always has zero virtual address (see http://reviews.llvm.org/D21750)
- PT_LOAD segments are very often not aligned correctly, because section grouping is not yet implemented
Consider the following script:
SECTIONS { . = 0x10000000; .bss : { *(.bss) } .data : { *(.data) } . = 0x11000000; .text : { *(.text) } }
And the following C code:
int main(void) { return 0; }
Compiling and linking it using lld and script provided will result in ELF having following segments:
LOAD 0x002000 0x0000000011000000 0x0000000011000000 0x182 0x182 R E LOAD 0x002184 0x0000000011000184 0x0000000011000184 0x1d0 0x1d0 R LOAD 0x002354 0x0000000011000354 0x0000000011000354 0x04c 0x04c R E LOAD 0x0023a0 0x00000000110003a0 0x00000000110003a0 0x188 0x188 RW
Linux kernel will map them one by one to virtual address 0x11000000 (page-aligned), with map size of 0x1000 (page rounded)
and different protection attributes. Finally one will have region 0x11000000 - 0x11001000 mapped with RW attributes. Jumping to
entry point 0x11000000 will immediately cause protection fault (SIGSEGV). Not a single user instruction will be executed
To (temporary) overcome this problem and generate working image I propose to merge PT_LOAD segments ORing protection attributes
(this is, to my beleif, gold linker does). After merge one will have a single PT_LOAD segment:
LOAD 0x002000 0x0000000011000000 0x0000000011000000 0x528 0x528 RWE
As now segment has RWE protection attributes user instructions can be executed normally.
Let's name this IsOrphan.