|
| 1 | +# REQUIRES: x86, zlib, zstd |
| 2 | + |
| 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 |
| 7 | + |
| 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: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MS 0 0 1 |
| 15 | + |
| 16 | +# CHECK1: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0 |
| 17 | +# CHECK1: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1 |
| 18 | + |
| 19 | +# RUN: ld.lld -pie a.o --compress-sections '*c0=zlib' --compress-sections .debug_str=zstd -o out2 |
| 20 | +# RUN: llvm-readelf -SrsX -x nonalloc0 -x .debug_str out2 | FileCheck %s --check-prefix=CHECK2 |
| 21 | + |
| 22 | +# CHECK2: Name Type Address Off Size ES Flg Lk Inf Al |
| 23 | +# CHECK2: foo0 PROGBITS [[#%x,FOO0:]] [[#%x,]] [[#%x,]] 00 A 0 0 8 |
| 24 | +# CHECK2-NEXT: foo1 PROGBITS [[#%x,FOO1:]] [[#%x,]] [[#%x,]] 00 A 0 0 8 |
| 25 | +# CHECK2-NEXT: .text PROGBITS [[#%x,TEXT:]] [[#%x,]] [[#%x,]] 00 AX 0 0 4 |
| 26 | +# CHECK2: nonalloc0 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1 |
| 27 | +# CHECK2-NEXT: nonalloc1 PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 8 |
| 28 | +# CHECK2-NEXT: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1 |
| 29 | + |
| 30 | +# CHECK2: 0000000000000010 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc0) sym0 |
| 31 | +# CHECK2: 0000000000000008 0 NOTYPE LOCAL DEFAULT [[#]] (nonalloc1) sym1 |
| 32 | + |
| 33 | +# CHECK2: Hex dump of section 'nonalloc0': |
| 34 | +## zlib with ch_size=0x10 |
| 35 | +# CHECK2-NEXT: 01000000 00000000 10000000 00000000 |
| 36 | +# CHECK2-NEXT: 01000000 00000000 {{.*}} |
| 37 | +# CHECK2: Hex dump of section '.debug_str': |
| 38 | +## zstd with ch_size=0x38 |
| 39 | +# CHECK2-NEXT: 02000000 00000000 38000000 00000000 |
| 40 | +# CHECK2-NEXT: 01000000 00000000 {{.*}} |
| 41 | + |
| 42 | +## --compress-debug-sections=none takes precedence. |
| 43 | +# RUN: ld.lld a.o --compress-debug-sections=none --compress-sections .debug_str=zstd -o out3 |
| 44 | +# RUN: llvm-readelf -S out3 | FileCheck %s --check-prefix=CHECK3 |
| 45 | + |
| 46 | +# CHECK3: .debug_str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MS 0 0 1 |
| 47 | + |
| 48 | +# RUN: not ld.lld a.o --compress-sections '*0=zlib' 2>&1 | \ |
| 49 | +# RUN: FileCheck %s --check-prefix=ERR-ALLOC --implicit-check-not=error: |
| 50 | +# ERR-ALLOC: error: --compress-sections: section 'foo0' with the SHF_ALLOC flag cannot be compressed |
| 51 | + |
| 52 | +# RUN: not ld.lld --compress-sections=foo a.o 2>&1 | \ |
| 53 | +# RUN: FileCheck %s --check-prefix=ERR1 --implicit-check-not=error: |
| 54 | +# ERR1: error: --compress-sections: parse error, not 'section-glob=[none|zlib|zstd]' |
| 55 | + |
| 56 | +# RUN: not ld.lld --compress-sections 'a[=zlib' a.o 2>&1 | \ |
| 57 | +# RUN: FileCheck %s --check-prefix=ERR2 --implicit-check-not=error: |
| 58 | +# ERR2: error: --compress-sections: invalid glob pattern, unmatched '[' |
| 59 | + |
| 60 | +# RUN: not ld.lld a.o --compress-sections='.debug*=zlib-gabi' --compress-sections='.debug*=' 2>&1 | \ |
| 61 | +# RUN: FileCheck -check-prefix=ERR3 %s |
| 62 | +# ERR3: unknown --compress-sections value: zlib-gabi |
| 63 | +# ERR3-NEXT: --compress-sections: parse error, not 'section-glob=[none|zlib|zstd]' |
| 64 | + |
| 65 | +.globl _start |
| 66 | +_start: |
| 67 | + ret |
| 68 | + |
| 69 | +.section foo0,"a" |
| 70 | +.balign 8 |
| 71 | +.quad .text-. |
| 72 | +.quad .text-. |
| 73 | +.section foo1,"a" |
| 74 | +.balign 8 |
| 75 | +.quad .text-. |
| 76 | +.quad .text-. |
| 77 | +.section nonalloc0,"" |
| 78 | +.balign 8 |
| 79 | +.quad .text+1 |
| 80 | +.quad .text+2 |
| 81 | +sym0: |
| 82 | +.section nonalloc1,"" |
| 83 | +.balign 8 |
| 84 | +.quad 42 |
| 85 | +sym1: |
| 86 | + |
| 87 | +.section .debug_str,"MS",@progbits,1 |
| 88 | +.Linfo_string0: |
| 89 | + .asciz "AAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 90 | +.Linfo_string1: |
| 91 | + .asciz "BBBBBBBBBBBBBBBBBBBBBBBBBBB" |
0 commit comments