Store the offset in the output section, no in the file.

That is the value that is stable as the we layout the output sections.

llvm-svn: 244904
diff --git a/lld/ELF/Chunks.cpp b/lld/ELF/Chunks.cpp
index 9121a78..aaae6e8 100644
--- a/lld/ELF/Chunks.cpp
+++ b/lld/ELF/Chunks.cpp
@@ -33,7 +33,7 @@
     return;
   // Copy section contents from source object file to output file.
   ArrayRef<uint8_t> Data = *Obj->getSectionContents(Header);
-  memcpy(Buf + FileOff, Data.data(), Data.size());
+  memcpy(Buf + OutputSectionOff, Data.data(), Data.size());
 
   // FIXME: Relocations
 }
diff --git a/lld/ELF/Chunks.h b/lld/ELF/Chunks.h
index 1462724..f953cfe 100644
--- a/lld/ELF/Chunks.h
+++ b/lld/ELF/Chunks.h
@@ -37,17 +37,18 @@
   virtual void writeTo(uint8_t *Buf) = 0;
 
   // The writer sets and uses the addresses.
-  uint64_t getFileOff() { return FileOff; }
+  uint64_t getOutputSectionOff() { return OutputSectionOff; }
   uint32_t getAlign() { return Align; }
-  void setFileOff(uint64_t V) { FileOff = V; }
+  void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
 
   // Returns the section name if this is a section chunk.
   // It is illegal to call this function on non-section chunks.
   virtual StringRef getSectionName() const = 0;
 
 protected:
-  // The offset from beginning of the output file. The writer sets a value.
-  uint64_t FileOff = 0;
+  // The offset from beginning of the output sections this chunk was assigned
+  // to. The writer sets a value.
+  uint64_t OutputSectionOff = 0;
 
   // The alignment of this chunk. The writer uses the value.
   uint32_t Align = 1;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 79ab880..77093cf 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -50,8 +50,8 @@
 
   // Returns the size of the section in the output file.
   uintX_t getSize() { return Header.sh_size; }
-
   uintX_t getFlags() { return Header.sh_flags; }
+  uintX_t getOffset() { return Header.sh_offset; }
 
 private:
   StringRef Name;
@@ -122,8 +122,6 @@
   if (Header.sh_size == 0)
     return;
   Header.sh_offset = Off;
-  for (Chunk *C : Chunks)
-    C->setFileOff(C->getFileOff() + Off);
 }
 
 template <class ELFT>
@@ -131,7 +129,7 @@
   Chunks.push_back(C);
   uintX_t Off = Header.sh_size;
   Off = RoundUpToAlignment(Off, C->getAlign());
-  C->setFileOff(Off);
+  C->setOutputSectionOff(Off);
   Off += C->getSize();
   Header.sh_size = Off;
   Header.sh_type = C->getSectionHdr()->sh_type;
@@ -275,8 +273,9 @@
 template <class ELFT> void Writer<ELFT>::writeSections() {
   uint8_t *Buf = Buffer->getBufferStart();
   for (OutputSection<ELFT> *Sec : OutputSections) {
+    uint8_t *SecBuf = Buf + Sec->getOffset();
     for (Chunk *C : Sec->getChunks())
-      C->writeTo(Buf);
+      C->writeTo(SecBuf);
   }
 
   // String table.