Skip to content

Commit a02fa37

Browse files
committed
Add linker script test
Created using spr 1.3.6-beta.1
1 parent 678959e commit a02fa37

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

lld/test/ELF/randomize-section-padding.s renamed to lld/test/ELF/randomize-section-padding.test

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
2+
# RUN: split-file %s %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
34

45
## --randomize-section-padding= inserts segment offset padding and pre-section
56
## padding, and does not affect flags. Segment offset padding is only inserted
67
## when PT_LOAD changes, as shown by .bss size (.data and .bss share a PT_LOAD).
78

8-
# RUN: ld.lld --randomize-section-padding=6 %t.o -o %t.out
9-
# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t.out | FileCheck --check-prefix=PAD6 %s
9+
# RUN: ld.lld --randomize-section-padding=6 %t/a.o -o %t/a.out
10+
# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD6 %s
1011

1112
# PAD6: .rodata PROGBITS 0000000000200158 000158 000b8d 00 A 0 0 1
1213
# PAD6: .text PROGBITS 0000000000201ce8 000ce8 000270 00 AX 0 0 4
@@ -28,8 +29,8 @@
2829
## Size of segment offset padding and location of pre-section padding is
2930
## dependent on the seed.
3031

31-
# RUN: ld.lld --randomize-section-padding=46 %t.o -o %t.out
32-
# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t.out | FileCheck --check-prefix=PAD46 %s
32+
# RUN: ld.lld --randomize-section-padding=46 %t/a.o -o %t/a.out
33+
# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46 %s
3334

3435
# PAD46: .rodata PROGBITS 0000000000200158 000158 000cc0 00 A 0 0 1
3536
# PAD46: .text PROGBITS 0000000000201e18 000e18 0009bf 00 AX 0 0 4
@@ -47,6 +48,31 @@
4748
# PAD46: Hex dump of section '.data':
4849
# PAD46: 0x00203d07 00000000 00000000 00000000 07000809
4950

51+
## When there are multiple InputSectionDescriptions for an output section,
52+
## segment offset padding is inserted in the first InputSectionDescription.
53+
54+
# RUN: ld.lld --randomize-section-padding=46 %t/a.o %t/a.lds -o %t/a.out
55+
56+
# RUN: llvm-readelf -sS -x .rodata -x .text -x .data %t/a.out | FileCheck --check-prefix=PAD46-LDS %s
57+
58+
# PAD46-LDS: .rodata PROGBITS 0000000000000158 000158 000cc0 00 A 0 0 1
59+
# PAD46-LDS: .text PROGBITS 0000000000001000 001000 0009c0 00 AX 0 0 4
60+
# PAD46-LDS: .data PROGBITS 0000000000002000 002000 000540 00 WA 0 0 1
61+
# PAD46-LDS: .bss NOBITS 0000000000002540 002540 000004 00 WA 0 0 1
62+
63+
# PAD46-LDS: 0000000000002543 0 NOTYPE LOCAL DEFAULT 4 a
64+
# PAD46-LDS: 0000000000002541 0 NOTYPE LOCAL DEFAULT 4 b
65+
# PAD46-LDS: 0000000000002540 0 NOTYPE LOCAL DEFAULT 4 c
66+
67+
# PAD46-LDS: Hex dump of section '.rodata':
68+
# PAD46-LDS: 0x00000e08 00000000 00000000 00000000 00030201 ................
69+
# PAD46-LDS: Hex dump of section '.text':
70+
# PAD46-LDS: 0x000019b0 cccccccc cccccccc cccc0605 04cccccc ................
71+
# PAD46-LDS: Hex dump of section '.data':
72+
# PAD46-LDS: 0x00002530 00000000 00000000 00000000 09000807 ................
73+
74+
#--- a.s
75+
5076
.section .rodata.a,"a",@progbits
5177
.byte 1
5278

@@ -86,3 +112,14 @@ b:
86112
c:
87113
.zero 1
88114

115+
#--- a.lds
116+
117+
SECTIONS {
118+
. = SIZEOF_HEADERS;
119+
.rodata : { *(.rodata.c) *(.rodata.b) *(.rodata.a) }
120+
. = ALIGN(CONSTANT(MAXPAGESIZE));
121+
.text : { *(.text.c) *(.text.b) *(.text.a) }
122+
. = ALIGN(CONSTANT(MAXPAGESIZE));
123+
.data : { *(.data.c) *(.data.b) *(.data.a) }
124+
.bss : { *(.bss.c) *(.bss.b) *(.bss.a) }
125+
}

0 commit comments

Comments
 (0)