Simplify logic to find the last executable segment. NFC.

llvm-svn: 316742
This commit is contained in:
Rui Ueyama 2017-10-27 05:08:39 +00:00
parent df15559c80
commit 0f46e45b03
1 changed files with 7 additions and 12 deletions

View File

@ -1858,18 +1858,13 @@ template <class ELFT> void Writer<ELFT>::writeTrapInstr() {
// Round up the file size of the last segment to the page boundary iff it is
// an executable segment to ensure that 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)
continue;
if (P->p_flags & PF_X)
LastRX = P;
else
LastRX = nullptr;
}
if (LastRX)
LastRX->p_memsz = LastRX->p_filesz =
alignTo(LastRX->p_filesz, Target->PageSize);
PhdrEntry *Last = nullptr;
for (PhdrEntry *P : Phdrs)
if (P->p_type == PT_LOAD)
Last = P;
if (Last && (Last->p_flags & PF_X))
Last->p_memsz = Last->p_filesz = alignTo(Last->p_filesz, Target->PageSize);
}
// Write section contents to a mmap'ed file.