[PATCH] D35803: [ELF] - Fix calculation of memory region offset.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 01:30:17 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL308955: [ELF] - Fix calculation of memory region offset. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D35803?vs=107915&id=108017#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35803

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/memory2.s


Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -550,6 +550,7 @@
 }
 
 void LinkerScript::output(InputSection *S) {
+  uint64_t Before = advance(0, 1);
   uint64_t Pos = advance(S->getSize(), S->Alignment);
   S->OutSecOff = Pos - S->getSize() - CurAddressState->OutSec->Addr;
 
@@ -563,7 +564,7 @@
   if (CurAddressState->MemRegion) {
     uint64_t &CurOffset =
         CurAddressState->MemRegionOffset[CurAddressState->MemRegion];
-    CurOffset += CurAddressState->OutSec->Size;
+    CurOffset += Pos - Before;
     uint64_t CurSize = CurOffset - CurAddressState->MemRegion->Origin;
     if (CurSize > CurAddressState->MemRegion->Length) {
       uint64_t OverflowAmt = CurSize - CurAddressState->MemRegion->Length;
Index: lld/trunk/test/ELF/linkerscript/memory2.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/memory2.s
+++ lld/trunk/test/ELF/linkerscript/memory2.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \
+# RUN: SECTIONS { .text : { *(.text*) } > ram }" > %t.script
+# RUN: ld.lld -o %t2 --script %t.script %t
+
+.text
+.global _start
+_start:
+  .zero 1024
+
+.section .text.foo,"ax",%progbits
+foo:
+  nop


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35803.108017.patch
Type: text/x-patch
Size: 1429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170725/7c351986/attachment.bin>


More information about the llvm-commits mailing list