[lld] r321390 - Result of subtracting two symbols should be absolute.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 13:55:28 PST 2017


Author: rafael
Date: Fri Dec 22 13:55:28 2017
New Revision: 321390

URL: http://llvm.org/viewvc/llvm-project?rev=321390&view=rev
Log:
Result of subtracting two symbols should be absolute.

When two linker script symbols are subtracted, the result should be absolute.

This is the behavior of binutils' ld.

Patch by Erick Reyes!

Modified:
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript/operators.s

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=321390&r1=321389&r2=321390&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Fri Dec 22 13:55:28 2017
@@ -151,6 +151,8 @@ static ExprValue add(ExprValue A, ExprVa
 }
 
 static ExprValue sub(ExprValue A, ExprValue B) {
+  if (!A.isAbsolute() && !B.isAbsolute())
+    return A.getValue() - B.getValue();
   return {A.Sec, false, A.getSectionOffset() - B.getValue(), A.Loc};
 }
 

Modified: lld/trunk/test/ELF/linkerscript/operators.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/operators.s?rev=321390&r1=321389&r2=321390&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/operators.s (original)
+++ lld/trunk/test/ELF/linkerscript/operators.s Fri Dec 22 13:55:28 2017
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 # RUN: echo "SECTIONS { \
+# RUN:  _start = .; \
 # RUN:  plus = 1 + 2 + 3; \
 # RUN:  minus = 5 - 1; \
 # RUN:  div = 6 / 2; \
@@ -26,6 +27,9 @@
 # RUN:  . = 0xfff0; \
 # RUN:  datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); \
 # RUN:  datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); \
+# RUN:  _end = .; \
+# RUN:  minus_rel = _end - 0x10; \
+# RUN:  minus_abs = _end - _start; \
 # RUN: }" > %t.script
 # RUN: ld.lld %t --script %t.script -o %t2
 # RUN: llvm-objdump -t %t2 | FileCheck %s
@@ -53,6 +57,8 @@
 # CHECK: 00000000001000 *ABS* 00000000 commonpagesize
 # CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
 # CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
+# CHECK: 0000000000ffe0 .text 00000000 minus_rel
+# CHECK: 0000000000fff0 *ABS* 00000000 minus_abs
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script




More information about the llvm-commits mailing list