[PATCH] D60744: lld: elf: Fix sections with explict addresses in regions

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 19:35:32 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL358638: lld: elf: Fix sections with explict addresses in regions (authored by ruiu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60744?vs=195388&id=195663#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60744/new/

https://reviews.llvm.org/D60744

Files:
  lld/trunk/ELF/LinkerScript.cpp
  lld/trunk/test/ELF/linkerscript/out-of-order-section-in-region.s


Index: lld/trunk/test/ELF/linkerscript/out-of-order-section-in-region.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/out-of-order-section-in-region.s
+++ lld/trunk/test/ELF/linkerscript/out-of-order-section-in-region.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+# RUN: echo "MEMORY {                                       \
+# RUN:   REGION (rwx) : ORIGIN = 0x1000, LENGTH = 0x100     \
+# RUN: }                                                    \
+# RUN:                                                      \
+# RUN: SECTIONS {                                           \
+# RUN:   .aaa ORIGIN(REGION) + 0x8 : { *(.aaa) } > REGION   \
+# RUN:   _stext = .;                                        \
+# RUN:   .bbb ORIGIN(REGION) : { *(.bbb) } > REGION         \
+# RUN:   . = _stext;                                        \
+# RUN: }" > %t.script
+# RUN: ld.lld %t --script %t.script -o %t2
+# RUN: llvm-objdump -section-headers %t2 | FileCheck %s
+# CHECK: .aaa        00000008 0000000000001008 DATA
+# CHECK: .bbb        00000008 0000000000001000 DATA
+
+.section .aaa, "a"
+.quad 0
+
+.section .bbb, "a"
+.quad 0
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -135,7 +135,7 @@
   // Update to location counter means update to section size.
   if (InSec)
     expandOutputSection(Val - Dot);
-  else
+  else if (Val > Dot)
     expandMemoryRegions(Val - Dot);
 
   Dot = Val;
@@ -760,14 +760,15 @@
 void LinkerScript::assignOffsets(OutputSection *Sec) {
   if (!(Sec->Flags & SHF_ALLOC))
     Dot = 0;
-  else if (Sec->AddrExpr)
-    setDot(Sec->AddrExpr, Sec->Location, false);
 
   Ctx->MemRegion = Sec->MemRegion;
   Ctx->LMARegion = Sec->LMARegion;
   if (Ctx->MemRegion)
     Dot = Ctx->MemRegion->CurPos;
 
+  if ((Sec->Flags & SHF_ALLOC) && Sec->AddrExpr)
+    setDot(Sec->AddrExpr, Sec->Location, false);
+
   switchTo(Sec);
 
   if (Sec->LMAExpr)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60744.195663.patch
Type: text/x-patch
Size: 2108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190418/d34aaaf7/attachment.bin>


More information about the llvm-commits mailing list