Imagine we have too sections .foo and .bar with virtual addresses 0x10000 and 0x20000, which share the same segment:
PHDRS { all PT_LOAD; } SECTIONS { .foo (0x10000) : { *(.foo*) } : all .bar (0x20000) : { *(.bar*) } : all }
Now also imagine that section .foo is the first section in PT_LOAD and segment virtual address is the same as section .foo, i.e 0x10000
As we have only one PT_LOAD, OS kernel should allocate the both sections correctly using only one memory mapping operation. The only
way this can be done is setting difference between file offsets of .bar and .foo to the same value as difference between their virtual addresses, i.e:
File_offset(.bar) - File_offset(.foo) = VA(.bar) - VA(.foo) = 0x10000
In such case both sections be correctly loaded using a single mmap() call.
Also It looks like both gold and ld use the same approach.