[PATCH] D35651: [ELF] Align the value if needed when computing the expression

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 23:43:30 PDT 2017


phosek updated this revision to Diff 107447.
phosek edited the summary of this revision.

Repository:
  rL LLVM

https://reviews.llvm.org/D35651

Files:
  ELF/ScriptParser.cpp
  test/ELF/linkerscript/Inputs/symbol-reserved.script
  test/ELF/linkerscript/symbol-reserved.s


Index: test/ELF/linkerscript/symbol-reserved.s
===================================================================
--- test/ELF/linkerscript/symbol-reserved.s
+++ test/ELF/linkerscript/symbol-reserved.s
@@ -17,6 +17,12 @@
 
 # ALIGNED: 0000000000200005 .text 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 %s
+# RELATIVE: 0000000000001005         .text           00000000 .hidden newsym
+# RELATIVE: 0000000000000007         .text           00000000 .hidden _end
+
 .global _start
 _start:
   lea newsym(%rip),%rax
Index: test/ELF/linkerscript/Inputs/symbol-reserved.script
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/Inputs/symbol-reserved.script
@@ -0,0 +1,5 @@
+SECTIONS
+{
+  .text : { *(.text) }
+  PROVIDE_HIDDEN(_end = .);
+}
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -139,11 +139,13 @@
 
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35651.107447.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170720/f65e6a14/attachment.bin>


More information about the llvm-commits mailing list