[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.
This commit is contained in:
Fangrui Song 2024-05-22 15:40:24 -07:00
parent bd5c6367bd
commit e53c53559b
6 changed files with 50 additions and 21 deletions

View File

@ -3,22 +3,25 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 --compress-debug-sections=zstd %s -o %t.o
# RUN: ld.lld %t.o -o %t.so -shared
# RUN: llvm-readelf -S -x .debug_str %t.so | FileCheck %s
# RUN: llvm-readelf -S -p .debug_str %t.so | FileCheck %s
# CHECK: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MS 0 0 1
# CHECK: Hex dump of section '.debug_str':
# CHECK-NEXT: 0x00000000 73686f72 7420756e 7369676e 65642069 short unsigned i
# CHECK-NEXT: 0x00000010 6e740075 6e736967 6e656420 63686172 nt.unsigned char
# CHECK-NEXT: 0x00000020 00636861 72006c6f 6e672075 6e736967 .char.long unsig
# CHECK-NEXT: 0x00000030 6e656420 696e7400 756e7369 676e6564 ned int.unsigned
# CHECK-NEXT: 0x00000040 20696e74 00 int.
# CHECK: String dump of section '.debug_str':
# CHECK-NEXT: [ 0] {{A+}}
# CHECK-NEXT: [ 81] short unsigned int
# CHECK-NEXT: [ 94] unsigned char
# CHECK-NEXT: [ a2] char
# CHECK-NEXT: [ a7] long unsigned int
# CHECK-NEXT: [ b9] unsigned int
# RUN: ld.lld %t.o -o %t.so -shared --compress-debug-sections=zstd
# RUN: llvm-readelf -S %t.so | FileCheck %s --check-prefix=OUTPUT-SEC
# RUN: llvm-objcopy --decompress-debug-sections %t.so
# RUN: llvm-readelf -S -x .debug_str %t.so | FileCheck %s
# RUN: llvm-readelf -S -p .debug_str %t.so | FileCheck %s
# OUTPUT-SEC: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0 1
# OUTPUT-SEC: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0 1
# OUTPUT-SEC-NEXT: .debug_frame PROGBITS [[#%x,]] [[#%x,]] 000000 00 0 0 1
# OUTPUT-SEC-NEXT: .debug_loc PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 C 0 0 1
.section .debug_str,"MS",@progbits,1
.LASF2:
@ -31,3 +34,11 @@
.string "char"
.LASF1:
.string "unsigned char"
.Lunused:
.fill 128, 1, 0x41
.byte 0
## Test sections where compressed content would be larger.
.section .debug_frame,""
.section .debug_loc,""
.space 16

View File

@ -14,7 +14,7 @@
# CHECK: warning: {{.*}}: unable to get the string table for the SHT_SYMTAB section: SHT_STRTAB string table section
# CHECK: Hex dump of section '.strtab':
# CHECK-NEXT: 01000000 00000000 1a000000 00000000
# CHECK-NEXT: 01000000 00000000 5c000000 00000000
# CHECK-NEXT: 01000000 00000000 {{.*}}
# RUN: not ld.lld -shared a.o --compress-sections .dynstr=zlib 2>&1 | FileCheck %s --check-prefix=ERR-ALLOC
@ -25,6 +25,8 @@ _start:
l0:
g0:
g1:
.globl ggggggggggggggggggggggggggggggg0
.globl ggggggggggggggggggggggggggggggg1
.section nonalloc0,""
.quad .text+1

View File

@ -11,10 +11,11 @@
# CHECK1-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
# CHECK1: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
# CHECK1-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
# CHECK1-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
# CHECK1-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MS 0 0 1
# CHECK1: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
# CHECK1: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
# CHECK1: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
# CHECK1: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
# RUN: ld.lld -pie a.o --compress-sections '*c0=zlib' --compress-sections .debug_str=zstd:3 -o out2
# RUN: llvm-readelf -SrsX -x nonalloc0 -x .debug_str out2 | FileCheck %s --check-prefix=CHECK2
@ -25,14 +26,15 @@
# CHECK2-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
# CHECK2: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
# CHECK2-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
# CHECK2-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
# CHECK2-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
# CHECK2: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
# CHECK2: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
# CHECK2: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
# CHECK2: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
# CHECK2: Hex dump of section 'nonalloc0':
## zlib with ch_size=0x10
# CHECK2-NEXT: 01000000 00000000 10000000 00000000
## zlib with ch_size=0x90
# CHECK2-NEXT: 01000000 00000000 90000000 00000000
# CHECK2-NEXT: 01000000 00000000 {{.*}}
# CHECK2: Hex dump of section '.debug_str':
## zstd with ch_size=0x38
@ -80,20 +82,28 @@ _start:
.balign 8
.quad .text-.
.quad .text-.
.space 128
.section foo1,"a"
.balign 8
.quad .text-.
.quad .text-.
.space 128
.section nonalloc0,""
.balign 8
.quad .text+1
.quad .text+2
.space 128
sym0:
.section nonalloc1,""
.balign 8
.quad 42
.space 128
sym1:
.section smallc0,""
.balign 8
.space 12
.section .debug_str,"MS",@progbits,1
.Linfo_string0:
.asciz "AAAAAAAAAAAAAAAAAAAAAAAAAAA"

View File

@ -18,8 +18,8 @@
# RUN: llvm-readelf --sections %t.6 | FileCheck -check-prefixes=HEADER,LEVEL6 %s
# HEADER: [Nr] Name Type Address Off Size
# LEVEL1: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[bc]}}
# LEVEL6: [ 1] .debug_info PROGBITS 00000000 000094 00001a
# LEVEL1: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[def]}}
# LEVEL6: [ 1] .debug_info PROGBITS 00000000 000094 00001{{[abc]}}
## A little arbitrary debug section which has a different size after
## applying compression of level 1 and 6.
@ -33,4 +33,4 @@ FileHeader:
Sections:
- Name: .debug_info
Type: SHT_PROGBITS
Content: '010101010101010201010201'
Content: '010101010101010201010201010101010101010201010201010101010101010201010201'

View File

@ -34,3 +34,5 @@
.section .debug_str,"MS",@progbits,1
.asciz "AAA"
.asciz "BBB"
.fill 64,1,0x41
.byte 0

View File

@ -10,10 +10,11 @@
# CHECK-NEXT: str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
# CHECK: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_start
# CHECK: 0000000000000023 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
# CHECK: 0000000000000063 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
# CHECK: String dump of section 'str':
# CHECK-NEXT: [ 0] AAA
# CHECK-NEXT: [ 4] BBB
# CHECK-NEXT: [ 4] {{a+}}
# CHECK-NEXT: [ 45] BBB
## TODO The uncompressed size of 'nonalloc' is dependent on linker script
## commands, which is not handled. We should report an error.
@ -28,6 +29,7 @@ _start:
.balign 8
.quad .text
.quad .text
.space 64
.section nonalloc1,""
.balign 8
.quad 42
@ -35,6 +37,8 @@ _start:
.section str,"MS",@progbits,1
.asciz "AAA"
.asciz "BBB"
.fill 64,1,0x61
.byte 0
#--- a.lds
SECTIONS {