1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3
4## Contiguous SHF_LINK_ORDER sections.
5# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \
6# RUN:   .text : {*(.text.bar) *(.text.foo)} }' > %t.lds
7# RUN: ld.lld -T %t.lds %t.o -o %t
8# RUN: llvm-readelf -S -x .rodata -x .text %t | FileCheck %s
9
10# CHECK:      [ 1] .rodata   {{.*}} AL 3
11# CHECK:      [ 3] .text     {{.*}} AX 0
12# CHECK:      Hex dump of section '.rodata':
13# CHECK-NEXT: 00020103
14# CHECK:      Hex dump of section '.text':
15# CHECK-NEXT: 0201
16
17# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \
18# RUN:  .text : {*(.text.foo) *(.text.bar)} }' > %t1.lds
19# RUN: ld.lld -T %t1.lds %t.o -o %t1
20# RUN: llvm-readelf -S -x .rodata -x .text %t1 | FileCheck --check-prefix=CHECK1 %s
21
22# CHECK1:      [ 1] .rodata   {{.*}} AL 3
23# CHECK1:      [ 3] .text     {{.*}} AX 0
24# CHECK1:      Hex dump of section '.rodata':
25# CHECK1-NEXT: 00010203
26# CHECK1:      Hex dump of section '.text':
27# CHECK1-NEXT: 0102
28
29## Adjacent input sections descriptions are contiguous.
30## Orphan section .text.bar precedes .text.foo, so swap the order of .rodata.*
31# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }' > %t2.lds
32# RUN: ld.lld -T %t2.lds %t.o -o %t2
33# RUN: llvm-readelf -S -x .rodata %t2 | FileCheck --check-prefix=CHECK2 %s
34
35# CHECK2:      [ 1] .rodata   {{.*}} AL 4
36# CHECK2:      [ 4] .text.bar {{.*}} AX 0
37# CHECK2:      Hex dump of section '.rodata':
38# CHECK2-NEXT: 0201
39
40## Non-contiguous SHF_LINK_ORDER sections, separated by a BYTE.
41# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) BYTE(0) *(.rodata.bar)} }' > %terr1.lds
42# RUN: not ld.lld -T %terr1.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
43
44## Non-contiguous SHF_LINK_ORDER sections, separated by a non-SHF_LINK_ORDER section.
45# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.text) *(.rodata.bar)} }' > %terr2.lds
46# RUN: not ld.lld -T %terr2.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
47
48## Non-contiguous SHF_LINK_ORDER sections, separated by a symbol assignment.
49# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) a = .; *(.rodata.bar)} }' > %terr3.lds
50# RUN: not ld.lld -T %terr3.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
51
52# ERR: error: {{.*}}.o:(.rodata.bar): SHF_LINK_ORDER sections in .rodata are not contiguous
53
54.global _start
55_start:
56
57.section .ro,"a"
58.byte 0
59
60.section .text.bar,"a",@progbits
61.byte 2
62.section .text.foo,"a",@progbits
63.byte 1
64.section .rodata.foo,"ao",@progbits,.text.foo
65.byte 1
66.section .rodata.bar,"ao",@progbits,.text.bar
67.byte 2
68