[PATCH] D12788: [elf2] Combine adjacent compatible OutputSections in PT_LOADs.

Rafael Ávila de Espíndola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 14:18:21 PDT 2015


rafael added inline comments.

================
Comment at: ELF/Writer.cpp:835
@@ +834,3 @@
+  // Create a PHDR for the first output section.
+  PHDRs.push_back(new (PAlloc) ProgramHeader<ELFT::Is64Bits>(
+      PT_LOAD, convertSectionFlagsToPHDRFlags(OutputSections[0]->getFlags())));
----------------
This creates an output section even if the section is empty.


================
Comment at: ELF/Writer.cpp:847
@@ -774,7 +846,3 @@
 
-    // Since each output section gets its own PHDR, align each output section to
-    // a page.
-    if (outputSectionHasPHDR<ELFT>(Sec)) {
-      ++NumPhdrs;
-      VA = RoundUpToAlignment(VA, PageSize);
-      FileOff = RoundUpToAlignment(FileOff, PageSize);
+    if (Sec->getSize()) {
+      uintX_t Flags = convertSectionFlagsToPHDRFlags(Sec->getFlags());
----------------
This does not. We should to treat the first section specially. What I would suggest is to have a "ProgramHeader *LastHeader" variable and initialize it to the file header program header.

In the loop you can check if the current section is compatible with the previous one. If not, create a new one and add to LastHeader.

Note in particular that if the first section that needs a program header is read only, the original program header gets extended.

================
Comment at: test/elf2/program-header-layout.s:3
@@ +2,3 @@
+# RUN: lld -flavor gnu2 %t -o %t2
+# RUN: llvm-readobj -program-headers %t2 \
+# RUN:   | FileCheck %s
----------------
It doesn't fit in 80 columns?


http://reviews.llvm.org/D12788





More information about the llvm-commits mailing list