<table><tr><td style="">This revision was automatically updated to reflect the committed changes.<br />Closed by commit rL282705: [ELF] Change the way we compute file offsets  (authored by evgeny777).
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://reviews.llvm.org/D25014" rel="noreferrer">View Revision</a></tr></table><br /><div><strong><strong>Changed prior to commit:</strong></strong><div><a href="https://reviews.llvm.org/D25014?vs=72896&id=72965#toc" rel="noreferrer">https://reviews.llvm.org/D25014?vs=72896&id=72965#toc</a></div></div><br /><div><strong><strong>Repository:</strong></strong><div><div>rL LLVM</div></div></div><br /><div><a href="https://reviews.llvm.org/D25014" rel="noreferrer">https://reviews.llvm.org/D25014</a></div><br /><div><strong><strong>Files:</strong></strong><div><div>lld/trunk/ELF/OutputSections.h<br />
lld/trunk/ELF/Writer.cpp<br />
lld/trunk/test/ELF/linkerscript/outsections-addr.s</div></div></div><br /><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><span style="color: #4b4d51; font-weight: bold;">lld/trunk/test/ELF/linkerscript/outsections-addr.s</span></div><div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    ]
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Address: 0x4008
</div><div style="padding: 0 8px; margin: 0 4px; background: #ffd0d0;">#CHECK:    Offset: 0x<span class="bright">2</span>008
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">#CHECK:    Offset: 0x<span class="bright">3</span>008
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Size: 8
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Link: 0
</div><div style="padding: 0 8px; margin: 0 4px; background: #F7F7F7; color: #74777D; border-style: dashed; border-color: #C7CCD9; border-width: 1px 0;">...</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    ]
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Address: 0x5010
</div><div style="padding: 0 8px; margin: 0 4px; background: #ffd0d0;">#CHECK:    Offset: 0x<span class="bright">2</span>010
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">#CHECK:    Offset: 0x<span class="bright">4</span>010
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Size: 8
</div><div style="padding: 0 8px; margin: 0 4px; ">#CHECK:    Link: 0
</div></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><span style="color: #4b4d51; font-weight: bold;">lld/trunk/ELF/OutputSections.h</span></div><div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; ">  uintX_t getVA() const { return Header.sh_addr; }
</div><div style="padding: 0 8px; margin: 0 4px; ">  void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  uintX_t getFileOffset() { return Header.sh_offset; }
</div><div style="padding: 0 8px; margin: 0 4px; ">  void setSHName(unsigned Val) { Header.sh_name = Val; }
</div><div style="padding: 0 8px; margin: 0 4px; ">  void writeHeaderTo(Elf_Shdr *SHdr);
</div><div style="padding: 0 8px; margin: 0 4px; background: #F7F7F7; color: #74777D; border-style: dashed; border-color: #C7CCD9; border-width: 1px 0;">...</div><div style="padding: 0 8px; margin: 0 4px; ">  bool PageAlign = false;
</div><div style="padding: 0 8px; margin: 0 4px; ">
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // Pointer to the first section in PT_LOAD segment, which this section
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // also resides in. This field is used to correctly compute file offset
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // of a section. When two sections share the same load segment, difference
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // between their file offsets should be equal to difference between their
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // virtual addresses. To compute some section offset we use the following
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // formula: Off = Off_first + VA - VA_first.
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  OutputSectionBase<ELFT> *FirstInPtLoad = nullptr;
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">
</div><div style="padding: 0 8px; margin: 0 4px; ">  virtual void finalize() {}
</div><div style="padding: 0 8px; margin: 0 4px; ">  virtual void finalizePieces() {}
</div></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><span style="color: #4b4d51; font-weight: bold;">lld/trunk/ELF/Writer.cpp</span></div><div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; ">    First = Sec;
</div><div style="padding: 0 8px; margin: 0 4px; ">  H.p_align = std::max<typename ELFT::uint>(H.p_align, Sec->getAlignment());
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  if (H.p_type == PT_LOAD && !Config->OFormatBinary)
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    Sec->FirstInPtLoad = First;
</div><div style="padding: 0 8px; margin: 0 4px; ">}
</div><div style="padding: 0 8px; margin: 0 4px; ">
</div><div style="padding: 0 8px; margin: 0 4px; background: #F7F7F7; color: #74777D; border-style: dashed; border-color: #C7CCD9; border-width: 1px 0;">...</div><div style="padding: 0 8px; margin: 0 4px; ">  if (Config->Relocatable || !(Sec->getFlags() & SHF_ALLOC))
</div><div style="padding: 0 8px; margin: 0 4px; ">    return Off;
</div><div style="padding: 0 8px; margin: 0 4px; background: #ffd0d0;"><span class="bright">  return alignTo(Off, Config->MaxPageSize, Sec->getVA());</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  OutputSectionBase<ELFT> *First = Sec->FirstInPtLoad;
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // If two sections share the same PT_LOAD the file offset is calculated using
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  // this formula: Off2 = Off1 + (VA2 - VA1).
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  if (!First || Sec == First)
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">    return alignTo(Off, Target->MaxPageSize, Sec->getVA());
</div><div style="padding: 0 8px; margin: 0 4px; background: #d0ffd0;">  return First->getFileOffset() + Sec->getVA() - First->getVA();
</div><div style="padding: 0 8px; margin: 0 4px; ">}
</div></div></div></div></div><br />