[PATCH] D106665: [lld/mac] Let OutputSegment store its start address

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 08:44:22 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9482aa98e551: [lld/mac] Let OutputSegment store its start address (authored by thakis).
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106665/new/

https://reviews.llvm.org/D106665

Files:
  lld/MachO/OutputSection.cpp
  lld/MachO/OutputSegment.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/Writer.cpp


Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -239,10 +239,7 @@
     c->maxprot = seg->maxProt;
     c->initprot = seg->initProt;
 
-    if (seg->getSections().empty())
-      return;
-
-    c->vmaddr = seg->firstSection()->addr;
+    c->vmaddr = seg->addr;
     c->vmsize = seg->vmSize;
     c->filesize = seg->fileSize;
     c->nsects = seg->numNonHiddenSections();
@@ -980,6 +977,7 @@
   for (OutputSegment *seg : outputSegments) {
     if (seg == linkEditSegment)
       continue;
+    seg->addr = addr;
     assignAddresses(seg);
     // codesign / libstuff checks for segment ordering by verifying that
     // `fileOff + fileSize == next segment fileOff`. So we call alignTo() before
@@ -987,7 +985,7 @@
     // contiguous. We handle addr / vmSize similarly for the same reason.
     fileOff = alignTo(fileOff, pageSize);
     addr = alignTo(addr, pageSize);
-    seg->vmSize = addr - seg->firstSection()->addr;
+    seg->vmSize = addr - seg->addr;
     seg->fileSize = fileOff - seg->fileOff;
   }
 }
@@ -1013,9 +1011,10 @@
 
   // Now that __LINKEDIT is filled out, do a proper calculation of its
   // addresses and offsets.
+  linkEditSegment->addr = addr;
   assignAddresses(linkEditSegment);
   // No need to page-align fileOff / addr here since this is the last segment.
-  linkEditSegment->vmSize = addr - linkEditSegment->firstSection()->addr;
+  linkEditSegment->vmSize = addr - linkEditSegment->addr;
   linkEditSegment->fileSize = fileOff - linkEditSegment->fileOff;
 }
 
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -693,7 +693,7 @@
   OutputSegment *dataSeg = in.lazyPointers->parent;
   os << static_cast<uint8_t>(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB |
                              dataSeg->index);
-  uint64_t offset = in.lazyPointers->addr - dataSeg->firstSection()->addr +
+  uint64_t offset = in.lazyPointers->addr - dataSeg->addr +
                     sym.stubsIndex * target->wordSize;
   encodeULEB128(offset, os);
   encodeDylibOrdinal(ordinalForDylibSymbol(sym), os);
Index: lld/MachO/OutputSegment.h
===================================================================
--- lld/MachO/OutputSegment.h
+++ lld/MachO/OutputSegment.h
@@ -39,9 +39,6 @@
 
 class OutputSegment {
 public:
-  const OutputSection *firstSection() const { return sections.front(); }
-  const OutputSection *lastSection() const { return sections.back(); }
-
   void addOutputSection(OutputSection *os);
   void sortOutputSections();
 
@@ -50,6 +47,7 @@
 
   uint64_t fileOff = 0;
   uint64_t fileSize = 0;
+  uint64_t addr = 0;
   uint64_t vmSize = 0;
   int inputOrder = UnspecifiedInputOrder;
   StringRef name;
Index: lld/MachO/OutputSection.cpp
===================================================================
--- lld/MachO/OutputSection.cpp
+++ lld/MachO/OutputSection.cpp
@@ -14,5 +14,5 @@
 using namespace lld::macho;
 
 uint64_t OutputSection::getSegmentOffset() const {
-  return addr - parent->firstSection()->addr;
+  return addr - parent->addr;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106665.361239.patch
Type: text/x-patch
Size: 3210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210723/0c9b295f/attachment.bin>


More information about the llvm-commits mailing list