[lld] r308692 - [ELF] Align the value if needed when computing the expression

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 16:11:47 PDT 2017


Author: phosek
Date: Thu Jul 20 16:11:47 2017
New Revision: 308692

URL: http://llvm.org/viewvc/llvm-project?rev=308692&view=rev
Log:
[ELF] Align the value if needed when computing the expression

Also add the test cases for the addition and subtraction both for
the relative and absolute case.

Differential Revision: https://reviews.llvm.org/D35346

Added:
    lld/trunk/test/ELF/linkerscript/Inputs/symbol-reserved.script
Modified:
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/linkerscript/symbol-reserved.s

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=308692&r1=308691&r2=308692&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Jul 20 16:11:47 2017
@@ -139,11 +139,13 @@ static void moveAbsRight(ExprValue &A, E
 
 static ExprValue add(ExprValue A, ExprValue B) {
   moveAbsRight(A, B);
-  return {A.Sec, A.ForceAbsolute, A.Val + B.getValue(), A.Loc};
+  uint64_t Val = alignTo(A.Val, A.Alignment) + B.getValue();
+  return {A.Sec, A.ForceAbsolute, Val, A.Loc};
 }
 
 static ExprValue sub(ExprValue A, ExprValue B) {
-  return {A.Sec, A.Val - B.getValue(), A.Loc};
+  uint64_t Val = alignTo(A.Val, A.Alignment) - B.getValue();
+  return {A.Sec, Val, A.Loc};
 }
 
 static ExprValue mul(ExprValue A, ExprValue B) {

Added: lld/trunk/test/ELF/linkerscript/Inputs/symbol-reserved.script
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/Inputs/symbol-reserved.script?rev=308692&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/symbol-reserved.script (added)
+++ lld/trunk/test/ELF/linkerscript/Inputs/symbol-reserved.script Thu Jul 20 16:11:47 2017
@@ -0,0 +1,5 @@
+SECTIONS
+{
+  .text : { *(.text) }
+  PROVIDE_HIDDEN(_end = .);
+}

Modified: lld/trunk/test/ELF/linkerscript/symbol-reserved.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-reserved.s?rev=308692&r1=308691&r2=308692&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-reserved.s (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-reserved.s Thu Jul 20 16:11:47 2017
@@ -17,6 +17,28 @@
 
 # ALIGNED: 0000000000200005 .text 00000000 .hidden newsym
 
+# RUN: echo "PROVIDE_HIDDEN(newsym = ALIGN(3, 8) + 10);" > %t.script
+# RUN: ld.lld -o %t1 %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=ALIGN-ADD %s
+# ALIGN-ADD: 0000000000000012 *ABS* 00000000 .hidden newsym
+
+# RUN: echo "PROVIDE_HIDDEN(newsym = ALIGN(11, 8) - 10);" > %t.script
+# RUN: ld.lld -o %t1 %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=ALIGN-SUB %s
+# ALIGN-SUB: 0000000000000006 *ABS* 00000000 .hidden newsym
+
+# RUN: echo "PROVIDE_HIDDEN(newsym = ALIGN(_end, CONSTANT(MAXPAGESIZE)) + 5);" > %t.script
+# RUN: ld.lld -o %t1 --script %p/Inputs/symbol-reserved.script %t %t.script
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=RELATIVE-ADD %s
+# RELATIVE-ADD: 0000000000001005 .text 00000000 .hidden newsym
+# RELATIVE-ADD: 0000000000000007 .text 00000000 .hidden _end
+
+# RUN: echo "PROVIDE_HIDDEN(newsym = ALIGN(_end, CONSTANT(MAXPAGESIZE)) - 5);" > %t.script
+# RUN: ld.lld -o %t1 --script %p/Inputs/symbol-reserved.script %t %t.script
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=RELATIVE-SUB %s
+# RELATIVE-SUB: 0000000000000ffb .text 00000000 .hidden newsym
+# RELATIVE-SUB: 0000000000000007 .text 00000000 .hidden _end
+
 .global _start
 _start:
   lea newsym(%rip),%rax




More information about the llvm-commits mailing list