diff options
-rw-r--r-- | lld/ELF/OutputSections.cpp | 30 | ||||
-rw-r--r-- | lld/ELF/OutputSections.h | 2 |
2 files changed, 15 insertions, 17 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index b721dd947ae..18a20fe7eb0 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -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 Size, uint32_t Filler) { 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 diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 1e27b9070fa..0ae3df5f785 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -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(); |