[lld] r300004 - Call getFiller only when filler is not zero.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 15:45:38 PDT 2017


Author: ruiu
Date: Tue Apr 11 17:45:38 2017
New Revision: 300004

URL: http://llvm.org/viewvc/llvm-project?rev=300004&view=rev
Log:
Call getFiller only when filler is not zero.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=300004&r1=300003&r2=300004&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Apr 11 17:45:38 2017
@@ -224,9 +224,6 @@ void OutputSection::sortCtorsDtors() {
 // Fill [Buf, Buf + Size) with Filler. Filler is written in big
 // endian order. This is used for linker script "=fillexp" command.
 static void fill(uint8_t *Buf, size_t Size, uint32_t Filler) {
-  if (Filler == 0)
-    return;
-
   uint8_t V[4];
   write32be(V, Filler);
   size_t I = 0;
@@ -235,7 +232,7 @@ static void fill(uint8_t *Buf, size_t Si
   memcpy(Buf + I, V, Size - I);
 }
 
-uint32_t OutputSection::getFill() {
+uint32_t OutputSection::getFiller() {
   // Determine what to fill gaps between InputSections with, as specified by the
   // linker script. If nothing is specified and this is an executable section,
   // fall back to trap instructions to prevent bad diassembly and detect invalid
@@ -250,24 +247,25 @@ uint32_t OutputSection::getFill() {
 template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) {
   Loc = Buf;
 
-  uint32_t Filler = getFill();
-
   // Write leading padding.
-  size_t FillSize = Sections.empty() ? Size : Sections[0]->OutSecOff;
-  fill(Buf, FillSize, Filler);
+  uint32_t Filler = getFiller();
+  if (Filler)
+    fill(Buf, Sections.empty() ? Size : Sections[0]->OutSecOff, Filler);
 
   parallelFor(0, Sections.size(), [=](size_t I) {
     InputSection *Sec = Sections[I];
     Sec->writeTo<ELFT>(Buf);
 
-    // Fill gaps between sections with the specified fill value.
-    uint8_t *Start = Buf + Sec->OutSecOff + Sec->getSize();
-    uint8_t *End;
-    if (I + 1 == Sections.size())
-      End = Buf + Size;
-    else
-      End = Buf + Sections[I + 1]->OutSecOff;
-    fill(Start, End - Start, Filler);
+    // Fill gaps between sections.
+    if (Filler) {
+      uint8_t *Start = Buf + Sec->OutSecOff + Sec->getSize();
+      uint8_t *End;
+      if (I + 1 == Sections.size())
+        End = Buf + Size;
+      else
+        End = Buf + Sections[I + 1]->OutSecOff;
+      fill(Start, End - Start, Filler);
+    }
   });
 
   // Linker scripts may have BYTE()-family commands with which you

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=300004&r1=300003&r2=300004&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Apr 11 17:45:38 2017
@@ -81,7 +81,7 @@ public:
   void sort(std::function<int(InputSectionBase *S)> Order);
   void sortInitFini();
   void sortCtorsDtors();
-  uint32_t getFill();
+  uint32_t getFiller();
   template <class ELFT> void writeTo(uint8_t *Buf);
   template <class ELFT> void finalize();
   void assignOffsets();




More information about the llvm-commits mailing list