xref: /llvm-project/lld/test/ELF/linkerscript/subalign.s (revision 7c5fcb3591b57b77c079700d7b12c2ecfd995818)
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
3
4# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script
5# RUN: ld.lld -o %t1 --script %t1.script %t1.o
6# RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=NOALIGN %s
7# NOALIGN:      Contents of section .aaa:
8# NOALIGN-NEXT:   01000000 00000000 00000000 00000000
9# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
10# NOALIGN-NEXT:   02000000 00000000 00000000 00000000
11# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
12# NOALIGN-NEXT:   03000000 00000000 00000000 00000000
13# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
14# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
15# NOALIGN-NEXT:   00000000 00000000 00000000 00000000
16# NOALIGN-NEXT:   04000000 00000000
17
18# RUN: echo "SECTIONS { .aaa : SUBALIGN(1) { *(.aaa.*) } }" > %t2.script
19# RUN: ld.lld -o %t2 --script %t2.script %t1.o
20# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SUBALIGN %s
21# SUBALIGN: Contents of section .aaa:
22# SUBALIGN:   01000000 00000000 02000000 00000000
23# SUBALIGN:   03000000 00000000 04000000 00000000
24
25## Test we do not assert or crash when dot(.) is used inside SUBALIGN.
26## Value of dot is undefined. Some versions of ld.bfd do not allow to use dot
27## in such expressions.
28# RUN: echo "SECTIONS { . = 0x32; .aaa : SUBALIGN(.) { *(.aaa*) } }" > %t3.script
29# RUN: not ld.lld %t1.o --script %t3.script -o /dev/null 2>&1 | FileCheck --check-prefix=ERR1 %s
30# ERR1: {{.*}}.script:1: unable to get location counter value
31
32## Test we are able to link with zero alignment, this is consistent with bfd 2.26.1.
33# RUN: echo "SECTIONS { .aaa : SUBALIGN(0) { *(.aaa*) } }" > %t4.script
34# RUN: ld.lld %t1.o --script %t4.script -o %t4
35# RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SUBALIGN %s
36
37## Test we fail gracefully when alignment value is not a power of 2.
38# RUN: echo "SECTIONS { .aaa : SUBALIGN(3) { *(.aaa*) } }" > %t5.script
39# RUN: not ld.lld %t1.o --script %t5.script -o /dev/null 2>&1 | FileCheck --check-prefix=ERR2 %s
40# ERR2: {{.*}}.script:1: alignment must be power of 2
41
42.global _start
43_start:
44 nop
45
46.section .aaa.1, "a"
47.align 16
48.quad 1
49
50.section .aaa.2, "a"
51.align 32
52.quad 2
53
54.section .aaa.3, "a"
55.align 64
56.quad 3
57
58.section .aaa.4, "a"
59.align 128
60.quad 4
61