[lld] r336335 - [ELF] - Advance position in a memory region when change the Dot.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 5 03:44:18 PDT 2018


Author: grimar
Date: Thu Jul  5 03:44:17 2018
New Revision: 336335

URL: http://llvm.org/viewvc/llvm-project?rev=336335&view=rev
Log:
[ELF] - Advance position in a memory region when change the Dot.

This is https://bugs.llvm.org//show_bug.cgi?id=37836

Previously LLD could assign to Dot or set the address
for the section with address expression but did not advance
the position in a memory region.

Patch fixes the issue.

Added:
    lld/trunk/test/ELF/linkerscript/memory4.test
    lld/trunk/test/ELF/linkerscript/memory5.test
Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=336335&r1=336334&r2=336335&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Jul  5 03:44:17 2018
@@ -135,6 +135,9 @@ void LinkerScript::setDot(Expr E, const
   // Update to location counter means update to section size.
   if (InSec)
     expandOutputSection(Val - Dot);
+  else
+    expandMemoryRegions(Val - Dot);
+
   Dot = Val;
 }
 

Added: lld/trunk/test/ELF/linkerscript/memory4.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/memory4.test?rev=336335&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/memory4.test (added)
+++ lld/trunk/test/ELF/linkerscript/memory4.test Thu Jul  5 03:44:17 2018
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \
+# RUN:   | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o
+# RUN: ld.lld -o %t.so --script %s %t.o
+# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
+
+# CHECK:      1 .text         00000001 0000000000042000
+# CHECK-NEXT: 2 .data         00000001 0000000000042400
+
+## Test that address expressions changes the position in a memory region.
+
+MEMORY {
+  ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
+}
+SECTIONS {
+  .text : { *(.text*) }
+  data_addr = ALIGN(1024); 
+  .data data_addr : { *(.data*) }
+}

Added: lld/trunk/test/ELF/linkerscript/memory5.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/memory5.test?rev=336335&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/memory5.test (added)
+++ lld/trunk/test/ELF/linkerscript/memory5.test Thu Jul  5 03:44:17 2018
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \
+# RUN:   | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o
+# RUN: ld.lld -o %t.so --script %s %t.o
+# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
+
+# CHECK:      1 .text         00000001 0000000000042000
+# CHECK-NEXT: 2 .data         00000001 0000000000044001
+
+## Test that assign to Dot changes the position in a memory region.
+
+MEMORY {
+  ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
+}
+SECTIONS {
+  .text : { *(.text*) }
+  . += 0x2000;
+  .data : { *(.data*) }
+}




More information about the llvm-commits mailing list