diff options
author | Petr Hosek <phosek@chromium.org> | 2017-07-20 23:11:47 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2017-07-20 23:11:47 +0000 |
commit | 039fb8c2967efffacaf2150748fcad9dbe99ab4d (patch) | |
tree | 0f91b4cdaf53300c4e4d2ab227fb15c7680720a5 /lld | |
parent | b4c351dfd1d07ca7aa3f8e1c9fa25588d95b8638 (diff) | |
download | bcm5719-llvm-039fb8c2967efffacaf2150748fcad9dbe99ab4d.tar.gz bcm5719-llvm-039fb8c2967efffacaf2150748fcad9dbe99ab4d.zip |
[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
llvm-svn: 308692
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 6 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/Inputs/symbol-reserved.script | 5 | ||||
-rw-r--r-- | lld/test/ELF/linkerscript/symbol-reserved.s | 22 |
3 files changed, 31 insertions, 2 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 531c61e6cb4..29570c80d2f 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -139,11 +139,13 @@ static void moveAbsRight(ExprValue &A, ExprValue &B) { 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) { diff --git a/lld/test/ELF/linkerscript/Inputs/symbol-reserved.script b/lld/test/ELF/linkerscript/Inputs/symbol-reserved.script new file mode 100644 index 00000000000..269bb120de9 --- /dev/null +++ b/lld/test/ELF/linkerscript/Inputs/symbol-reserved.script @@ -0,0 +1,5 @@ +SECTIONS +{ + .text : { *(.text) } + PROVIDE_HIDDEN(_end = .); +} diff --git a/lld/test/ELF/linkerscript/symbol-reserved.s b/lld/test/ELF/linkerscript/symbol-reserved.s index e0b25959738..23f164e94d0 100644 --- a/lld/test/ELF/linkerscript/symbol-reserved.s +++ b/lld/test/ELF/linkerscript/symbol-reserved.s @@ -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 |