This fixed PR31196,
problem is that ElfHeader address was taken in account when we calculated offsets:
static uintX_t getFileAlignment(uintX_t Off, OutputSectionBase *Sec) {
...
return First->Offset + Sec->Addr - First->Addr;Sec->Addr is 600 here.
First->Addr is 0x10000 (First here is Out<ELFT>::ElfHeader->Addr == ImageBase).
Binary output does not have headers, we do not need to rely on their address to
calculate file offset.
Ah. Why do we add Load for the !ScriptConfig->HasSections case?
For me at least this seems to make it more clear:
Phdr *Load = nullptr; if (!ScriptConfig->HasSections && !Config->OFormatBinary) { Load = AddHdr(PT_LOAD, Flags); Load->add(Out<ELFT>::ElfHeader); Load->add(Out<ELFT>::ProgramHeaders); }