[PATCH] D19416: [ELF] - Assign correct value to Phdr's p_offset field.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 13:42:17 PDT 2016


ruiu added inline comments.

================
Comment at: ELF/Writer.cpp:1641-1644
@@ -1640,1 +1640,6 @@
 
+// System V ABI 4.1 specifies that program header's
+// p_vaddr should equal p_offset, modulo p_align.
+// (http://www.x86-64.org/documentation/abi.pdf, p.76),
+// this method used to adjust sections file offsets.
+template <class ELFT, class uintX_t>
----------------
  // Adjusts the file alignment for a given output section and returns
  // its new file offset. The file offset must be the same with its
  // virtual address (modulo the page size) so that the loader can load
  // executables without any address adjustment.

================
Comment at: ELF/Writer.cpp:1646
@@ +1645,3 @@
+template <class ELFT, class uintX_t>
+static uintX_t alignOffset(uintX_t Off, uintX_t Align,
+                           OutputSectionBase<ELFT> *Sec) {
----------------
Rename this getFileAlignment.

================
Comment at: ELF/Writer.cpp:1674-1676
@@ -1650,4 +1673,5 @@
     }
     uintX_t Align = Sec->getAlign();
     if (Sec->PageAlign)
       Align = std::max<uintX_t>(Align, Target->PageSize);
+    Off = alignOffset<ELFT>(Off, Align, Sec);
----------------
You want to move these three lines of code to the new function because it handles alignment as well. Then you can remove `Align` parameter from the function.


http://reviews.llvm.org/D19416





More information about the llvm-commits mailing list