[PATCH] D30886: [ELF] Pad x86 executable sections with 0xcc int3 instructions

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 31 13:04:42 PDT 2017


ruiu added a comment.

This seems to be updating too many function just to fill section gaps with INT3 or equivalent. Doesn't something like this work? (This is a rough patch, so not all tests pass, but I think you can get an idea.)

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(),
[X] (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.


https://reviews.llvm.org/D30886





More information about the llvm-commits mailing list