Align addresses, not offsets.
This fixes two more cases where we were aligning the offset in a
section, instead of the final address.
llvm-svn: 312983
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 121f2fb..3ccc2c9 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -70,6 +70,10 @@
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 @@
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 0206b95..921bff0 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -53,6 +53,7 @@
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 6a534e6..7d01bac 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -147,13 +147,11 @@
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 7fdf02d..1d70fab 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: