Call getFiller only when filler is not zero.

llvm-svn: 300004
This commit is contained in:
Rui Ueyama 2017-04-11 22:45:38 +00:00
parent 0b5eed24c5
commit 8f8c2f9599
2 changed files with 15 additions and 17 deletions

View File

@ -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

View File

@ -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();