[PATCH] D17269: [ELF] - Implemented linkerscript sections padding.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 11:18:01 PST 2016


ruiu added inline comments.

================
Comment at: ELF/InputSection.cpp:250-261
@@ +249,14 @@
+
+  // If there is some padding behind and value for padding is
+  // not null, this one fills the space repeating 4 bytes of
+  // padding value.
+  if (PadBehind && OutSec->PaddingValue) {
+    llvm::support::ubig32_t Bytes(OutSec->PaddingValue);
+    int I = OutSecOff - PadBehind;
+    while (PadBehind) {
+      Buf[OutSecOff - PadBehind] =
+          ((uint8_t *)&Bytes)[(OutSecOff - PadBehind - I) % 4];
+      --PadBehind;
+    }
+  }
+
----------------
This is not a right place to add this code.  You want to add code to OutputSection<ELFT>::writeTo instead. I think the following code should suffice as an initial implementation.

  +static void fill(uint8_t *Buf, size_t Size, ArrayRef<uint8_t> A) {
  +  size_t I = 0;
  +  for (; I < Size; I += A.size())
  +    memcpy(Buf + I, A.data(), A.size());
  +  memcpy(Buf + I, A.data(), Size - I);
  +}
  +
   template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
  +  ArrayRef<uint8_t> Filler = Script->getFiller(Name);
  +  if (!Filler.empty())
  +    fill(Buf, getSize(), Filler);
     for (InputSection<ELFT> *C : Sections)
       C->writeTo(Buf);
   }


http://reviews.llvm.org/D17269





More information about the llvm-commits mailing list