[lld] r304513 - Run fabricateDefaultCommands before fixSectionAlignments.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 18:37:58 PDT 2017


Author: rafael
Date: Thu Jun  1 20:37:58 2017
New Revision: 304513

URL: http://llvm.org/viewvc/llvm-project?rev=304513&view=rev
Log:
Run fabricateDefaultCommands before fixSectionAlignments.

This allows us to remove the PageAlign field. It will also allow
moving fabricateDefaultCommands earlier.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304513&r1=304512&r2=304513&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Jun  1 20:37:58 2017
@@ -464,10 +464,6 @@ void LinkerScript::fabricateDefaultComma
     auto I = Config->SectionStartMap.find(Sec->Name);
     if (I != Config->SectionStartMap.end())
       OSCmd->AddrExpr = [=] { return I->second; };
-    else if (Sec->PageAlign)
-      OSCmd->AddrExpr = [=] {
-        return alignTo(Script->getDot(), Config->MaxPageSize);
-      };
 
     Commands.push_back(OSCmd);
     if (Sec->Sections.size()) {

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=304513&r1=304512&r2=304513&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Thu Jun  1 20:37:58 2017
@@ -59,10 +59,6 @@ public:
       Alignment = Val;
   }
 
-  // If true, this section will be page aligned on disk.
-  // Typically the first section of each PT_LOAD segment has this flag.
-  bool PageAlign = false;
-
   // Pointer to the first section in PT_LOAD segment, which this section
   // also resides in. This field is used to correctly compute file offset
   // of a section. When two sections share the same load segment, difference

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=304513&r1=304512&r2=304513&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Jun  1 20:37:58 2017
@@ -258,9 +258,9 @@ template <class ELFT> void Writer<ELFT>:
     return;
 
   if (!Script->Opt.HasSections) {
+    Script->fabricateDefaultCommands();
     if (!Config->Relocatable)
       fixSectionAlignments();
-    Script->fabricateDefaultCommands();
   } else {
     Script->synchronize();
   }
@@ -1504,15 +1504,23 @@ void Writer<ELFT>::addPtArmExid(std::vec
 // first section after PT_GNU_RELRO have to be page aligned so that the dynamic
 // linker can set the permissions.
 template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
+  auto PageAlign = [](OutputSection *Sec) {
+    OutputSectionCommand *Cmd = Script->getCmd(Sec);
+    if (Cmd && !Cmd->AddrExpr)
+      Cmd->AddrExpr = [=] {
+        return alignTo(Script->getDot(), Config->MaxPageSize);
+      };
+  };
+
   for (const PhdrEntry &P : Phdrs)
     if (P.p_type == PT_LOAD && P.First)
-      P.First->PageAlign = true;
+      PageAlign(P.First);
 
   for (const PhdrEntry &P : Phdrs) {
     if (P.p_type != PT_GNU_RELRO)
       continue;
     if (P.First)
-      P.First->PageAlign = true;
+      PageAlign(P.First);
     // Find the first section after PT_GNU_RELRO. If it is in a PT_LOAD we
     // have to align it to a page.
     auto End = OutputSections.end();
@@ -1521,7 +1529,7 @@ template <class ELFT> void Writer<ELFT>:
       continue;
     OutputSection *Sec = *(I + 1);
     if (needsPtLoad(Sec))
-      Sec->PageAlign = true;
+      PageAlign(Sec);
   }
 }
 




More information about the llvm-commits mailing list