xref: /llvm-project/llvm/test/tools/llvm-objcopy/wasm/only-keep-debug.test (revision 2a6136e552d24b6bf665c42a6e32efc0b2d88fbf)
1## Test that only debug sections are kept with --only-keep-debug.
2# RUN: yaml2obj %s -o %t.wasm
3# RUN: llvm-strip --only-keep-debug %t.wasm -o %t2.wasm
4# RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefixes=CHECK,STRIPTYPE,STRIPFOO
5
6## Test that keep-section overrides only-keep-debug.
7# RUN: llvm-strip --only-keep-debug --keep-section=foo %t.wasm -o %t3.wasm
8# RUN: obj2yaml %t3.wasm | FileCheck --implicit-check-not=Name --check-prefixes=CHECK,STRIPTYPE,KEEPFOO %s
9
10## Test that keep-section overrides only-keep-debug, even for known sections.
11# RUN: llvm-strip --only-keep-debug --keep-section=TYPE %t.wasm -o %t4.wasm
12# RUN: obj2yaml %t4.wasm | FileCheck --implicit-check-not=Name --check-prefixes=CHECK,KEEPTYPE,STRIPFOO %s
13
14# CHECK:      Sections:
15# KEEPTYPE:       - Type: TYPE
16# STRIPTYPE-NOT:  - Type: TYPE
17# STRIPTYPE:      - Type: CUSTOM
18# STRIPTYPE-NEXT:   Name: .objcopy.removed
19# CHECK:          - Type: CUSTOM
20# CHECK-NEXT:       Name: .debug_info
21# CHECK:          - Type: CUSTOM
22# CHECK-NEXT:       Name: .objcopy.removed
23# CHECK:          - Type: CUSTOM
24# CHECK-NEXT:       Name: .objcopy.removed
25# CHECK:          - Type: CUSTOM
26# CHECK-NEXT:       Name: .debug_line
27# CHECK:          - Type: CUSTOM
28# KEEPFOO-NEXT:     Name: foo
29# STRIPFOO-NEXT:    Name: .objcopy.removed
30
31## Test that remove-section overrides only-keep-debug.
32# RUN: yaml2obj %s -o %t
33# RUN: llvm-strip --only-keep-debug --remove-section=.debug_info %t
34# RUN: obj2yaml %t | FileCheck %s --check-prefix=NOINFO --implicit-check-not=.debug_info
35
36# NOINFO: Name: .debug_line
37
38--- !WASM
39FileHeader:
40  Version: 0x00000001
41Sections:
42  - Type: TYPE
43    Signatures:
44      - Index: 0
45        ParamTypes:
46          - I32
47        ReturnTypes:
48          - F32
49  - Type: CUSTOM
50    Name: .debug_info
51    Payload: CAFE1234
52  - Type: CUSTOM
53    Name: linking
54    Version: 2
55  - Type: CUSTOM
56    Name: producers
57    Tools:
58      - Name:   clang
59        Version: 9.0.0
60  - Type: CUSTOM
61    Name: .debug_line
62    Payload: DEADBEEF
63  - Type: CUSTOM
64    Name: foo
65    Payload: CAFE
66