Changeset View
Standalone View
lld/test/ELF/linkerscript/linkorder.s
# REQUIRES: x86 | # REQUIRES: x86 | ||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o | ||||
## Contiguous SHF_LINK_ORDER sections. | ## Contiguous SHF_LINK_ORDER sections. | ||||
# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \ | # RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(4)} \ | ||||
# RUN: .text : {*(.text.bar) *(.text.foo)} }' > %t.lds | # RUN: .text : {*(.text.bar) *(.text.foo)} }' > %t.lds | ||||
# RUN: ld.lld -T %t.lds %t.o -o %t | # RUN: ld.lld -T %t.lds %t.o -o %t | ||||
# RUN: llvm-readelf -S -x .rodata -x .text %t | FileCheck %s | # RUN: llvm-readelf -S -x .rodata -x .text %t | FileCheck %s | ||||
# CHECK: [ 1] .rodata {{.*}} AL 3 | # CHECK: [ 1] .rodata {{.*}} AL 3 | ||||
# CHECK: [ 3] .text {{.*}} AX 0 | # CHECK: [ 3] .text {{.*}} AX 0 | ||||
# CHECK: Hex dump of section '.rodata': | # CHECK: Hex dump of section '.rodata': | ||||
# CHECK-NEXT: 00020103 | # CHECK-NEXT: 00030102 04 | ||||
# CHECK: Hex dump of section '.text': | # CHECK: Hex dump of section '.text': | ||||
# CHECK-NEXT: 0201 | # CHECK-NEXT: 0201 | ||||
# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \ | # RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(4)} \ | ||||
# RUN: .text : {*(.text.foo) *(.text.bar)} }' > %t1.lds | # RUN: .text : {*(.text.foo) *(.text.bar)} }' > %t1.lds | ||||
# RUN: ld.lld -T %t1.lds %t.o -o %t1 | # RUN: ld.lld -T %t1.lds %t.o -o %t1 | ||||
# RUN: llvm-readelf -S -x .rodata -x .text %t1 | FileCheck --check-prefix=CHECK1 %s | # RUN: llvm-readelf -S -x .rodata -x .text %t1 | FileCheck --check-prefix=CHECK1 %s | ||||
# CHECK1: [ 1] .rodata {{.*}} AL 3 | # CHECK1: [ 1] .rodata {{.*}} AL 3 | ||||
# CHECK1: [ 3] .text {{.*}} AX 0 | # CHECK1: [ 3] .text {{.*}} AX 0 | ||||
# CHECK1: Hex dump of section '.rodata': | # CHECK1: Hex dump of section '.rodata': | ||||
# CHECK1-NEXT: 00010203 | # CHECK1-NEXT: 00010302 04 | ||||
# CHECK1: Hex dump of section '.text': | # CHECK1: Hex dump of section '.text': | ||||
# CHECK1-NEXT: 0102 | # CHECK1-NEXT: 0102 | ||||
## Adjacent input sections descriptions are contiguous. | ## Adjacent input sections descriptions are contiguous. | ||||
## Orphan section .text.bar precedes .text.foo, so swap the order of .rodata.* | ## Orphan section .text.bar precedes .text.foo. However, don't swap the order of .rodata.* | ||||
## because they are in different InputSectionDescriptions. | |||||
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }' > %t2.lds | # RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }' > %t2.lds | ||||
# RUN: ld.lld -T %t2.lds %t.o -o %t2 | # RUN: ld.lld -T %t2.lds %t.o -o %t2 | ||||
# RUN: llvm-readelf -S -x .rodata %t2 | FileCheck --check-prefix=CHECK2 %s | # RUN: llvm-readelf -S -x .rodata %t2 | FileCheck --check-prefix=CHECK2 %s | ||||
# CHECK2: [ 1] .rodata {{.*}} AL 4 | # CHECK2: [ 1] .rodata {{.*}} AL 5 | ||||
# CHECK2: [ 4] .text.bar {{.*}} AX 0 | # CHECK2: [ 4] .text.bar {{.*}} AX 0 | ||||
# CHECK2: [ 5] .text.foo {{.*}} AX 0 | |||||
# CHECK2: Hex dump of section '.rodata': | # CHECK2: Hex dump of section '.rodata': | ||||
# CHECK2-NEXT: 0201 | # CHECK2-NEXT: 010302 | ||||
## Non-contiguous SHF_LINK_ORDER sections, separated by a BYTE. | ## Non-contiguous SHF_LINK_ORDER sections, separated by a BYTE. | ||||
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) BYTE(0) *(.rodata.bar)} }' > %terr1.lds | # RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) BYTE(0) *(.rodata.bar)} }' > %t3.lds | ||||
# RUN: not ld.lld -T %terr1.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s | # RUN: ld.lld -T %t3.lds %t.o -o %t3 | ||||
# RUN: llvm-readelf -S -x .rodata %t3 | FileCheck --check-prefix=CHECK3 %s | |||||
# CHECK3: [ 1] .rodata {{.*}} AL 5 | |||||
# CHECK3: [ 4] .text.bar {{.*}} AX 0 | |||||
# CHECK3: [ 5] .text.foo {{.*}} AX 0 | |||||
# CHECK3: Hex dump of section '.rodata': | |||||
# CHECK3-NEXT: 01000302 | |||||
## Non-contiguous SHF_LINK_ORDER sections, separated by a non-SHF_LINK_ORDER section. | ## Non-contiguous SHF_LINK_ORDER sections, separated by a non-SHF_LINK_ORDER section. | ||||
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.text) *(.rodata.bar)} }' > %terr2.lds | # RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.text) *(.rodata.bar)} }' > %t4.lds | ||||
# RUN: not ld.lld -T %terr2.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s | # RUN: ld.lld -T %t4.lds %t.o -o %t4 | ||||
# RUN: llvm-readelf -S -x .rodata %t4 | FileCheck --check-prefix=CHECK4 %s | |||||
jhenderson: You don't use the section header dump here. Can you get rid of `-S`? | |||||
## Non-contiguous SHF_LINK_ORDER sections, separated by a symbol assignment. | # CHECK4: Hex dump of section '.rodata': | ||||
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) a = .; *(.rodata.bar)} }' > %terr3.lds | # CHECK4-NEXT: 01cccccc 0302 | ||||
I'm either missing something, or something odd is going on here. Where are the cccccc coming from? There doesn't appear to be a .text section with any contents - it has the _start symbol in, if I follow correctly, but should be empty; nothing specifies alignment requirements either here. jhenderson: I'm either missing something, or something odd is going on here. Where are the `cccccc` coming… | |||||
sh_addralign(.text)=4. lld fills the gap with traps. MaskRay: sh_addralign(.text)=4. lld fills the gap with traps. | |||||
# RUN: not ld.lld -T %terr3.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s | |||||
# ERR: error: {{.*}}.o:(.rodata.bar): SHF_LINK_ORDER sections in .rodata are not contiguous | ## Non-contiguous SHF_LINK_ORDER sections, separated by a symbol assignment. | ||||
# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) a = .; *(.rodata.bar)} }' > %t5.lds | |||||
# RUN: ld.lld -T %t5.lds %t.o -o %t5 | |||||
# RUN: llvm-readelf -S -x .rodata %t5 | FileCheck --check-prefix=CHECK2 %s | |||||
.global _start | .global _start | ||||
_start: | _start: | ||||
.section .ro,"a" | .section .ro,"a" | ||||
.byte 0 | .byte 0 | ||||
Not Done ReplyInline ActionsThis section doesn't seem to be being used? jhenderson: This section doesn't seem to be being used? | |||||
This was a leftover from a previous patch where I probably wanted to test an orphan section. It is unrelated to this patch so I will not deal with it. It may find new uses if we take another think about the organization of tests. MaskRay: This was a leftover from a previous patch where I probably wanted to test an orphan section. It… | |||||
.section .text.bar,"a",@progbits | .section .text.bar,"a",@progbits | ||||
.byte 2 | .byte 2 | ||||
.section .text.foo,"a",@progbits | .section .text.foo,"a",@progbits | ||||
.byte 1 | .byte 1 | ||||
.section .rodata.foo,"ao",@progbits,.text.foo | .section .rodata.foo,"ao",@progbits,.text.foo | ||||
.byte 1 | .byte 1 | ||||
.section .rodata.bar,"ao",@progbits,.text.bar | ## If the two .rodata.bar sections are in the same InputSectionDescription, | ||||
## 03 (sh_link!=0) will be ordered before 02 (sh_link=0). | |||||
It seems to me like you need test cases for sh_link=0 for SHF_LINK_ORDER sections here too? jhenderson: It seems to me like you need test cases for sh_link=0 for SHF_LINK_ORDER sections here too? | |||||
linkorder-mixed.test tested sh_link=0 for SHF_LINK_ORDER sections MaskRay: `linkorder-mixed.test` tested sh_link=0 for SHF_LINK_ORDER sections | |||||
.section .rodata.bar,"a",@progbits | |||||
.byte 2 | .byte 2 | ||||
.section .rodata.bar,"ao",@progbits,.text.bar | |||||
.byte 3 |
You don't use the section header dump here. Can you get rid of -S?