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

Ed Maste emaste at FreeBSD.org
Mon Jan 29 13:55:51 UTC 2018


Author: emaste
Date: Mon Jan 29 13:55:50 2018
New Revision: 328548
URL: https://svnweb.freebsd.org/changeset/base/328548

Log:
  lld: Put the header in the first PT_LOAD even if that PT_LOAD has a LMAExpr
  
  The root problem is that we were creating a PT_LOAD just for the header.
  That was technically valid, but inconvenient: we should not be making
  the ELF discontinuous.
  
  The solution is to allow a section with LMAExpr to be added to a PT_LOAD
  if that PT_LOAD doesn't already have a LMAExpr.
  
  LLVM PR:	36017
  Obtained from:	LLVM r323625 by Rafael Espindola

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

Modified: head/contrib/llvm/tools/lld/ELF/Writer.cpp
==============================================================================
--- head/contrib/llvm/tools/lld/ELF/Writer.cpp	Mon Jan 29 13:54:51 2018	(r328547)
+++ head/contrib/llvm/tools/lld/ELF/Writer.cpp	Mon Jan 29 13:55:50 2018	(r328548)
@@ -822,6 +822,8 @@ void PhdrEntry::add(OutputSection *Sec) {
   p_align = std::max(p_align, Sec->Alignment);
   if (p_type == PT_LOAD)
     Sec->PtLoad = this;
+  if (Sec->LMAExpr)
+    ASectionHasLMA = true;
 }
 
 // The beginning and the ending of .rel[a].plt section are marked
@@ -1626,8 +1628,9 @@ template <class ELFT> std::vector<PhdrEntry *> Writer<
     // different flags or is loaded at a discontiguous address using AT linker
     // script command.
     uint64_t NewFlags = computeFlags(Sec->getPhdrFlags());
-    if (Sec->LMAExpr || Sec->MemRegion != Load->FirstSec->MemRegion ||
-        Flags != NewFlags) {
+    if ((Sec->LMAExpr && Load->ASectionHasLMA) ||
+        Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) {
+
       Load = AddHdr(PT_LOAD, NewFlags);
       Flags = NewFlags;
     }

Modified: head/contrib/llvm/tools/lld/ELF/Writer.h
==============================================================================
--- head/contrib/llvm/tools/lld/ELF/Writer.h	Mon Jan 29 13:54:51 2018	(r328547)
+++ head/contrib/llvm/tools/lld/ELF/Writer.h	Mon Jan 29 13:55:50 2018	(r328548)
@@ -44,6 +44,11 @@ struct PhdrEntry {
   OutputSection *FirstSec = nullptr;
   OutputSection *LastSec = nullptr;
   bool HasLMA = false;
+
+  // True if any of the sections in this program header as a LMA specified via
+  // linker script: AT(addr).
+  bool ASectionHasLMA = false;
+
   uint64_t LMAOffset = 0;
 };
 


More information about the svn-src-all mailing list