Skip to content

Instantly share code, notes, and snippets.

@rui314
Created March 31, 2017 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rui314/19a059a461dd787ebd4694aebb3b7658 to your computer and use it in GitHub Desktop.
Save rui314/19a059a461dd787ebd4694aebb3b7658 to your computer and use it in GitHub Desktop.
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index cda8a2b3f42..a77ae6acf73 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -238,8 +238,21 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) {
if (uint32_t Filler = Script->getFiller(this->Name))
fill(Buf, this->Size, Filler);
- parallelForEach(Sections.begin(), Sections.end(),
- [=](InputSection *IS) { IS->writeTo<ELFT>(Buf); });
+ parallelFor(0, Sections.size(), [=](size_t I) {
+ InputSection *Sec = Sections[I];
+ Sec->writeTo<ELFT>(Buf);
+
+ // Fill gaps between executable sections with INT3 or equivalent.
+ if (Sec->Flags & SHF_EXECINSTR) {
+ uint8_t *Start = Buf + Sec->OutSecOff + Sec->getSize();
+ uint8_t *End;
+ if (I + 1 == Sections.size())
+ End = Buf + this->Size;
+ else
+ End = Buf + Sections[I + 1]->OutSecOff;
+ fill(Start, End - Start, 0xcccccccc);
+ }
+ });
// Linker scripts may have BYTE()-family commands with which you
// can write arbitrary bytes to the output. Process them if any.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment