From 039fb8c2967efffacaf2150748fcad9dbe99ab4d Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Thu, 20 Jul 2017 23:11:47 +0000 Subject: [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 --- lld/ELF/ScriptParser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lld/ELF/ScriptParser.cpp') 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) { -- cgit v1.2.3