xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-zstd.test (revision c26dc2904b95b3685d883e760e84046ea6c33d7f)
1# REQUIRES: zstd
2## Test --compress-debug-sections=zstd and decompression.
3
4# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t && llvm-objcopy %t
5# RUN: llvm-objcopy --compress-debug-sections=zstd %t %t-zstd
6# RUN: llvm-objcopy --decompress-debug-sections %t-zstd %t-de
7# RUN: cmp %t %t-de
8
9# RUN: llvm-readelf -S -r -x .debug_foo %t-zstd | FileCheck %s --check-prefixes=CHECK,COMPRESSED
10# RUN: llvm-readelf -S -r -x .debug_foo %t-de | FileCheck %s --check-prefixes=CHECK,DECOMPRESSED
11
12# CHECK:             Name              Type            Address          Off    Size   ES Flg Lk Inf Al
13# COMPRESSED:        .debug_foo        PROGBITS        0000000000000000 000040 {{.*}} 00   C  0   0  8
14# COMPRESSED-NEXT:   .notdebug_foo     PROGBITS        0000000000000000 {{.*}} 000008 00      0   0  0
15# DECOMPRESSED:      .debug_foo        PROGBITS        0000000000000000 000040 000008 00      0   0  0
16# DECOMPRESSED-NEXT: .notdebug_foo     PROGBITS        0000000000000000 {{.*}} 000008 00      0   0  0
17
18## Relocations do not change.
19# CHECK:             Relocation section '.rela.debug_foo' at offset {{.*}} contains 2 entries:
20# CHECK-NEXT:            Offset
21# CHECK-NEXT:        0000000000000001  000000010000000a R_X86_64_32            0000000000000000 .debug_foo + 0
22# CHECK-NEXT:        0000000000000002  000000020000000a R_X86_64_32            0000000000000000 .notdebug_foo + 0
23
24# COMPRESSED:        Hex dump of section '.debug_foo':
25## ch_type == ELFCOMPRESS_ZSTD (2)
26# COMPRESSED-NEXT:   0x00000000 02000000 00000000 08000000 00000000
27# COMPRESSED-NEXT:   0x00000010 00000000 00000000 {{.*}}
28
29## --compress-debug-sections does not update a compressed section. Its compression
30## type does not change.
31# RUN: llvm-objcopy --compress-debug-sections=zstd %t-zstd %t-zstd-zstd
32# RUN: cmp %t-zstd %t-zstd-zstd
33# RUN: %if zlib %{ llvm-objcopy --compress-debug-sections=zlib %t-zstd %t-zstd-zlib && cmp %t-zstd %t-zstd-zlib %}
34
35# RUN: yaml2obj %s -o %t-corrupted
36# RUN: not llvm-objcopy --decompress-debug-sections %t-corrupted /dev/null 2>&1 | FileCheck %s -DFILE=%t-corrupted --check-prefix=ERR
37
38# ERR: error: '[[FILE]]': failed to decompress section '.debug_info': Src size is incorrect
39
40--- !ELF
41FileHeader:
42  Class:   ELFCLASS64
43  Data:    ELFDATA2LSB
44  Type:    ET_REL
45  Machine: EM_X86_64
46Sections:
47  - Type:         SHT_PROGBITS
48    Name:         .debug_info
49    Flags:        [ SHF_COMPRESSED ]
50    AddressAlign: 8
51    Content:      "020000000000000004000000000000000100000000000000ffffffff"
52