1# REQUIRES: x86 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. 6 7# RUN: llvm-mc -filetype=obj --triple=x86_64 %s -o %t.o 8 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 14 15## A non-relocatable link places readonly sections before read-executable sections. 16# EXE: [Nr] Name {{.*}} Flg Lk 17# EXE-NEXT: [ 0] 18# EXE-NEXT: [ 1] foo {{.*}} AL 2 19# EXE-NEXT: [ 2] .text {{.*}} AX 0 20 21## An implementation detail: foo is moved after its linked-to section (orphan). 22# REL: [Nr] Name {{.*}} Flg Lk 23# REL-NEXT: [ 0] 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 29 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 36 37# REL1: [Nr] Name {{.*}} Flg Lk 38# REL1-NEXT: [ 0] 39# REL1-NEXT: [ 1] .text {{.*}} AX 0 40# REL1-NEXT: [ 2] foo {{.*}} AL 1 41 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 48 49# EXE2: [Nr] Name {{.*}} Flg Lk 50# EXE2-NEXT: [ 0] 51# EXE2-NEXT: [ 1] foo {{.*}} AL 2 52# EXE2-NEXT: [ 2] .text.f1 {{.*}} AX 0 53# EXE2-NEXT: [ 3] .text.f2 {{.*}} AX 0 54 55# REL2: [Nr] Name {{.*}} Flg Lk 56# REL2-NEXT: [ 0] 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 62 63# EXE-HEX: Hex dump of section 'foo': 64# EXE-HEX-NEXT: 0102 65 66.section .text.f1,"ax",@progbits 67ret 68.section .text.f2,"ax",@progbits 69ret 70 71.section foo,"ao",@progbits,.text.f2 72.byte 2 73.section foo,"ao",@progbits,.text.f1 74.byte 1 75