[PATCH] D74286: [ELF] Respect output section alignment for AT> (non-null lmaRegion)
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 08:23:57 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe21b9ca751c5: [ELF] Respect output section alignment for AT> (non-null lmaRegion) (authored by MaskRay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74286/new/
https://reviews.llvm.org/D74286
Files:
lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/lma-align.test
Index: lld/test/ELF/linkerscript/lma-align.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/lma-align.test
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: echo 'ret; .data.rel.ro; .balign 16; .byte 0; .data; .byte 0; .bss; .byte 0' | \
+# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
+# RUN: ld.lld -T %s %t.o -o %t
+# RUN: llvm-readelf -S -l %t | FileCheck %s
+
+# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
+# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
+# CHECK-NEXT: .text PROGBITS 0000000000001000 001000 000001 00 AX 0 0 4
+# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000011000 002000 000001 00 WA 0 0 16
+# CHECK-NEXT: .data PROGBITS 0000000000011010 002010 000001 00 WA 0 0 16
+# CHECK-NEXT: .bss NOBITS 0000000000011040 002011 000001 00 WA 0 0 64
+
+# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
+# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000001 0x000001 R E 0x1000
+# CHECK-NEXT: LOAD 0x002000 0x0000000000011000 0x0000000000001010 0x000001 0x000001 RW 0x1000
+## FIXME .data and .bss should be placed in different PT_LOAD segments
+## because their LMA regions are different.
+# CHECK-NEXT: LOAD 0x002010 0x0000000000011010 0x0000000000001020 0x000001 0x000031 RW 0x1000
+
+MEMORY {
+ ROM : ORIGIN = 0x1000, LENGTH = 1K
+ RAM : ORIGIN = 0x11000, LENGTH = 1K
+}
+SECTIONS {
+ .text 0x1000 : { *(.text*) } >ROM
+ ## Input section alignment decides output section alignment.
+ .data.rel.ro 0x11000 : { *(.data.rel.ro) } >RAM AT>ROM
+ ## ALIGN decides output section alignment.
+ .data . : ALIGN(16) { *(.data*) } >RAM AT>ROM
+ .bss . : ALIGN(64) { *(.bss*) } >RAM
+}
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -835,7 +835,7 @@
ctx->lmaOffset = sec->lmaExpr().getValue() - dot;
if (MemoryRegion *mr = sec->lmaRegion)
- ctx->lmaOffset = mr->curPos - dot;
+ ctx->lmaOffset = alignTo(mr->curPos, sec->alignment) - dot;
// If neither AT nor AT> is specified for an allocatable section, the linker
// will set the LMA such that the difference between VMA and LMA for the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74286.244190.patch
Type: text/x-patch
Size: 2391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200212/1071b95e/attachment.bin>
More information about the llvm-commits
mailing list