[PATCH] D36138: [ELF] - Don't segfault when accessing location counter inside MEMORY command.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 01:48:21 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL311073: [ELF] - Don't segfault when accessing location counter inside MEMORY command. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D36138?vs=109079&id=111479#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36138

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/memory-err.s


Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -842,8 +842,13 @@
 }
 
 ExprValue LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) {
-  if (S == ".")
-    return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr, Loc};
+  if (S == ".") {
+    if (CurAddressState)
+      return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr,
+              Loc};
+    error(Loc + ": unable to get location counter value");
+    return 0;
+  }
   if (SymbolBody *B = Symtab->find(S)) {
     if (auto *D = dyn_cast<DefinedRegular>(B))
       return {D->Section, D->Value, Loc};
Index: lld/trunk/test/ELF/linkerscript/memory-err.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/memory-err.s
+++ lld/trunk/test/ELF/linkerscript/memory-err.s
@@ -8,3 +8,9 @@
 # RUN: not ld.lld -shared -o %t2 --script %t.script %t 2>&1 |\
 # RUN:   FileCheck %s --check-prefix=ERR2
 # ERR2: error: {{.*}}.script:1: unable to calculate page size
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "MEMORY { name : ORIGIN = .; }" > %t.script
+# RUN: not ld.lld -shared -o %t2 --script %t.script %t 2>&1 |\
+# RUN:   FileCheck %s --check-prefix=ERR3
+# ERR3: error: {{.*}}.script:1: unable to get location counter value


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36138.111479.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170817/af0a5ae7/attachment.bin>


More information about the llvm-commits mailing list