[lld] r304860 - Use assignAddresses with -r.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 19:24:08 PDT 2017


Author: rafael
Date: Tue Jun  6 21:24:08 2017
New Revision: 304860

URL: http://llvm.org/viewvc/llvm-project?rev=304860&view=rev
Log:
Use assignAddresses with -r.

Before this patch in -r we compute the OutputSection sizes early in
the various calls to assignOffsets. With this change we can remove
most of those calls.

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=304860&r1=304859&r2=304860&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Jun  6 21:24:08 2017
@@ -268,22 +268,24 @@ template <class ELFT> void Writer<ELFT>:
       OutputSectionCommands.begin(), OutputSectionCommands.end(),
       [](OutputSectionCommand *Cmd) { Cmd->maybeCompress<ELFT>(); });
 
-  if (Config->Relocatable) {
+  Script->assignAddresses(Phdrs, OutputSectionCommands);
+
+  // Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
+  // 0 sized region. This has to be done late since only after assignAddresses
+  // we know the size of the sections.
+  removeEmptyPTLoad();
+
+  if (!Config->OFormatBinary)
     assignFileOffsets();
-  } else {
-    Script->assignAddresses(Phdrs, OutputSectionCommands);
+  else
+    assignFileOffsetsBinary();
 
-    // Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
-    // 0 sized region. This has to be done late since only after assignAddresses
-    // we know the size of the sections.
-    removeEmptyPTLoad();
-
-    if (!Config->OFormatBinary)
-      assignFileOffsets();
-    else
-      assignFileOffsetsBinary();
+  setPhdrs();
 
-    setPhdrs();
+  if (Config->Relocatable) {
+    for (OutputSectionCommand *Cmd : OutputSectionCommands)
+      Cmd->Sec->Addr = 0;
+  } else {
     fixPredefinedSymbols();
   }
 




More information about the llvm-commits mailing list