[lld] r312983 - Align addresses, not offsets.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 17:06:00 PDT 2017
Author: rafael
Date: Mon Sep 11 17:06:00 2017
New Revision: 312983
URL: http://llvm.org/viewvc/llvm-project?rev=312983&view=rev
Log:
Align addresses, not offsets.
This fixes two more cases where we were aligning the offset in a
section, instead of the final address.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/align.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=312983&r1=312982&r2=312983&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Sep 11 17:06:00 2017
@@ -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(SymbolAs
Sym->Value = V.getValue();
} else {
Sym->Section = V.Sec;
- Sym->Value = V.getValue() - V.getSecAddr();
+ Sym->Value = V.getSectionOffset();
}
}
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=312983&r1=312982&r2=312983&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Mon Sep 11 17:06:00 2017
@@ -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.
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=312983&r1=312982&r2=312983&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Sep 11 17:06:00 2017
@@ -147,13 +147,11 @@ static void moveAbsRight(ExprValue &A, E
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) {
Modified: lld/trunk/test/ELF/linkerscript/align.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/align.s?rev=312983&r1=312982&r2=312983&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/align.s (original)
+++ lld/trunk/test/ELF/linkerscript/align.s Mon Sep 11 17:06:00 2017
@@ -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:
More information about the llvm-commits
mailing list