Skip to content

Commit 6cf1ea9

Browse files
committed
[ELF,test] Improve unclosed tests
1 parent 4f5ad22 commit 6cf1ea9

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

lld/test/ELF/linkerscript/memory-err.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
# RUN: not ld.lld -T %t.script %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=NOT_CONVERGE %s
7272
# NOT_CONVERGE: error: address (0x14) of section '.text' does not converge
7373

74+
# RUN: echo 'MEMORY { ram : ORIGIN = symbol, LENGTH = 4094 ' > %t.script
75+
# RUN: not ld.lld -T %t.script %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=UNCLOSED %s
76+
# UNCLOSED: error: {{.*}}:1: unexpected EOF
77+
7478
nop
7579

7680
.data

lld/test/ELF/linkerscript/overlay.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,11 @@ SECTIONS {
9292
.out.aaa { *(.aaa) } > AX AT>FLASH
9393
}
9494
}
95+
96+
#--- unclosed.lds
97+
SECTIONS {
98+
OVERLAY 0x1000 : AT ( 0x2000 ) {
99+
100+
# RUN: not ld.lld a.o -T unclosed.lds 2>&1 | FileCheck %s --check-prefix=UNCLOSED
101+
# UNCLOSED: error: unclosed.lds:1: unexpected EOF
102+
# UNCLOSED-NOT: {{.}}

lld/test/ELF/linkerscript/phdrs.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ PHDRS { text PT_FOO FOOHDR; }
9797
# PTFOO-NEXT:>>> PHDRS { text PT_FOO FOOHDR; }
9898
# PTFOO-NEXT:>>> ^
9999

100+
#--- unclosed.lds
101+
PHDRS { text PT_LOAD ;
102+
103+
# RUN: not ld.lld -T unclosed.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED %s
104+
# UNCLOSED:error: unclosed.lds:1: invalid program header type:
105+
100106
#--- a.s
101107
.global _start
102108
_start:

lld/test/ELF/linkerscript/sections.s

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
34

4-
# Empty SECTIONS command.
5-
# RUN: echo "SECTIONS {}" > %t.script
6-
# RUN: ld.lld -o %t1 --script %t.script %t
7-
# RUN: llvm-objdump --section-headers %t1 | \
5+
#--- empty.lds
6+
SECTIONS {}
7+
8+
# RUN: ld.lld -o empty -T empty.lds a.o
9+
# RUN: llvm-objdump --section-headers empty | \
810
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
911

12+
#--- 1.lds
1013
# SECTIONS command with the same order as default.
11-
# RUN: echo "SECTIONS { \
12-
# RUN: .text : { *(.text) } \
13-
# RUN: .data : { *(.data) } }" > %t.script
14-
# RUN: ld.lld -o %t2 --script %t.script %t
15-
# RUN: llvm-objdump --section-headers %t2 | \
14+
SECTIONS {
15+
.text : { *(.text) }
16+
.data : { *(.data) } }
17+
18+
# RUN: ld.lld -o 1 -T 1.lds a.o
19+
# RUN: llvm-objdump --section-headers 1 | \
1620
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
1721

1822
# Idx Name Size
@@ -28,8 +32,8 @@
2832
# .text and .data have swapped names but proper sizes and types.
2933
# RUN: echo "SECTIONS { \
3034
# RUN: .data : { *(.text) } \
31-
# RUN: .text : { *(.data) } }" > %t.script
32-
# RUN: ld.lld -o %t4 --script %t.script %t
35+
# RUN: .text : { *(.data) } }" > t.lds
36+
# RUN: ld.lld -o %t4 --script t.lds a.o
3337
# RUN: llvm-objdump --section-headers %t4 | \
3438
# RUN: FileCheck -check-prefix=SEC-SWAP-NAMES %s
3539

@@ -50,8 +54,8 @@
5054
# RUN: .text : { *(.text) } \
5155
# RUN: .data : { *(.data) } } \
5256
# RUN: SECTIONS { \
53-
# RUN: .data : { *(other) } }" > %t.script
54-
# RUN: ld.lld -o %t6 --script %t.script %t
57+
# RUN: .data : { *(other) } }" > t.lds
58+
# RUN: ld.lld -o %t6 --script t.lds a.o
5559
# RUN: llvm-objdump --section-headers %t6 | \
5660
# RUN: FileCheck -check-prefix=SEC-MULTI %s
5761

@@ -72,7 +76,7 @@
7276
# RUN: .data : { *(.data) } \
7377
# RUN: .comment : { *(.comment) } \
7478
# RUN: other : { *(other) } }' > %t5.lds
75-
# RUN: ld.lld -o %t5 -T %t5.lds %t
79+
# RUN: ld.lld -o %t5 -T %t5.lds a.o
7680
# RUN: llvm-readelf -S -l %t5 | FileCheck --check-prefix=SEP-BY-NONALLOC %s
7781

7882
# SEP-BY-NONALLOC: [Nr] Name Type Address Off Size ES Flg
@@ -87,11 +91,25 @@
8791
# SEP-BY-NONALLOC-NEXT: LOAD 0x00100e 0x000000000000000e 0x000000000000000e 0x000023 0x000025 RW 0x1000
8892
# SEP-BY-NONALLOC-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0
8993

94+
#--- semi.lds
9095
# Input section pattern contains additional semicolon.
9196
# Case found in linux kernel script. Check we are able to parse it.
92-
# RUN: echo "SECTIONS { .text : { ;;*(.text);;S = 0;; } }" > %t.script
93-
# RUN: ld.lld -o /dev/null --script %t.script %t
97+
SECTIONS { .text : { ;;*(.text);;S = 0;; } }
98+
99+
# RUN: ld.lld -T semi.lds a.o
100+
101+
#--- unclosed.lds
102+
SECTIONS {
103+
.text : { *(.text) }
104+
105+
# RUN: not ld.lld -T unclosed.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED %s
106+
# UNCLOSED: error: unclosed.lds:1: malformed number:
107+
108+
#--- unclosed-out.lds
109+
SECTIONS {
110+
.text : { *(.text)
94111

112+
#--- a.s
95113
.globl _start
96114
_start:
97115
mov $60, %rax

0 commit comments

Comments
 (0)