forked from OSchip/llvm-project
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
This commit is contained in:
parent
661e2422d7
commit
a6acd23c53
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue