xref: /llvm-project/llvm/test/MC/ELF/compress-debug-sections-zstd.s (revision 76a441a6efa5b7e73d96a3d67512493f3873b1cb)
1fbf5e872SFangrui Song# REQUIRES: zstd
2fbf5e872SFangrui Song
3fbf5e872SFangrui Song# RUN: llvm-mc -filetype=obj -triple=x86_64 -compress-debug-sections=zstd %s -o %t
4fbf5e872SFangrui Song# RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SEC
5fbf5e872SFangrui Song# RUN: llvm-objdump -s %t | FileCheck %s
6fbf5e872SFangrui Song
7fbf5e872SFangrui Song## Check that the large debug sections .debug_line and .debug_frame are compressed
8fbf5e872SFangrui Song## and have the SHF_COMPRESSED flag.
9fbf5e872SFangrui Song# SEC: .nonalloc     PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00     0 0  1
10fbf5e872SFangrui Song# SEC: .debug_line   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00   C 0 0  8
11fbf5e872SFangrui Song# SEC: .debug_abbrev PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00     0 0  1
12fbf5e872SFangrui Song# SEC: .debug_info   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00     0 0  1
13*76a441a6SFangrui Song## .debug_str is uncompressed becuase sizeof(Elf64_Chdr)+len(compressed) >= len(uncompressed).
14*76a441a6SFangrui Song# SEC: .debug_str    PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MS  0 0  1
15fbf5e872SFangrui Song# SEC: .debug_frame  PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00   C 0 0  8
16fbf5e872SFangrui Song
17fbf5e872SFangrui Song# CHECK:      Contents of section .debug_line
18fbf5e872SFangrui Song## ch_type == ELFCOMPRESS_ZSTD (2)
19fbf5e872SFangrui Song# CHECK-NEXT: 0000 02000000 00000000 55010000 00000000
20fbf5e872SFangrui Song# CHECK-NEXT: 0010 01000000 00000000 {{.*}}
21fbf5e872SFangrui Song
22fbf5e872SFangrui Song## The compress/decompress round trip should be identical to the uncompressed output.
23fbf5e872SFangrui Song# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.uncom
24fbf5e872SFangrui Song# RUN: llvm-objcopy --decompress-debug-sections %t %t.decom
25fbf5e872SFangrui Song# RUN: cmp %t.uncom %t.decom
26fbf5e872SFangrui Song
27*76a441a6SFangrui Song## .debug_str is compressed becuase sizeof(Elf32_Chdr)+len(compressed) < len(uncompressed).
28*76a441a6SFangrui Song# RUN: llvm-mc -filetype=obj -triple=i386 --defsym I386=1 -compress-debug-sections=zstd --defsym LONG=1 %s -o %t1
29*76a441a6SFangrui Song# RUN: llvm-readelf -S %t1 | FileCheck %s --check-prefix=SEC1
30*76a441a6SFangrui Song
31*76a441a6SFangrui Song# SEC1: .debug_str    PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0  4
32*76a441a6SFangrui Song
33fbf5e872SFangrui Song## Don't compress a section not named .debug_*.
34fbf5e872SFangrui Song	.section .nonalloc,"",@progbits
35fbf5e872SFangrui Song.rept 50
36fbf5e872SFangrui Song.asciz "aaaaaaaaaa"
37fbf5e872SFangrui Song.endr
38fbf5e872SFangrui Song
39fbf5e872SFangrui Song	.section	.debug_line,"",@progbits
40fbf5e872SFangrui Song
41fbf5e872SFangrui Song	.section	.debug_abbrev,"",@progbits
42fbf5e872SFangrui Song.Lsection_abbrev:
43fbf5e872SFangrui Song	.byte	1                       # Abbreviation Code
44fbf5e872SFangrui Song	.byte	17                      # DW_TAG_compile_unit
45fbf5e872SFangrui Song	.byte	0                       # DW_CHILDREN_no
46fbf5e872SFangrui Song	.byte	27                      # DW_AT_comp_dir
47fbf5e872SFangrui Song	.byte	14                      # DW_FORM_strp
48fbf5e872SFangrui Song	.byte	0                       # EOM(1)
49fbf5e872SFangrui Song	.byte	0                       # EOM(2)
50fbf5e872SFangrui Song
51fbf5e872SFangrui Song	.section	.debug_info,"",@progbits
52fbf5e872SFangrui Song	.long	12                      # Length of Unit
53fbf5e872SFangrui Song	.short	4                       # DWARF version number
54fbf5e872SFangrui Song	.long	.Lsection_abbrev        # Offset Into Abbrev. Section
55fbf5e872SFangrui Song	.byte	8                       # Address Size (in bytes)
56fbf5e872SFangrui Song	.byte	1                       # Abbrev [1] DW_TAG_compile_unit
57fbf5e872SFangrui Song	.long	.Linfo_string0          # DW_AT_comp_dir
58fbf5e872SFangrui Song
59fbf5e872SFangrui Song	.text
60fbf5e872SFangrui Songfoo:
61fbf5e872SFangrui Song	.cfi_startproc
62fbf5e872SFangrui Song	.file 1 "Driver.ii"
63fbf5e872SFangrui Song
64fbf5e872SFangrui Song.rept 3
65fbf5e872SFangrui Song.ifdef I386
66fbf5e872SFangrui Song	pushl	%ebp
67fbf5e872SFangrui Song	.cfi_def_cfa_offset 8
68fbf5e872SFangrui Song	.cfi_offset %ebp, -8
69fbf5e872SFangrui Song	movl	%esp, %ebp
70fbf5e872SFangrui Song	.cfi_def_cfa_register %ebp
71fbf5e872SFangrui Song	pushl	%ebx
72fbf5e872SFangrui Song	pushl	%edi
73fbf5e872SFangrui Song	pushl	%esi
74fbf5e872SFangrui Song	.cfi_offset %esi, -20
75fbf5e872SFangrui Song	.cfi_offset %edi, -16
76fbf5e872SFangrui Song	.cfi_offset %ebx, -12
77fbf5e872SFangrui Song	.loc	1 1 1 prologue_end
78fbf5e872SFangrui Song	popl	%esi
79fbf5e872SFangrui Song	popl	%edi
80fbf5e872SFangrui Song	popl	%ebx
81fbf5e872SFangrui Song	popl	%ebp
82fbf5e872SFangrui Song	.cfi_def_cfa %esp, 4
83fbf5e872SFangrui Song.else
84fbf5e872SFangrui Song	pushq	%rbp
85fbf5e872SFangrui Song	.cfi_def_cfa_offset 16
86fbf5e872SFangrui Song	.cfi_offset %rbp, -16
87fbf5e872SFangrui Song	movq	%rsp, %rbp
88fbf5e872SFangrui Song	.cfi_def_cfa_register %rbp
89fbf5e872SFangrui Song	pushq	%r15
90fbf5e872SFangrui Song	pushq	%r14
91fbf5e872SFangrui Song	pushq	%r13
92fbf5e872SFangrui Song	pushq	%r12
93fbf5e872SFangrui Song	pushq	%rbx
94fbf5e872SFangrui Song	.cfi_offset %rbx, -56
95fbf5e872SFangrui Song	.cfi_offset %r12, -48
96fbf5e872SFangrui Song	.cfi_offset %r13, -40
97fbf5e872SFangrui Song	.cfi_offset %r14, -32
98fbf5e872SFangrui Song	.cfi_offset %r15, -24
99fbf5e872SFangrui Song	.loc	1 1 1 prologue_end
100fbf5e872SFangrui Song	popq	%rbx
101fbf5e872SFangrui Song	popq	%r12
102fbf5e872SFangrui Song	popq	%r13
103fbf5e872SFangrui Song	popq	%r14
104fbf5e872SFangrui Song	popq	%r15
105fbf5e872SFangrui Song	popq	%rbp
106fbf5e872SFangrui Song	.cfi_def_cfa %rsp, 8
107fbf5e872SFangrui Song.endif
108fbf5e872SFangrui Song.endr
109fbf5e872SFangrui Song
110fbf5e872SFangrui Song# pad out the line table to make sure it's big enough to warrant compression
111fbf5e872SFangrui Song	.irpc i, 123456789
112fbf5e872SFangrui Song	  .irpc j, 0123456789
113fbf5e872SFangrui Song	    .loc 1 \i\j \j
114fbf5e872SFangrui Song	    nop
115fbf5e872SFangrui Song	   .endr
116fbf5e872SFangrui Song	.endr
117fbf5e872SFangrui Song	.cfi_endproc
118fbf5e872SFangrui Song	.cfi_sections .debug_frame
119fbf5e872SFangrui Song
120fbf5e872SFangrui Song	.section        .debug_str,"MS",@progbits,1
121fbf5e872SFangrui Song.Linfo_string0:
122fbf5e872SFangrui Song	.asciz  "perfectly compressable data sample *****************************************"
123