Skip to content

Commit e53c535

Browse files
committed
[ELF,test] Improve --compress-debug-sections/--compress-sections tests
Make sections larger so that compressed content will be smaller than uncompressed content. Add a few dedicated tests where compressed content is larger.
1 parent bd5c636 commit e53c535

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

lld/test/ELF/compress-debug-sections-zstd.s

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
# RUN: llvm-mc -filetype=obj -triple=x86_64 --compress-debug-sections=zstd %s -o %t.o
44

55
# RUN: ld.lld %t.o -o %t.so -shared
6-
# RUN: llvm-readelf -S -x .debug_str %t.so | FileCheck %s
6+
# RUN: llvm-readelf -S -p .debug_str %t.so | FileCheck %s
77

88
# CHECK: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MS 0 0 1
9-
# CHECK: Hex dump of section '.debug_str':
10-
# CHECK-NEXT: 0x00000000 73686f72 7420756e 7369676e 65642069 short unsigned i
11-
# CHECK-NEXT: 0x00000010 6e740075 6e736967 6e656420 63686172 nt.unsigned char
12-
# CHECK-NEXT: 0x00000020 00636861 72006c6f 6e672075 6e736967 .char.long unsig
13-
# CHECK-NEXT: 0x00000030 6e656420 696e7400 756e7369 676e6564 ned int.unsigned
14-
# CHECK-NEXT: 0x00000040 20696e74 00 int.
9+
# CHECK: String dump of section '.debug_str':
10+
# CHECK-NEXT: [ 0] {{A+}}
11+
# CHECK-NEXT: [ 81] short unsigned int
12+
# CHECK-NEXT: [ 94] unsigned char
13+
# CHECK-NEXT: [ a2] char
14+
# CHECK-NEXT: [ a7] long unsigned int
15+
# CHECK-NEXT: [ b9] unsigned int
1516

1617
# RUN: ld.lld %t.o -o %t.so -shared --compress-debug-sections=zstd
1718
# RUN: llvm-readelf -S %t.so | FileCheck %s --check-prefix=OUTPUT-SEC
1819
# RUN: llvm-objcopy --decompress-debug-sections %t.so
19-
# RUN: llvm-readelf -S -x .debug_str %t.so | FileCheck %s
20+
# RUN: llvm-readelf -S -p .debug_str %t.so | FileCheck %s
2021

21-
# OUTPUT-SEC: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0 1
22+
# OUTPUT-SEC: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0 1
23+
# OUTPUT-SEC-NEXT: .debug_frame PROGBITS [[#%x,]] [[#%x,]] 000000 00 0 0 1
24+
# OUTPUT-SEC-NEXT: .debug_loc PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 C 0 0 1
2225

2326
.section .debug_str,"MS",@progbits,1
2427
.LASF2:
@@ -31,3 +34,11 @@
3134
.string "char"
3235
.LASF1:
3336
.string "unsigned char"
37+
.Lunused:
38+
.fill 128, 1, 0x41
39+
.byte 0
40+
41+
## Test sections where compressed content would be larger.
42+
.section .debug_frame,""
43+
.section .debug_loc,""
44+
.space 16

lld/test/ELF/compress-sections-special.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# CHECK: warning: {{.*}}: unable to get the string table for the SHT_SYMTAB section: SHT_STRTAB string table section
1515

1616
# CHECK: Hex dump of section '.strtab':
17-
# CHECK-NEXT: 01000000 00000000 1a000000 00000000
17+
# CHECK-NEXT: 01000000 00000000 5c000000 00000000
1818
# CHECK-NEXT: 01000000 00000000 {{.*}}
1919

2020
# RUN: not ld.lld -shared a.o --compress-sections .dynstr=zlib 2>&1 | FileCheck %s --check-prefix=ERR-ALLOC
@@ -25,6 +25,8 @@ _start:
2525
l0:
2626
g0:
2727
g1:
28+
.globl ggggggggggggggggggggggggggggggg0
29+
.globl ggggggggggggggggggggggggggggggg1
2830

2931
.section nonalloc0,""
3032
.quad .text+1

lld/test/ELF/compress-sections.s

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
# CHECK1-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
1212
# CHECK1: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
1313
# CHECK1-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
14+
# CHECK1-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
1415
# CHECK1-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MS 0 0 1
1516

