[PATCH] D74736: [ELF] Use ALIGN to decide output section alignment

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 17 15:12:48 PST 2020


MaskRay updated this revision to Diff 245042.
MaskRay added a comment.

Adjust linkerscript/section-align2.test for a future change that adds warnings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74736

Files:
  lld/ELF/LinkerScript.cpp
  lld/test/ELF/linkerscript/lma-align.test
  lld/test/ELF/linkerscript/section-align2.test


Index: lld/test/ELF/linkerscript/section-align2.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/section-align2.test
@@ -0,0 +1,27 @@
+# REQUIRES: aarch64
+# RUN: echo '.globl _start; _start: ret; .data.rel.ro; .balign 8; .byte 0; .data; .byte 0; \
+# RUN:   .section .data2,"aw"; .balign 8; .byte 0; .bss; .balign 32; .byte 0' | \
+# RUN:   llvm-mc -filetype=obj -triple=aarch64 - -o %t.o
+# RUN: ld.lld -T %s %t.o -o %t 2>&1 | count 0
+# RUN: llvm-readelf -S %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 0000000000010000 010000 000004 00  AX  0   0  4
+# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000010010 010010 000001 00  WA  0   0 16
+# CHECK-NEXT: .data        PROGBITS 0000000000020000 020000 000001 00  WA  0   0  1
+# CHECK-NEXT: .data2       PROGBITS 0000000000020008 020008 000001 00  WA  0   0  8
+# CHECK-NEXT: .bss         NOBITS   0000000000020010 020009 000011 00  WA  0   0 32
+
+SECTIONS {
+  .text 0x10000 : {}
+  ## The output section is aligned to 16.
+  .data.rel.ro . : ALIGN(16) {}
+
+  .data 0x20000 : {}
+  ## The output section is aligned to 8.
+  .data2 . : { *(.data2) }
+  ## The output section is aligned to 16.
+  ## The input section has a larger alignment and is thus preceded by a gap.
+  .bss . : ALIGN(16) {}
+}
Index: lld/test/ELF/linkerscript/lma-align.test
===================================================================
--- lld/test/ELF/linkerscript/lma-align.test
+++ lld/test/ELF/linkerscript/lma-align.test
@@ -1,5 +1,6 @@
 # REQUIRES: x86
-# RUN: echo 'ret; .data.rel.ro; .balign 16; .byte 0; .data; .byte 0; .bss; .byte 0' | \
+# RUN: echo '.globl _start; _start: ret; .data.rel.ro; .balign 16; .byte 0; \
+# RUN:   .data; .balign 32; .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
@@ -8,13 +9,13 @@
 # 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: .data        PROGBITS 0000000000011010 002010 000011 00  WA  0   0 32
 # CHECK-NEXT: .bss         NOBITS   0000000000011040 002040 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
-# CHECK-NEXT: LOAD  0x002010 0x0000000000011010 0x0000000000001020 0x000001 0x000001 RW  0x1000
+# CHECK-NEXT: LOAD  0x002010 0x0000000000011010 0x0000000000001020 0x000011 0x000011 RW  0x1000
 # CHECK-NEXT: LOAD  0x002040 0x0000000000011040 0x0000000000011040 0x000000 0x000001 RW  0x1000
 
 MEMORY {
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -762,7 +762,9 @@
   ctx->outSec = sec;
 
   uint64_t before = advance(0, 1);
-  ctx->outSec->addr = advance(0, ctx->outSec->alignment);
+  uint32_t align =
+      sec->alignExpr ? sec->alignExpr().getValue() : ctx->outSec->alignment;
+  ctx->outSec->addr = advance(0, align);
   expandMemoryRegions(ctx->outSec->addr - before);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74736.245042.patch
Type: text/x-patch
Size: 3714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200217/0ad284bc/attachment.bin>


More information about the llvm-commits mailing list