[lld] r297713 - [ELF] Fix LMA offset calculation
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 01:57:09 PDT 2017
Author: evgeny777
Date: Tue Mar 14 03:57:09 2017
New Revision: 297713
URL: http://llvm.org/viewvc/llvm-project?rev=297713&view=rev
Log:
[ELF] Fix LMA offset calculation
Differential revision: https://reviews.llvm.org/D30832
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/at.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=297713&r1=297712&r2=297713&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Mar 14 03:57:09 2017
@@ -547,10 +547,6 @@ MemoryRegion *LinkerScript<ELFT>::findMe
// 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(O
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());
Modified: lld/trunk/test/ELF/linkerscript/at.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/at.s?rev=297713&r1=297712&r2=297713&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/at.s (original)
+++ lld/trunk/test/ELF/linkerscript/at.s Tue Mar 14 03:57:09 2017
@@ -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
More information about the llvm-commits
mailing list