Skip to content

Commit 309d1c4

Browse files
committed
[ELF][test] Add a test to demonstrate #66836
1 parent ad762f2 commit 309d1c4

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# REQUIRES: arm
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=armv7-linux-gnueabi a.s -o a.o
4+
5+
## If we don't merge adjacent duplicate entries, __code_size will be negative and
6+
## . += __code_size will trigger a "move location counter backward" error.
7+
## LLD may report more errors further down, but there is only one "move location counter backward" error.
8+
# RUN: not ld.lld -z norelro -z max-page-size=4096 -T a.t a.o -o /dev/null --no-merge-exidx-entries 2>&1 | \
9+
# RUN: FileCheck %s --check-prefix=ERR --implicit-check-not=error:
10+
11+
# ERR: error: a.t:14: unable to move location counter backward for: code.unused_space
12+
# ERR-NEXT: error: a.t:9: unable to move location counter backward for: dummy1
13+
# ERR-NEXT: error: a.t:10: unable to move location counter backward for: dummy2
14+
# ERR-NEXT: error: a.t:14: unable to move location counter backward for: code.unused_space
15+
# ERR-NEXT: error: a.t:9: unable to move location counter backward for: dummy1
16+
# ERR-NEXT: error: a.t:10: unable to move location counter backward for: dummy2
17+
# ERR-NEXT: error: a.t:14: unable to move location counter backward for: code.unused_space
18+
# ERR-NEXT: error: section dummy1 at 0x1000 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
19+
# ERR-NEXT: error: section dummy2 at 0x2000 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
20+
# ERR-NEXT: error: section code.unused_space at 0x4104 of size 0xFFFFFFFFFFFFFF6C exceeds available address space
21+
22+
## If we merge adjacent duplicate entries, we will have enough space. Don't report
23+
## a spurious error https://github.com/llvm/llvm-project/issues/66836
24+
# RUN: not ld.lld -z norelro -z max-page-size=4096 -T a.t a.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
25+
26+
# ERR2: error: a.t:14: unable to move location counter backward for: code.unused_space
27+
28+
#--- a.s
29+
.globl _start
30+
_start:
31+
bx lr
32+
33+
.macro A
34+
.section .text.f\@,"ax"
35+
.globl f\@
36+
f\@:
37+
.fnstart
38+
bx lr
39+
.cantunwind
40+
.fnend
41+
.endm
42+
43+
.rept 20
44+
A
45+
.endr
46+
47+
#--- a.t
48+
MEMORY {
49+
DUMMY1 (RW) : ORIGIN = 0x1000, LENGTH = 0x70
50+
DUMMY2 (RW) : ORIGIN = 0x2000, LENGTH = 0x70
51+
CODE (RX) : ORIGIN = 0x4000, LENGTH = 0x70
52+
}
53+
code_end = ORIGIN(CODE) + LENGTH(CODE);
54+
55+
SECTIONS {
56+
dummy1 (NOLOAD) : { . += code_size; } > DUMMY1
57+
dummy2 (NOLOAD) : { . += code_size; } > DUMMY2
58+
.text : { *(.text .text.*) } > CODE
59+
.ARM.exidx : { *(.ARM.exidx .ARM.exidx.*) } > CODE
60+
code_size = code_end - .;
61+
code.unused_space (NOLOAD) : { . += code_size; } > CODE
62+
}

0 commit comments

Comments
 (0)