Filipe noticed that given a linker script that ended in
.some_sec { ...} ;
stack_start = .;
. = . + 0x2000;
stack_end = .;
lld would put orphan sections like .comment before __stack_end, corrupting the intended meaning.
The reason we don't normally move orphans past assignments to . is to avoid breaking
rx_sec : { *(rx_sec) }
. = ALIGN(0x1000);
/* The RW PT_LOAD starts here*/
but in this case, there is nothing after and it seems safer to put the orphan section last. This seems to match bfd's behavior and is convenient for writing linker scripts that care about the layout of SHF_ALLOC sections, but not of any non SHF_ALLOC sections.