BSD linker scripts contain special cases to add NOP padding to code sections. Syntax is next:
.init:
{
KEEP (*(.init))
} =0x90909090(0x90 is NOP)
This patch implements that functionality.
Differential D17269
[ELF] - Implemented linkerscript sections padding. Authored by grimar on Feb 15 2016, 7:51 AM.
Details
Diff Detail Event Timeline
Comment Actions
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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); }