svn commit: r328547 - head/contrib/llvm/tools/lld/ELF

Ed Maste emaste at FreeBSD.org
Mon Jan 29 13:54:53 UTC 2018


Author: emaste
Date: Mon Jan 29 13:54:51 2018
New Revision: 328547
URL: https://svnweb.freebsd.org/changeset/base/328547

Log:
  lld: Move LMAOffset from the OutputSection to the PhdrEntry. NFC.
  
  If two sections are in the same PT_LOAD, their relatives offsets,
  virtual address and physical addresses are all the same.
  
  [Rafael] initially wanted to have a single global LMAOffset, on the
  assumption that every ELF file was in practiced loaded contiguously in
  both physical and virtual memory.
  
  Unfortunately that is not the case. The linux kernel has:
  
    LOAD           0x200000 0xffffffff81000000 0x0000000001000000 0xced000 0xced000 R E 0x200000
    LOAD           0x1000000 0xffffffff81e00000 0x0000000001e00000 0x15f000 0x15f000 RW  0x200000
    LOAD           0x1200000 0x0000000000000000 0x0000000001f5f000 0x01b198 0x01b198 RW  0x200000
    LOAD           0x137b000 0xffffffff81f7b000 0x0000000001f7b000 0x116000 0x1ec000 RWE 0x200000
  
  The delta for all but the third PT_LOAD is the same:
  0xffffffff80000000. [Rafael] thinks the 3rd one is a hack for implementing
  per cpu data, but we can't break that.
  
  Obtained from:	LLVM r323456 by Rafael Espindola

Modified:
  head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp
  head/contrib/llvm/tools/lld/ELF/OutputSections.h
  head/contrib/llvm/tools/lld/ELF/Writer.h

Modified: head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp
==============================================================================
--- head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp	Mon Jan 29 13:52:42 2018	(r328546)
+++ head/contrib/llvm/tools/lld/ELF/LinkerScript.cpp	Mon Jan 29 13:54:51 2018	(r328547)
@@ -671,8 +671,8 @@ void LinkerScript::assignOffsets(OutputSection *Sec) {
   // will set the LMA such that the difference between VMA and LMA for the
   // section is the same as the preceding output section in the same region
   // https://sourceware.org/binutils/docs-2.20/ld/Output-Section-LMA.html
-  if (Ctx->LMAOffset)
-    Ctx->OutSec->LMAOffset = Ctx->LMAOffset;
+  if (PhdrEntry *L = Ctx->OutSec->PtLoad)
+    L->LMAOffset = Ctx->LMAOffset;
 
   // The Size previously denoted how many InputSections had been added to this
   // section, and was used for sorting SHF_LINK_ORDER sections. Reset it to

Modified: head/contrib/llvm/tools/lld/ELF/OutputSections.h
==============================================================================
--- head/contrib/llvm/tools/lld/ELF/OutputSections.h	Mon Jan 29 13:52:42 2018	(r328546)
+++ head/contrib/llvm/tools/lld/ELF/OutputSections.h	Mon Jan 29 13:54:51 2018	(r328547)
@@ -49,7 +49,7 @@ class OutputSection final : public BaseCommand, public
 
   static bool classof(const BaseCommand *C);
 
-  uint64_t getLMA() const { return Addr + LMAOffset; }
+  uint64_t getLMA() const { return PtLoad ? Addr + PtLoad->LMAOffset : Addr; }
   template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *SHdr);
 
   unsigned SectionIndex;
@@ -78,7 +78,6 @@ class OutputSection final : public BaseCommand, public
 
   // The following fields correspond to Elf_Shdr members.
   uint64_t Offset = 0;
-  uint64_t LMAOffset = 0;
   uint64_t Addr = 0;
   uint32_t ShName = 0;
 

Modified: head/contrib/llvm/tools/lld/ELF/Writer.h
==============================================================================
--- head/contrib/llvm/tools/lld/ELF/Writer.h	Mon Jan 29 13:52:42 2018	(r328546)
+++ head/contrib/llvm/tools/lld/ELF/Writer.h	Mon Jan 29 13:54:51 2018	(r328547)
@@ -44,6 +44,7 @@ struct PhdrEntry {
   OutputSection *FirstSec = nullptr;
   OutputSection *LastSec = nullptr;
   bool HasLMA = false;
+  uint64_t LMAOffset = 0;
 };
 
 void addReservedSymbols();


More information about the svn-src-head mailing list