[ELF] Fix LMA offset calculation

Differential revision: https://reviews.llvm.org/D30832

llvm-svn: 297713
This commit is contained in:
Eugene Leviant 2017-03-14 08:57:09 +00:00
parent 30c1b436ad
commit 5784e96f5c
2 changed files with 25 additions and 4 deletions

View File

@ -547,10 +547,6 @@ MemoryRegion *LinkerScript<ELFT>::findMemoryRegion(OutputSectionCommand *Cmd,
// for a single sections command (e.g. ".text { *(.text); }").
template <class ELFT>
void LinkerScript<ELFT>::assignOffsets(OutputSectionCommand *Cmd) {
if (Cmd->LMAExpr) {
uintX_t D = Dot;
LMAOffset = [=] { return Cmd->LMAExpr() - D; };
}
OutputSection *Sec = findSection<ELFT>(Cmd->Name, *OutputSections);
if (!Sec)
return;
@ -558,6 +554,11 @@ void LinkerScript<ELFT>::assignOffsets(OutputSectionCommand *Cmd) {
if (Cmd->AddrExpr && Sec->Flags & SHF_ALLOC)
setDot(Cmd->AddrExpr, Cmd->Location);
if (Cmd->LMAExpr) {
uintX_t D = Dot;
LMAOffset = [=] { return Cmd->LMAExpr() - D; };
}
// Handle align (e.g. ".foo : ALIGN(16) { ... }").
if (Cmd->AlignExpr)
Sec->updateAlignment(Cmd->AlignExpr());

View File

@ -18,6 +18,10 @@
# RUN: { \
# RUN: *(.ddd) \
# RUN: } \
# RUN: .eee 0x5000 : AT(0x5000) \
# RUN: { \
# RUN: *(.eee) \
# RUN: } \
# RUN: }" > %t.script
# RUN: ld.lld %t --script %t.script -o %t2
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
@ -79,6 +83,19 @@
# CHECK-NEXT: Offset: 0x1018
# CHECK-NEXT: VirtualAddress: 0x1018
# CHECK-NEXT: PhysicalAddress: 0x4000
# CHECK-NEXT: FileSize: 8
# CHECK-NEXT: MemSize: 8
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: PF_X
# CHECK-NEXT: ]
# CHECK-NEXT: Alignment: 4096
# CHECK-NEXT: }
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD
# CHECK-NEXT: Offset: 0x2000
# CHECK-NEXT: VirtualAddress: 0x5000
# CHECK-NEXT: PhysicalAddress: 0x5000
# CHECK-NEXT: FileSize: 9
# CHECK-NEXT: MemSize: 9
# CHECK-NEXT: Flags [
@ -117,3 +134,6 @@ _start:
.section .ddd, "a"
.quad 0
.section .eee, "a"
.quad 0