[lld] r298094 - Refuse to add two non absolute symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 07:51:08 PDT 2017


Author: rafael
Date: Fri Mar 17 09:51:07 2017
New Revision: 298094

URL: http://llvm.org/viewvc/llvm-project?rev=298094&view=rev
Log:
Refuse to add two non absolute symbols.

Since there is no way to produce the correct answer at runtime, it is
probably better to just err.

Added:
    lld/trunk/test/ELF/linkerscript/expr-invalid-sec.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=298094&r1=298093&r2=298094&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Mar 17 09:51:07 2017
@@ -62,6 +62,8 @@ uint64_t ExprValue::getValue() const {
 static ExprValue add(ExprValue A, ExprValue B) {
   if (A.isAbsolute())
     std::swap(A, B);
+  if (!B.isAbsolute())
+    error("At least one side of the expression must be absolute");
   return {A.Sec, A.ForceAbsolute, A.Val + B.getValue()};
 }
 static ExprValue sub(ExprValue A, ExprValue B) {

Added: lld/trunk/test/ELF/linkerscript/expr-invalid-sec.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/expr-invalid-sec.s?rev=298094&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/expr-invalid-sec.s (added)
+++ lld/trunk/test/ELF/linkerscript/expr-invalid-sec.s Fri Mar 17 09:51:07 2017
@@ -0,0 +1,6 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { foo = ADDR(.text) + ADDR(.text); };" > %t.script
+# RUN: not ld.lld -o %t.so --script %t.script %t.o -shared 2>&1 | FileCheck %s
+
+# CHECK: At least one side of the expression must be absolute




More information about the llvm-commits mailing list