Binary output feature is a bit confuzing. bfd and gold output differs a lot sometimes,
though it is important for FreeBSD mbr loaders.
Patch change the way how we compute file offsets for binary output.
This fixes PR31196.
Previously offsets were calculated basing on a sections offsets in the same loads.
bfd assigns offsets for each section to VA - MinVA:
https://github.com/redox-os/binutils-gdb/blob/master/bfd/binary.c#L27
https://github.com/redox-os/binutils-gdb/blob/master/bfd/binary.c#L255
(LMA == VA usually)
This patch for now just stops creating phdrs for binary output. An effect from this that
that offset remains unchanged:
OutputSectionBase *First = Sec->FirstInPtLoad; // If the section is not in a PT_LOAD, we have no other constraint. if (!First) return Off; //**Always happens** if (Sec == First) return alignTo(Off, Target->MaxPageSize, Sec->Addr); return First->Offset + Sec->Addr - First->Addr;
That is enough with combination of another 2 patches to generate output
that is similar to what bfd produce.
I uploaded the demo patch showing that: D27340