[lld] r310886 - Update comments as the function does not write to the first page anymore.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 14:18:12 PDT 2017
Author: ruiu
Date: Mon Aug 14 14:18:12 2017
New Revision: 310886
URL: http://llvm.org/viewvc/llvm-project?rev=310886&view=rev
Log:
Update comments as the function does not write to the first page anymore.
Also refactored the code a bit.
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=310886&r1=310885&r2=310886&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 14 14:18:12 2017
@@ -1851,31 +1851,31 @@ template <class ELFT> void Writer<ELFT>:
Sec->writeTo<ELFT>(Buf + Sec->Offset);
}
-static void fillTrapInstr(uint8_t *I, uint8_t *End) {
+static void fillTrap(uint8_t *I, uint8_t *End) {
for (; I + 4 < End; I += 4)
memcpy(I, &Target->TrapInstr, 4);
}
-
-// Fill the first and the last page of executable segments with trap
-// instructions instead of leaving them as zero. Even though it is not required
-// by any standard , it is in general a good thing to do for security reasons.
+// Fill the last page of executable segments with trap instructions
+// instead of leaving them as zero. Even though it is not required by any
+// standard, it is in general a good thing to do for security reasons.
+//
+// We'll leave other pages in segments as-is because the rest will be
+// overwritten by output sections.
template <class ELFT> void Writer<ELFT>::writeTrapInstr() {
if (Script->Opt.HasSections)
return;
+ // Fill the last page.
uint8_t *Buf = Buffer->getBufferStart();
+ for (PhdrEntry *P : Phdrs)
+ if (P->p_type == PT_LOAD && (P->p_flags & PF_X))
+ fillTrap(Buf + alignDown(P->p_offset + P->p_filesz, Target->PageSize),
+ Buf + alignTo(P->p_offset + P->p_filesz, Target->PageSize));
- for (PhdrEntry *P : Phdrs) {
- if (P->p_type != PT_LOAD || !(P->p_flags & PF_X))
- continue;
-
- // We only fill the last page of the segment because the rest will be
- // overwritten by output sections.
- fillTrapInstr(Buf + alignDown(P->p_offset + P->p_filesz, Target->PageSize),
- Buf + alignTo(P->p_offset + P->p_filesz, Target->PageSize));
- }
-
+ // Round up the file size of the last segment to the page boundary iff it is
+ // an executable segment to ensure that other other tools don't accidentally
+ // trim the instruction padding (e.g. when stripping the file).
PhdrEntry *LastRX = nullptr;
for (PhdrEntry *P : Phdrs) {
if (P->p_type != PT_LOAD)
@@ -1885,10 +1885,6 @@ template <class ELFT> void Writer<ELFT>:
else
LastRX = nullptr;
}
-
- // Round up the file size of the last segment to the page boundary iff it is
- // an executable segment to ensure that other other tools don't accidentally
- // trim the instruction padding (e.g. when stripping the file).
if (LastRX)
LastRX->p_filesz = alignTo(LastRX->p_filesz, Target->PageSize);
}
More information about the llvm-commits
mailing list