[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 04:25:07 PDT 2017


grimar updated this revision to Diff 98425.
grimar added a comment.
Herald added a subscriber: krytarowski.

- Addressed review comment.


https://reviews.llvm.org/D32793

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


Index: test/ELF/linkerscript/early-assign-symbol.s
===================================================================
--- test/ELF/linkerscript/early-assign-symbol.s
+++ 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: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ 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.98425.patch
Type: text/x-patch
Size: 1312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170510/a3310c01/attachment.bin>


More information about the llvm-commits mailing list