2 ## Test how we set the sh_link field of a SHF_LINK_ORDER output section.
3 ## Additionally, test that in a relocatable link, SHF_LINK_ORDER sections are
4 ## not combined. Combining them will arbitrarily choose a single output
5 ## section, losing tracking of correct dependencies.
7 # RUN: llvm-mc -filetype=obj --triple=x86_64 %s -o %t.o
9 ## In the absence of a SECTIONS command.
10 # RUN: ld.lld %t.o -o %t
11 # RUN: llvm-readelf -S -x foo %t | FileCheck --check-prefixes=EXE,EXE-HEX %s
12 # RUN: ld.lld %t.o -o %t.ro -r
13 # RUN: llvm-readelf -S %t.ro | FileCheck --check-prefix=REL %s
15 ## A non-relocatable link places readonly sections before read-executable sections.
16 # EXE: [Nr] Name {{.*}} Flg Lk
18 # EXE-NEXT: [ 1] foo {{.*}} AL 2
19 # EXE-NEXT: [ 2] .text {{.*}} AX 0
21 ## An implementation detail: foo is moved after its linked-to section (orphan).
22 # REL: [Nr] Name {{.*}} Flg Lk
24 # REL-NEXT: [ 1] .text {{.*}} AX 0
25 # REL-NEXT: [ 2] .text.f1 {{.*}} AX 0
26 # REL-NEXT: [ 3] foo {{.*}} AL 2
27 # REL-NEXT: [ 4] .text.f2 {{.*}} AX 0
28 # REL-NEXT: [ 5] foo {{.*}} AL 4
30 ## A SECTIONS command combines .text.*
31 # RUN: echo 'SECTIONS { .text : { *(.text.f1) *(.text.f2) } }' > %t1.lds
32 # RUN: ld.lld -T %t1.lds %t.o -o %t1
33 # RUN: llvm-readelf -S -x foo %t1 | FileCheck --check-prefixes=EXE,EXE-HEX %s
34 # RUN: ld.lld -T %t1.lds %t.o -o %t1.ro -r
35 # RUN: llvm-readelf -S -x foo %t1.ro | FileCheck --check-prefix=REL1 %s
37 # REL1: [Nr] Name {{.*}} Flg Lk
39 # REL1-NEXT: [ 1] .text {{.*}} AX 0
40 # REL1-NEXT: [ 2] foo {{.*}} AL 1
42 ## A SECTIONS command separates .text.*
43 # RUN: echo 'SECTIONS { .text.f1 : { *(.text.f1) } .text.f2 : { *(.text.f2) } }' > %t2.lds
44 # RUN: ld.lld -T %t2.lds %t.o -o %t2
45 # RUN: llvm-readelf -S -x foo %t2 | FileCheck --check-prefixes=EXE2,EXE-HEX %s
46 # RUN: ld.lld -T %t2.lds %t.o -o %t2.ro -r
47 # RUN: llvm-readelf -S %t2.ro | FileCheck --check-prefixes=REL2 %s
49 # EXE2: [Nr] Name {{.*}} Flg Lk
51 # EXE2-NEXT: [ 1] foo {{.*}} AL 2
52 # EXE2-NEXT: [ 2] .text.f1 {{.*}} AX 0
53 # EXE2-NEXT: [ 3] .text.f2 {{.*}} AX 0
55 # REL2: [Nr] Name {{.*}} Flg Lk
57 # REL2-NEXT: [ 1] .text.f1 {{.*}} AX 0
58 # REL2-NEXT: [ 2] .text.f2 {{.*}} AX 0
59 # REL2-NEXT: [ 3] .text {{.*}} AX 0
60 # REL2-NEXT: [ 4] foo {{.*}} AL 1
61 # REL2-NEXT: [ 5] foo {{.*}} AL 2
63 # EXE-HEX: Hex dump of section 'foo':
66 .section .text.f1,"ax",@progbits
68 .section .text.f2,"ax",@progbits
71 .section foo,"ao",@progbits,.text.f2
73 .section foo,"ao",@progbits,.text.f1