From 2d19270efcf01672c8eaab1ccb0e5b89ea953cc9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 28 Mar 2020 23:11:55 -0700 Subject: [PATCH] [ELF][test] Improve linkerscript/linkorder.s --- lld/test/ELF/linkerscript/linkorder.s | 66 +++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/lld/test/ELF/linkerscript/linkorder.s b/lld/test/ELF/linkerscript/linkorder.s index 042e8b3..060b829 100644 --- a/lld/test/ELF/linkerscript/linkorder.s +++ b/lld/test/ELF/linkerscript/linkorder.s @@ -1,33 +1,63 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .rodata : {*(.rodata*)} .text : {*(.text.bar) *(.text.foo)} }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-objdump -s %t | FileCheck %s +## Contiguous SHF_LINK_ORDER sections. +# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \ +# RUN: .text : {*(.text.bar) *(.text.foo)} }' > %t.lds +# RUN: ld.lld -T %t.lds %t.o -o %t +# RUN: llvm-readelf -S -x .rodata -x .text %t | FileCheck %s -# RUN: echo "SECTIONS { .rodata : {*(.rodata*)} .text : {*(.text.foo) *(.text.bar)} }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-objdump -s %t | FileCheck --check-prefix=INV %s +# CHECK: Hex dump of section '.rodata': +# CHECK-NEXT: 00020103 +# CHECK: Hex dump of section '.text': +# CHECK-NEXT: 0201 +# RUN: echo 'SECTIONS { .rodata : {BYTE(0) *(.rodata*) BYTE(3)} \ +# RUN: .text : {*(.text.foo) *(.text.bar)} }' > %t1.lds +# RUN: ld.lld -T %t1.lds %t.o -o %t1 +# RUN: llvm-readelf -S -x .rodata -x .text %t1 | FileCheck --check-prefix=CHECK1 %s -# CHECK: Contents of section .rodata: -# CHECK-NEXT: 02000000 00000000 01000000 00000000 -# CHECK: Contents of section .text: -# CHECK-NEXT: 02000000 00000000 01000000 00000000 +# CHECK1: Hex dump of section '.rodata': +# CHECK1-NEXT: 00010203 +# CHECK1: Hex dump of section '.text': +# CHECK1-NEXT: 0102 -# INV: Contents of section .rodata: -# INV-NEXT: 01000000 00000000 02000000 00000000 -# INV: Contents of section .text: -# INV-NEXT: 01000000 00000000 02000000 00000000 +## Adjacent input sections descriptions are contiguous. +## Orphan section .text.bar precedes .text.foo, so swap the order of .rodata.* +# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) *(.rodata.bar)} }' > %t2.lds +# RUN: ld.lld -T %t2.lds %t.o -o %t2 +# RUN: llvm-readelf -S -x .rodata %t2 | FileCheck --check-prefix=CHECK2 %s + +# CHECK2: [ 1] .rodata {{.*}} AL 4 +# CHECK2: [ 4] .text.bar {{.*}} AX 0 +# CHECK2: Hex dump of section '.rodata': +# CHECK2-NEXT: 0201 + +## Non-contiguous SHF_LINK_ORDER sections, separated by a BYTE. +# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) BYTE(0) *(.rodata.bar)} }' > %terr1.lds +# RUN: ld.lld -T %terr1.lds %t.o -o /dev/null + +## 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: not ld.lld -T %terr2.lds %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s + +## Non-contiguous SHF_LINK_ORDER sections, separated by a symbol assignment. +# RUN: echo 'SECTIONS { .rodata : {*(.rodata.foo) a = .; *(.rodata.bar)} }' > %terr3.lds +# RUN: ld.lld -T %terr3.lds %t.o -o /dev/null + +# ERR: error: incompatible section flags for .rodata .global _start _start: +.section .ro,"a" +.byte 0 + .section .text.bar,"a",@progbits -.quad 2 +.byte 2 .section .text.foo,"a",@progbits -.quad 1 +.byte 1 .section .rodata.foo,"ao",@progbits,.text.foo -.quad 1 +.byte 1 .section .rodata.bar,"ao",@progbits,.text.bar -.quad 2 +.byte 2 -- 2.7.4