Don't create dynamic relocations when its known what the got points to.

llvm-svn: 249485
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e25089d..61683ac 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -85,7 +85,7 @@
   Writer(SymbolTable *T)
       : SymTabSec(*T, StrTabSec, BssSec), DynSymSec(*T, DynStrSec, BssSec),
         RelaDynSec(DynSymSec, GotSec, BssSec, T->shouldUseRela()),
-        PltSec(GotSec), HashSec(DynSymSec),
+        GotSec(BssSec), PltSec(GotSec), HashSec(DynSymSec),
         DynamicSec(*T, HashSec, RelaDynSec, BssSec),
         BssSec(PltSec, GotSec, BssSec, ".bss", SHT_NOBITS,
                SHF_ALLOC | SHF_WRITE) {}
@@ -230,18 +230,14 @@
         if (Body->isInGot())
           continue;
         GotSec.addEntry(Body);
-        Body->setUsedInDynamicReloc();
-        RelaDynSec.addReloc({C, RI});
-        continue;
-      }
-      if (Body->isShared()) {
-        Body->setUsedInDynamicReloc();
-        RelaDynSec.addReloc({C, RI});
-        continue;
       }
     }
-    if (Config->Shared && !Target->isRelRelative(Type))
+    if (canBePreempted(Body)) {
+      Body->setUsedInDynamicReloc();
       RelaDynSec.addReloc({C, RI});
+    } else if (Config->Shared && !Target->isRelRelative(Type)) {
+      RelaDynSec.addReloc({C, RI});
+    }
   }
 }