16-
# CHECK1: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
17-
# CHECK1: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
17+
# CHECK1: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
18+
# CHECK1: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
1819

1920
# RUN: ld.lld -pie a.o --compress-sections '*c0=zlib' --compress-sections .debug_str=zstd:3 -o out2
2021
# RUN: llvm-readelf -SrsX -x nonalloc0 -x .debug_str out2 | FileCheck %s --check-prefix=CHECK2
@@ -25,14 +26,15 @@
2526
# CHECK2-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
2627
# CHECK2: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
2728
# CHECK2-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
29+
# CHECK2-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
2830
# CHECK2-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
2931

30-
# CHECK2: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
31-
# CHECK2: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
32+
# CHECK2: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
33+
# CHECK2: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
3234

3335
# CHECK2: Hex dump of section 'nonalloc0':
34-
## zlib with ch_size=0x10
35-
# CHECK2-NEXT: 01000000 00000000 10000000 00000000
36+
## zlib with ch_size=0x90
37+
# CHECK2-NEXT: 01000000 00000000 90000000 00000000
3638
# CHECK2-NEXT: 01000000 00000000 {{.*}}
3739
# CHECK2: Hex dump of section '.debug_str':
3840
## zstd with ch_size=0x38
@@ -80,20 +82,28 @@ _start:
8082
.balign 8
8183
.quad .text-.
8284
.quad .text-.
85+
.space 128
8386
.section foo1,"a"
8487
.balign 8
8588
.quad .text-.
8689
.quad .text-.
90+
.space 128
8791
.section nonalloc0,""
8892
.balign 8
8993
.quad .text+1
9094
.quad .text+2
95+
.space 128
9196
sym0:
9297
.section nonalloc1,""
9398
.balign 8
9499
.quad 42
100+
.space 128
95101
sym1:
96102

103+
.section smallc0,""
104+
.balign 8
105+
.space 12
106+
97107
.section .debug_str,"MS",@progbits,1
98108
.Linfo_string0:
99109
.asciz "AAAAAAAAAAAAAAAAAAAAAAAAAAA"

lld/test/ELF/compressed-debug-level.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# RUN: llvm-readelf --sections %t.6 | FileCheck -check-prefixes=HEADER,LEVEL6 %s
1919

2020
# HEADER: [Nr] Name Type Address Off Size
21-
# LEVEL1: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[bc]}}
22-
# LEVEL6: [ 1] .debug_info PROGBITS 00000000 000094 00001a
21+
# LEVEL1: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[def]}}
22+
# LEVEL6: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[abc]}}
2323

2424
## A little arbitrary debug section which has a different size after
2525
## applying compression of level 1 and 6.
@@ -33,4 +33,4 @@ FileHeader:
3333
Sections:
3434
- Name: .debug_info
3535
Type: SHT_PROGBITS
36-
Content: '010101010101010201010201'
36+
Content: '010101010101010201010201010101010101010201010201010101010101010201010201'

lld/test/ELF/linkerscript/compress-debug-sections.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
.section .debug_str,"MS",@progbits,1
3535
.asciz "AAA"
3636
.asciz "BBB"
37+
.fill 64,1,0x41
38+
.byte 0

lld/test/ELF/linkerscript/compress-sections.s

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
# CHECK-NEXT: str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
1111

1212
# CHECK: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_start
13-
# CHECK: 0000000000000023 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
13+
# CHECK: 0000000000000063 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
1414
# CHECK: String dump of section 'str':
1515
# CHECK-NEXT: [ 0] AAA
16-
# CHECK-NEXT: [ 4] BBB
16+
# CHECK-NEXT: [ 4] {{a+}}
17+
# CHECK-NEXT: [ 45] BBB
1718

1819
## TODO The uncompressed size of 'nonalloc' is dependent on linker script
1920
## commands, which is not handled. We should report an error.
@@ -28,13 +29,16 @@ _start:
2829
.balign 8
2930
.quad .text
3031
.quad .text
32+
.space 64
3133
.section nonalloc1,""
3234
.balign 8
3335
.quad 42
3436

3537
.section str,"MS",@progbits,1
3638
.asciz "AAA"
3739
.asciz "BBB"
40+
.fill 64,1,0x61
41+
.byte 0
3842

3943
#--- a.lds
4044
SECTIONS {

0 commit comments

Comments
 (0)