1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o
3# RUN: ld.lld -o %t --script %s %t.o
4# RUN: llvm-objdump --section-headers %t | FileCheck %s
5
6SECTIONS {
7  . = 0x10000;
8  .aaa : { *(.aaa) }
9  . = ALIGN(4096);
10  .bbb : { *(.bbb) }
11  . = ALIGN(4096 * 4);
12  .ccc : { *(.ccc) }
13}
14
15# CHECK:      Sections:
16# CHECK-NEXT: Idx Name          Size     VMA              Type
17# CHECK-NEXT:   0               00000000 0000000000000000
18# CHECK-NEXT:   1 .aaa          00000008 0000000000010000 DATA
19# CHECK-NEXT:   2 .bbb          00000008 0000000000011000 DATA
20# CHECK-NEXT:   3 .ccc          00000008 0000000000014000 DATA
21
22## Check that ALIGN zero do nothing and does not crash #1.
23# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script
24# RUN: ld.lld -o %t4 --script %t.script %t.o
25# RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=ZERO
26
27# ZERO:      Sections:
28# ZERO-NEXT: Idx Name          Size     VMA              Type
29# ZERO-NEXT:   0               00000000 0000000000000000
30# ZERO-NEXT:   1 .aaa          00000008 0000000000000123 DATA
31
32## Check that ALIGN zero do nothing and does not crash #2.
33# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script
34# RUN: ld.lld -o %t5 --script %t.script %t.o
35# RUN: llvm-objdump --section-headers %t5 | FileCheck %s --check-prefix=ZERO
36
37## Test we fail gracefully when alignment value is not a power of 2 (#1).
38# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0x123, 3); .aaa : { *(.aaa) } }" > %t.script
39# RUN: not ld.lld -o /dev/null --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s
40
41# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(3); .aaa : { *(.aaa) } }" > %t.script
42# RUN: not ld.lld -o /dev/null --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s
43
44# ERR: {{.*}}.script:1: alignment must be power of 2
45