[PATCH] D30832: [ELF] Fix LMA offset calculation

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 08:33:17 PST 2017


evgeny777 created this revision.
evgeny777 added a project: lld.

Current revision has bug, which causes incorrect LMA offset calculation in section also specifies VMA, i.e:

  .foo 0x5000 : AT(0x5000) { *(.bar*) }

This happens because Dot is evaluated after being passed by value to lambda expression


Repository:
  rL LLVM

https://reviews.llvm.org/D30832

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/at.s


Index: test/ELF/linkerscript/at.s
===================================================================
--- test/ELF/linkerscript/at.s
+++ test/ELF/linkerscript/at.s
@@ -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 @@
 
 .section .ddd, "a"
 .quad 0
+
+.section .eee, "a"
+.quad 0
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -547,17 +547,17 @@
 // 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) - D; };
-  }
   OutputSection *Sec = findSection<ELFT>(Cmd->Name, *OutputSections);
   if (!Sec)
     return;
 
   if (Cmd->AddrExpr && Sec->Flags & SHF_ALLOC)
     setDot(Cmd->AddrExpr, Cmd->Location);
 
+  if (Cmd->LMAExpr) {
+    uintX_t D = Dot;
+    LMAOffset = [=] { return Cmd->LMAExpr(D) - D; };
+  }
   // Handle align (e.g. ".foo : ALIGN(16) { ... }").
   if (Cmd->AlignExpr)
     Sec->updateAlignment(Cmd->AlignExpr(0));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30832.91356.patch
Type: text/x-patch
Size: 1990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170310/9f11989e/attachment.bin>


More information about the llvm-commits mailing list