[PATCH] D32793: [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 07:36:50 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL302668: [ELF] - Don't segfault when assigning non-calculatable absolute symbol value. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D32793?vs=98425&id=98455#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32793

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/early-assign-symbol.s


Index: lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
+++ lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); }" > %t1.script
+# RUN: not ld.lld -o %t --script %t1.script %t.o 2>&1 | FileCheck %s
+
+# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; }" > %t2.script
+# RUN: not ld.lld -o %t --script %t2.script %t.o 2>&1 | FileCheck %s
+
+# CHECK: error: unable to evaluate expression: input section .text has no output section assigned
+
+.section .text
+.globl foo
+foo:
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -48,8 +48,12 @@
 LinkerScript *elf::Script;
 
 uint64_t ExprValue::getValue() const {
-  if (Sec)
-    return Sec->getOffset(Val) + Sec->getOutputSection()->Addr;
+  if (Sec) {
+    if (Sec->getOutputSection())
+      return Sec->getOffset(Val) + Sec->getOutputSection()->Addr;
+    error("unable to evaluate expression: input section " + Sec->Name +
+          " has no output section assigned");
+  }
   return Val;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32793.98455.patch
Type: text/x-patch
Size: 1372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170510/abfe2f53/attachment.bin>


More information about the llvm-commits mailing list