[ELF] - Change the way how we compute offsets for binary output.
authorGeorge Rimar <grimar@accesssoftek.com>
Sat, 3 Dec 2016 07:23:30 +0000 (07:23 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Sat, 3 Dec 2016 07:23:30 +0000 (07:23 +0000)
commit40c28c7f9a0aac9795cff04e5f7e36108d8c00c1
tree1653d9ff9aef4dff3974d0c0e30d4fafdb84da8d
parentd250618c3e7538a78d28cec0189ac23559b2d5a2
[ELF] - Change the way how we compute offsets for binary output.

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 offsets and addresses of sections
from the same loads:
if (Sec == First)
  return alignTo(Off, Target->MaxPageSize, Sec->Addr);
return First->Offset + Sec->Addr - First->Addr;

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 no any additional calculation for offset is performed:

uintX_t getFileAlignment(uintX_t Off, OutputSectionBase *Sec) {
OutputSectionBase *First = Sec->FirstInPtLoad;
// If the section is not in a PT_LOAD, we have no other constraint.
if (!First)
  return Off; //**First is always null, condition always happens**

That is enough now with combination of another patch to generate output
that is similar to what bfd produce for mbr loader.

Differential revision: https://reviews.llvm.org/D27341

llvm-svn: 288580
lld/ELF/Writer.cpp
lld/test/ELF/oformat-binary-ttext.s [new file with mode: 0644]