[ELF] - Do not segfault when doing logical and/or operations on symbols that have no output sections.

Previously we would crash on samples from testcase,
because were trying to access zero pointer to output section.

Differential revision: https://reviews.llvm.org/D36145

llvm-svn: 311311
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index c146c46..ff89983 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -49,19 +49,24 @@
 
 LinkerScript *elf::Script;
 
+static uint64_t getOutputSectionVA(SectionBase *InputSec, StringRef Loc) {
+  if (OutputSection *OS = InputSec->getOutputSection())
+    return OS->Addr;
+  error(Loc + ": unable to evaluate expression: input section " +
+        InputSec->Name + " has no output section assigned");
+  return 0;
+}
+
 uint64_t ExprValue::getValue() const {
-  if (Sec) {
-    if (OutputSection *OS = Sec->getOutputSection())
-      return alignTo(Sec->getOffset(Val) + OS->Addr, Alignment);
-    error(Loc + ": unable to evaluate expression: input section " + Sec->Name +
-          " has no output section assigned");
-  }
+  if (Sec)
+    return alignTo(Sec->getOffset(Val) + getOutputSectionVA(Sec, Loc),
+                   Alignment);
   return alignTo(Val, Alignment);
 }
 
 uint64_t ExprValue::getSecAddr() const {
   if (Sec)
-    return Sec->getOffset(0) + Sec->getOutputSection()->Addr;
+    return Sec->getOffset(0) + getOutputSectionVA(Sec, Loc);
   return 0;
 }