[lld] r265131 - Split Writer::assignAddresses(): extract common code to fixFileOff(). NFC.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 04:04:47 PDT 2016


Author: grimar
Date: Fri Apr  1 06:04:47 2016
New Revision: 265131

URL: http://llvm.org/viewvc/llvm-project?rev=265131&view=rev
Log:
Split Writer::assignAddresses(): extract common code to fixFileOff(). NFC.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265131&r1=265130&r2=265131&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Apr  1 06:04:47 2016
@@ -1369,19 +1369,25 @@ template <class ELFT> void Writer<ELFT>:
   }
 }
 
+template <class ELFT, class uintX_t>
+static uintX_t fixFileOff(uintX_t FileOff, uintX_t Align,
+                          OutputSectionBase<ELFT> *Sec) {
+  if (Sec->getType() != SHT_NOBITS)
+    FileOff = alignTo(FileOff, Align);
+  Sec->setFileOffset(FileOff);
+  if (Sec->getType() != SHT_NOBITS)
+    FileOff += Sec->getSize();
+  return FileOff;
+}
+
 // Used for relocatable output (-r). In this case we create only ELF file
 // header, do not create program headers. Also assign of section addresses
 // is very straightforward: we just put all sections sequentually to the file.
 template <class ELFT> void Writer<ELFT>::assignAddressesRelocatable() {
   Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
   uintX_t FileOff = 0;
-  for (OutputSectionBase<ELFT> *Sec : OutputSections) {
-    if (Sec->getType() != SHT_NOBITS)
-      FileOff = alignTo(FileOff, Sec->getAlign());
-    Sec->setFileOffset(FileOff);
-    if (Sec->getType() != SHT_NOBITS)
-      FileOff += Sec->getSize();
-  }
+  for (OutputSectionBase<ELFT> *Sec : OutputSections)
+    FileOff = fixFileOff(FileOff, Sec->getAlign(), Sec);
   SectionHeaderOff = alignTo(FileOff, sizeof(uintX_t));
   FileSize = SectionHeaderOff + getNumSections() * sizeof(Elf_Shdr);
 }
@@ -1401,12 +1407,7 @@ template <class ELFT> void Writer<ELFT>:
     uintX_t Align = Sec->getAlign();
     if (Sec->PageAlign)
       Align = std::max<uintX_t>(Align, Target->PageSize);
-
-    if (Sec->getType() != SHT_NOBITS)
-      FileOff = alignTo(FileOff, Align);
-    Sec->setFileOffset(FileOff);
-    if (Sec->getType() != SHT_NOBITS)
-      FileOff += Sec->getSize();
+    FileOff = fixFileOff(FileOff, Align, Sec);
 
     // We only assign VAs to allocated sections.
     if (needsPtLoad<ELFT>(Sec)) {




More information about the llvm-commits mailing list