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.

llvm-svn: 304860
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 2e31bfd..444384d 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -268,22 +268,24 @@
       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
+    assignFileOffsetsBinary();
+
+  setPhdrs();
+
+  if (Config->Relocatable) {
+    for (OutputSectionCommand *Cmd : OutputSectionCommands)
+      Cmd->Sec->Addr = 0;
   } else {
-    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
-      assignFileOffsetsBinary();
-
-    setPhdrs();
     fixPredefinedSymbols();
   }