summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/LinkerScript.cpp6
-rw-r--r--lld/ELF/LinkerScript.h1
-rw-r--r--lld/ELF/ScriptParser.cpp6
-rw-r--r--lld/test/ELF/linkerscript/align.s16
4 files changed, 20 insertions, 9 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 121f2fb0c37..3ccc2c9a66e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -70,6 +70,10 @@ uint64_t ExprValue::getSecAddr() const {
return 0;
}
+uint64_t ExprValue::getSectionOffset() const {
+ return getValue() - getSecAddr();
+}
+
static SymbolBody *addRegular(SymbolAssignment *Cmd) {
Symbol *Sym;
uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
@@ -141,7 +145,7 @@ void LinkerScript::assignSymbol(SymbolAssignment *Cmd, bool InSec) {
Sym->Value = V.getValue();
} else {
Sym->Section = V.Sec;
- Sym->Value = V.getValue() - V.getSecAddr();
+ Sym->Value = V.getSectionOffset();
}
}
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 0206b95384c..921bff05245 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -53,6 +53,7 @@ struct ExprValue {
bool isAbsolute() const { return ForceAbsolute || Sec == nullptr; }
uint64_t getValue() const;
uint64_t getSecAddr() const;
+ uint64_t getSectionOffset() const;
};
// This represents an expression in the linker script.
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 6a534e60cba..7d01bac1f39 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -147,13 +147,11 @@ static void moveAbsRight(ExprValue &A, ExprValue &B) {
static ExprValue add(ExprValue A, ExprValue B) {
moveAbsRight(A, B);
- uint64_t Val = alignTo(A.Val, A.Alignment) + B.getValue();
- return {A.Sec, A.ForceAbsolute, Val, A.Loc};
+ return {A.Sec, A.ForceAbsolute, A.getSectionOffset() + B.getValue(), A.Loc};
}
static ExprValue sub(ExprValue A, ExprValue B) {
- uint64_t Val = alignTo(A.Val, A.Alignment) - B.getValue();
- return {A.Sec, Val, A.Loc};
+ return {A.Sec, A.getSectionOffset() - B.getValue(), A.Loc};
}
static ExprValue mul(ExprValue A, ExprValue B) {
diff --git a/lld/test/ELF/linkerscript/align.s b/lld/test/ELF/linkerscript/align.s
index 7fdf02d7475..1d70fab45fe 100644
--- a/lld/test/ELF/linkerscript/align.s
+++ b/lld/test/ELF/linkerscript/align.s
@@ -84,16 +84,24 @@
# RUN: echo "SECTIONS { \
# RUN: . = 0xff8; \
-# RUN: .aaa : { *(.aaa) foo = ALIGN(., 0x100); bar = .; } \
-# RUN: .bbb : { *(.bbb); } \
-# RUN: .ccc : { *(.ccc); } \
-# RUN: .text : { *(.text); } \
+# RUN: .aaa : { \
+# RUN: *(.aaa) \
+# RUN: foo = ALIGN(., 0x100); \
+# RUN: bar = .; \
+# RUN: zed1 = ALIGN(., 0x100) + 1; \
+# RUN: zed2 = ALIGN(., 0x100) - 1; \
+# RUN: } \
+# RUN: .bbb : { *(.bbb); } \
+# RUN: .ccc : { *(.ccc); } \
+# RUN: .text : { *(.text); } \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=OFFSET %s
# OFFSET: 0000000000001000 .aaa 00000000 foo
# OFFSET: 0000000000001000 .aaa 00000000 bar
+# OFFSET: 0000000000001001 .aaa 00000000 zed1
+# OFFSET: 0000000000000fff .aaa 00000000 zed2
.global _start
_start:
OpenPOWER on IntegriCloud