Skip to content

Commit b2881de

Browse files
committed
[ELF][test] Improve linkerscript/linkorder.s
(cherry picked from commit 2d19270)
1 parent b6ccc88 commit b2881de

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

lld/test/ELF/linkerscript/linkorder.s

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,63 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
33

4-
# RUN: echo "SECTIONS { .text : { *(.text.bar) *(.text.foo) } }" > %t.script
5-
# RUN: ld.lld -o %t --script %t.script %t.o
6-
# RUN: llvm-objdump -s %t | FileCheck %s
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
79

8-
# RUN: echo "SECTIONS { .text : { *(.text.foo) *(.text.bar) } }" > %t.script
9-
# RUN: ld.lld -o %t --script %t.script %t.o
10-
# RUN: llvm-objdump -s %t | FileCheck --check-prefix=INV %s
10+
# CHECK: Hex dump of section '.rodata':
11+
# CHECK-NEXT: 00020103
12+
# CHECK: Hex dump of section '.text':
13+
# CHECK-NEXT: 0201
1114

15+
# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \
16+
# RUN: .text : {*(.text.foo) *(.text.bar)} }' > %t1.lds
17+
# RUN: ld.lld -T %t1.lds %t.o -o %t1
18+
# RUN: llvm-readelf -S -x .rodata -x .text %t1 | FileCheck --check-prefix=CHECK1 %s
1219

13-
# CHECK: Contents of section .rodata:
14-
# CHECK-NEXT: 02000000 00000000 01000000 00000000
15-
# CHECK: Contents of section .text:
16-
# CHECK-NEXT: 02000000 00000000 01000000 00000000
20+
# CHECK1: Hex dump of section '.rodata':
21+
# CHECK1-NEXT: 00010203
22+
# CHECK1: Hex dump of section '.text':
23+
# CHECK1-NEXT: 0102
1724

18-
# INV: Contents of section .rodata:
19-
# INV-NEXT: 01000000 00000000 02000000 00000000
20-
# INV: Contents of section .text:
21-
# INV-NEXT: 01000000 00000000 02000000 00000000
25+
## Adjacent input sections descriptions are contiguous.
26+
## Orphan section .text.bar precedes .text.foo, so swap the order of .rodata.*
27+
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }' > %t2.lds
28+
# RUN: ld.lld -T %t2.lds %t.o -o %t2
29+
# RUN: llvm-readelf -S -x .rodata %t2 | FileCheck --check-prefix=CHECK2 %s
30+
31+
# CHECK2: [ 1] .rodata {{.*}} AL 3
32+
# CHECK2: [ 3] .text {{.*}} AX 0
33+
# CHECK2: Hex dump of section '.rodata':
34+
# CHECK2-NEXT: 0201
35+
36+
## Non-contiguous SHF_LINK_ORDER sections, separated by a BYTE.
37+
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) BYTE(0) *(.rodata.bar)} }' > %terr1.lds
38+
# RUN: ld.lld -T %terr1.lds %t.o -o /dev/null
39+
40+
## Non-contiguous SHF_LINK_ORDER sections, separated by a non-SHF_LINK_ORDER section.
41+
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.text) *(.rodata.bar)} }' > %terr2.lds
42+
# RUN: not ld.lld -T %terr2.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
43+
44+
## Non-contiguous SHF_LINK_ORDER sections, separated by a symbol assignment.
45+
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) a = .; *(.rodata.bar)} }' > %terr3.lds
46+
# RUN: ld.lld -T %terr3.lds %t.o -o /dev/null
47+
48+
# ERR: error: incompatible section flags for .rodata
2249

2350
.global _start
2451
_start:
2552

53+
.section .ro,"a"
54+
.byte 0
55+
2656
.section .text.bar,"a",@progbits
27-
.quad 2
57+
.byte 2
2858
.section .text.foo,"a",@progbits
29-
.quad 1
59+
.byte 1
3060
.section .rodata.foo,"ao",@progbits,.text.foo
31-
.quad 1
61+
.byte 1
3262
.section .rodata.bar,"ao",@progbits,.text.bar
33-
.quad 2
63+
.byte 2

0 commit comments

Comments
 (0)