[ELF] Linkerscript: fix bug in assignOffsets (check Sym for non-null)

llvm-svn: 278663
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index ca5ab37..d5748f8 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -319,8 +319,10 @@
       uintX_t Value = L->Cmd->Expression(Sec->getVA() + Off) - Sec->getVA();
       if (L->Cmd->Name == ".") {
         Off = Value;
-      } else {
-        auto *Sym = cast<DefinedSynthetic<ELFT>>(L->Cmd->Sym);
+      } else if (auto *Sym =
+                     cast_or_null<DefinedSynthetic<ELFT>>(L->Cmd->Sym)) {
+        // shouldDefine could have returned false, so we need to check Sym,
+        // for non-null value.
         Sym->Section = OutSec;
         Sym->Value = Value;
       }