[lld] r316742 - Simplify logic to find the last executable segment. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 22:08:39 PDT 2017


Author: ruiu
Date: Thu Oct 26 22:08:39 2017
New Revision: 316742

URL: http://llvm.org/viewvc/llvm-project?rev=316742&view=rev
Log:
Simplify logic to find the last executable segment. NFC.

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=316742&r1=316741&r2=316742&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 26 22:08:39 2017
@@ -1858,18 +1858,13 @@ template <class ELFT> void Writer<ELFT>:
   // 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.




More information about the llvm-commits mailing list