[memprof] Remove an unused using directive (#117004)
[llvm-project.git] / lld / test / ELF / compress-sections.s
blobaaad31476044ecd55895b5b71306d470a146fd6c
1 # REQUIRES: x86, zlib, zstd
3 # RUN: rm -rf %t && mkdir %t && cd %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o a.o
5 # RUN: ld.lld -pie a.o -o out --compress-sections '*0=zlib' --compress-sections '*0=none' --compress-sections 'nomatch=none'
6 # RUN: llvm-readelf -SrsX out | FileCheck %s --check-prefix=CHECK1
8 # CHECK1: Name Type Address Off Size ES Flg Lk Inf Al
9 # CHECK1: foo0 PROGBITS [[#%x,FOO0:]] [[#%x,]] [[#%x,]] 00 A 0 0 8
10 # CHECK1-NEXT: foo1 PROGBITS [[#%x,FOO1:]] [[#%x,]] [[#%x,]] 00 A 0 0 8
11 # CHECK1-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
12 # CHECK1: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
13 # CHECK1-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
14 # CHECK1-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8
15 # CHECK1-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MS 0 0 1
17 # CHECK1: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
18 # CHECK1: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
20 # RUN: ld.lld -pie a.o --compress-sections '*c0=zlib' --compress-sections .debug_str=zstd:3 -o out2
21 # RUN: llvm-readelf -SrsX -x nonalloc0 -x .debug_str out2 | FileCheck %s --check-prefix=CHECK2
23 # CHECK2: Name Type Address Off Size ES Flg Lk Inf Al
24 # CHECK2: foo0 PROGBITS [[#%x,FOO0:]] [[#%x,]] [[#%x,]] 00 A 0 0 8
25 # CHECK2-NEXT: foo1 PROGBITS [[#%x,FOO1:]] [[#%x,]] [[#%x,]] 00 A 0 0 8
26 # CHECK2-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4
27 # CHECK2: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
28 # CHECK2-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] 000088 00 0 0 8
29 # CHECK2-NEXT: smallc0 PROGBITS 0000000000000000 [[#%x,]] 00000c 00 0 0 1
30 # CHECK2-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
32 # CHECK2: 0000000000000090 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0
33 # CHECK2: 0000000000000088 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1
35 # CHECK2: Hex dump of section 'nonalloc0':
36 ## zlib with ch_size=0x90
37 # CHECK2-NEXT: 01000000 00000000 90000000 00000000
38 # CHECK2-NEXT: 01000000 00000000 {{.*}}
39 # CHECK2: Hex dump of section '.debug_str':
40 ## zstd with ch_size=0x38
41 # CHECK2-NEXT: 02000000 00000000 38000000 00000000
42 # CHECK2-NEXT: 01000000 00000000 {{.*}}
44 ## --compress-sections takes precedence.
45 # RUN: ld.lld a.o --compress-sections .debug_str=zstd --compress-debug-sections=none -o out3
46 # RUN: llvm-readelf -S out3 | FileCheck %s --check-prefix=CHECK3
48 # CHECK3: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
50 # RUN: not ld.lld a.o --compress-sections '*0=zlib' 2>&1 | \
51 # RUN: FileCheck %s --check-prefix=ERR-ALLOC --implicit-check-not=error:
52 # ERR-ALLOC: error: --compress-sections: section 'foo0' with the SHF_ALLOC flag cannot be compressed
54 # RUN: not ld.lld --compress-sections=foo a.o 2>&1 | \
55 # RUN: FileCheck %s --check-prefix=ERR1 --implicit-check-not=error:
56 # ERR1: error: --compress-sections: parse error, not 'section-glob=[none|zlib|zstd]'
58 # RUN: not ld.lld --compress-sections 'a[=zlib' a.o 2>&1 | \
59 # RUN: FileCheck %s --check-prefix=ERR2 --implicit-check-not=error:
60 # ERR2: error: --compress-sections: invalid glob pattern, unmatched '['
62 # RUN: not ld.lld a.o --compress-sections='.debug*=zlib-gabi' --compress-sections='.debug*=' 2>&1 | \
63 # RUN: FileCheck -check-prefix=ERR3 %s
64 # ERR3: unknown --compress-sections value: zlib-gabi
65 # ERR3-NEXT: --compress-sections: parse error, not 'section-glob=[none|zlib|zstd]'
67 # RUN: not ld.lld a.o --compress-sections='a=zlib:' --compress-sections='a=zlib:-1' 2>&1 | \
68 # RUN: FileCheck %s --check-prefix=ERR4 --implicit-check-not=error:
69 # ERR4: error: --compress-sections: expected a non-negative integer compression level, but got ''
70 # ERR4: error: --compress-sections: expected a non-negative integer compression level, but got '-1'
72 ## Invalid compression level for zlib.
73 # RUN: not ld.lld a.o --compress-sections='.debug*=zlib:99' 2>&1 | \
74 # RUN: FileCheck %s --check-prefix=ERR6 --implicit-check-not=error:
75 # ERR6: error: --compress-sections: deflateInit2 returned -2
77 .globl _start
78 _start:
79 ret
81 .section foo0,"a"
82 .balign 8
83 .quad .text-.
84 .quad .text-.
85 .space 128
86 .section foo1,"a"
87 .balign 8
88 .quad .text-.
89 .quad .text-.
90 .space 128
91 .section nonalloc0,""
92 .balign 8
93 .quad .text+1
94 .quad .text+2
95 .space 128
96 sym0:
97 .section nonalloc1,""
98 .balign 8
99 .quad 42
100 .space 128
101 sym1:
103 .section smallc0,""
104 .balign 8
105 .space 12
107 .section .debug_str,"MS",@progbits,1
108 .Linfo_string0:
109 .asciz "AAAAAAAAAAAAAAAAAAAAAAAAAAA"
110 .Linfo_string1:
111 .asciz "BBBBBBBBBBBBBBBBBBBBBBBBBBB"