xref: /llvm-project/llvm/test/MC/ELF/compress-debug-sections-zlib.s (revision 9f0d5330bd24ac226531ccda4544f94d7e2c18cd)
1*9f0d5330SFangrui Song// REQUIRES: zlib
2*9f0d5330SFangrui Song
3*9f0d5330SFangrui Song// Check zlib style
4*9f0d5330SFangrui Song// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple x86_64-pc-linux-gnu < %s -o %t
5*9f0d5330SFangrui Song// RUN: llvm-objdump -s %t | FileCheck %s
6*9f0d5330SFangrui Song// RUN: llvm-dwarfdump -debug-str %t | FileCheck --check-prefix=STR %s
7*9f0d5330SFangrui Song// RUN: llvm-readelf --sections %t | FileCheck --check-prefixes=FLAGS,FLAGS64 %s
8*9f0d5330SFangrui Song
9*9f0d5330SFangrui Song// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple i386-pc-linux-gnu --defsym I386=1 %s -o %t
10*9f0d5330SFangrui Song// RUN: llvm-readelf -S -s %t | FileCheck --check-prefixes=386-SYMBOLS,FLAGS,FLAGS32 %s
11*9f0d5330SFangrui Song
12*9f0d5330SFangrui Song// Decompress one valid dwarf section just to check that this roundtrips,
13*9f0d5330SFangrui Song// we use .debug_str section for that
14*9f0d5330SFangrui Song// STR: perfectly compressable data sample *****************************************
15*9f0d5330SFangrui Song
16*9f0d5330SFangrui Song
17*9f0d5330SFangrui Song// Now check the zlib style output:
18*9f0d5330SFangrui Song
19*9f0d5330SFangrui Song// Don't compress small sections, such as this simple debug_abbrev example
20*9f0d5330SFangrui Song// CHECK: Contents of section .debug_abbrev:
21*9f0d5330SFangrui Song// CHECK-NOT: ZLIB
22*9f0d5330SFangrui Song// CHECK-NOT: Contents of
23*9f0d5330SFangrui Song// CHECK: Contents of section .debug_info:
24*9f0d5330SFangrui Song// FIXME: Handle compressing alignment fragments to support compressing debug_frame
25*9f0d5330SFangrui Song// CHECK: Contents of section .debug_frame:
26*9f0d5330SFangrui Song// CHECK-NOT: ZLIB
27*9f0d5330SFangrui Song// CHECK: Contents of
28*9f0d5330SFangrui Song
29*9f0d5330SFangrui Song# FLAGS:   .text         PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 AX 0 0  4
30*9f0d5330SFangrui Song# FLAGS:   .nonalloc     PROGBITS [[#%x,]] [[#%x,]] 000226   00    0 0  1
31*9f0d5330SFangrui Song
32*9f0d5330SFangrui Song## Check that the large .debug_line and .debug_frame have the SHF_COMPRESSED
33*9f0d5330SFangrui Song## flag.
34*9f0d5330SFangrui Song# FLAGS32: .debug_line   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00  C 0 0  4
35*9f0d5330SFangrui Song# FLAGS32: .debug_abbrev PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00    0 0  1
36*9f0d5330SFangrui Song# FLAGS32: .debug_info   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00    0 0  1
37*9f0d5330SFangrui Song# FLAGS32: .debug_frame  PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00  C 0 0  4
38*9f0d5330SFangrui Song
39*9f0d5330SFangrui Song# FLAGS64: .debug_line   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00  C 0 0  8
40*9f0d5330SFangrui Song# FLAGS64: .debug_abbrev PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00    0 0  1
41*9f0d5330SFangrui Song# FLAGS64: .debug_info   PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00    0 0  1
42*9f0d5330SFangrui Song# FLAGS64: .debug_frame  PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00  C 0 0  8
43*9f0d5330SFangrui Song
44*9f0d5330SFangrui Song# 386-SYMBOLS: Symbol table '.symtab'
45*9f0d5330SFangrui Song# 386-SYMBOLS: .debug_str
46*9f0d5330SFangrui Song
47*9f0d5330SFangrui Song## Don't compress a section not named .debug_*.
48*9f0d5330SFangrui Song        .section .nonalloc,"",@progbits
49*9f0d5330SFangrui Song.rept 50
50*9f0d5330SFangrui Song.asciz "aaaaaaaaaa"
51*9f0d5330SFangrui Song.endr
52*9f0d5330SFangrui Song
53*9f0d5330SFangrui Song	.section	.debug_line,"",@progbits
54*9f0d5330SFangrui Song
55*9f0d5330SFangrui Song	.section	.debug_abbrev,"",@progbits
56*9f0d5330SFangrui Song.Lsection_abbrev:
57*9f0d5330SFangrui Song	.byte	1                       # Abbreviation Code
58*9f0d5330SFangrui Song	.byte	17                      # DW_TAG_compile_unit
59*9f0d5330SFangrui Song	.byte	0                       # DW_CHILDREN_no
60*9f0d5330SFangrui Song	.byte	27                      # DW_AT_comp_dir
61*9f0d5330SFangrui Song	.byte	14                      # DW_FORM_strp
62*9f0d5330SFangrui Song	.byte	0                       # EOM(1)
63*9f0d5330SFangrui Song	.byte	0                       # EOM(2)
64*9f0d5330SFangrui Song
65*9f0d5330SFangrui Song	.section	.debug_info,"",@progbits
66*9f0d5330SFangrui Song	.long	12                      # Length of Unit
67*9f0d5330SFangrui Song	.short	4                       # DWARF version number
68*9f0d5330SFangrui Song	.long	.Lsection_abbrev        # Offset Into Abbrev. Section
69*9f0d5330SFangrui Song	.byte	8                       # Address Size (in bytes)
70*9f0d5330SFangrui Song	.byte	1                       # Abbrev [1] DW_TAG_compile_unit
71*9f0d5330SFangrui Song	.long	.Linfo_string0          # DW_AT_comp_dir
72*9f0d5330SFangrui Song
73*9f0d5330SFangrui Song	.text
74*9f0d5330SFangrui Songfoo:
75*9f0d5330SFangrui Song	.cfi_startproc
76*9f0d5330SFangrui Song	.file 1 "Driver.ii"
77*9f0d5330SFangrui Song
78*9f0d5330SFangrui Song.rept 3
79*9f0d5330SFangrui Song.ifdef I386
80*9f0d5330SFangrui Song	pushl	%ebp
81*9f0d5330SFangrui Song	.cfi_def_cfa_offset 8
82*9f0d5330SFangrui Song	.cfi_offset %ebp, -8
83*9f0d5330SFangrui Song	movl	%esp, %ebp
84*9f0d5330SFangrui Song	.cfi_def_cfa_register %ebp
85*9f0d5330SFangrui Song	pushl	%ebx
86*9f0d5330SFangrui Song	pushl	%edi
87*9f0d5330SFangrui Song	pushl	%esi
88*9f0d5330SFangrui Song	.cfi_offset %esi, -20
89*9f0d5330SFangrui Song	.cfi_offset %edi, -16
90*9f0d5330SFangrui Song	.cfi_offset %ebx, -12
91*9f0d5330SFangrui Song	.loc	1 1 1 prologue_end
92*9f0d5330SFangrui Song	popl	%esi
93*9f0d5330SFangrui Song	popl	%edi
94*9f0d5330SFangrui Song	popl	%ebx
95*9f0d5330SFangrui Song	popl	%ebp
96*9f0d5330SFangrui Song	.cfi_def_cfa %esp, 4
97*9f0d5330SFangrui Song.else
98*9f0d5330SFangrui Song	pushq	%rbp
99*9f0d5330SFangrui Song	.cfi_def_cfa_offset 16
100*9f0d5330SFangrui Song	.cfi_offset %rbp, -16
101*9f0d5330SFangrui Song	movq	%rsp, %rbp
102*9f0d5330SFangrui Song	.cfi_def_cfa_register %rbp
103*9f0d5330SFangrui Song	pushq	%r15
104*9f0d5330SFangrui Song	pushq	%r14
105*9f0d5330SFangrui Song	pushq	%r13
106*9f0d5330SFangrui Song	pushq	%r12
107*9f0d5330SFangrui Song	pushq	%rbx
108*9f0d5330SFangrui Song	.cfi_offset %rbx, -56
109*9f0d5330SFangrui Song	.cfi_offset %r12, -48
110*9f0d5330SFangrui Song	.cfi_offset %r13, -40
111*9f0d5330SFangrui Song	.cfi_offset %r14, -32
112*9f0d5330SFangrui Song	.cfi_offset %r15, -24
113*9f0d5330SFangrui Song	.loc	1 1 1 prologue_end
114*9f0d5330SFangrui Song	popq	%rbx
115*9f0d5330SFangrui Song	popq	%r12
116*9f0d5330SFangrui Song	popq	%r13
117*9f0d5330SFangrui Song	popq	%r14
118*9f0d5330SFangrui Song	popq	%r15
119*9f0d5330SFangrui Song	popq	%rbp
120*9f0d5330SFangrui Song	.cfi_def_cfa %rsp, 8
121*9f0d5330SFangrui Song.endif
122*9f0d5330SFangrui Song.endr
123*9f0d5330SFangrui Song
124*9f0d5330SFangrui Song# pad out the line table to make sure it's big enough to warrant compression
125*9f0d5330SFangrui Song	.irpc i, 123456789
126*9f0d5330SFangrui Song	  .irpc j, 0123456789
127*9f0d5330SFangrui Song	    .loc 1 \i\j \j
128*9f0d5330SFangrui Song	    nop
129*9f0d5330SFangrui Song	   .endr
130*9f0d5330SFangrui Song	.endr
131*9f0d5330SFangrui Song	.cfi_endproc
132*9f0d5330SFangrui Song	.cfi_sections .debug_frame
133*9f0d5330SFangrui Song
134*9f0d5330SFangrui Song# Below is the section we will use to check that after compression with llvm-mc,
135*9f0d5330SFangrui Song# llvm-dwarfdump tool will be able to decompress data back and dump it. Data sample
136*9f0d5330SFangrui Song# should be compressable enough, so it is filled with some amount of equal symbols at the end
137*9f0d5330SFangrui Song	.section        .debug_str,"MS",@progbits,1
138*9f0d5330SFangrui Song.Linfo_string0:
139*9f0d5330SFangrui Song        .asciz  "perfectly compressable data sample *****************************************"
140