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