xref: /llvm-project/llvm/test/tools/llvm-objcopy/wasm/add-section.test (revision 91d0618368c0248e200d90b367322f9c1f74e387)
1## Test --add-section. This test dumps and removes the section first and checks
2## that adding it back doesn't change the result.
3# RUN: yaml2obj %s -o %t
4# RUN: llvm-objcopy --dump-section=producers=%t.sec --remove-section=producers %t %t2
5# RUN: llvm-objcopy --add-section=producers=%t.sec %t2 %t3
6# RUN: obj2yaml %t3 | FileCheck %s
7
8## Check that the producers section has been added back unchanged.
9# CHECK:      Name: producers
10# CHECK-NEXT: Tools:
11# CHECK-NEXT:  - Name:    clang
12# CHECK-NEXT:    Version: 9.0.0
13
14# Check that the section is replaced with new content in one invocation.
15# RUN: echo "123" > %t4
16# RUN: llvm-objcopy --remove-section=foo --add-section=foo=%t4 %t %t5
17# RUN: obj2yaml %t5 | FileCheck %s --check-prefix=REPLACE
18
19# REPLACE: - Type:  CUSTOM
20# REPLACE:   Name:    foo
21# REPLACE:   Payload: 3132330A
22
23## Check that raw data bytes can be imported and exported unchanged especially the ones containing empty bytes.
24# RUN: echo -e -n "\x02\x01\x00\x01\x02" > %t6
25# RUN: llvm-objcopy --add-section=bar=%t6 %t %t7
26# RUN: llvm-objcopy --dump-section=bar=%t8 %t7
27# RUN: diff %t8 %t6
28# RUN: obj2yaml %t7 | FileCheck %s --check-prefix=RAW-DATA
29
30## Check that raw data is well formated in the file as well.
31# RAW-DATA:      Name: bar
32# RAW-DATA-NEXT: Payload: '0201000102'
33
34--- !WASM
35FileHeader:
36  Version: 0x00000001
37Sections:
38  - Type: TYPE
39    Signatures:
40      - Index: 0
41        ParamTypes:
42          - I32
43        ReturnTypes:
44          - F32
45      - Index: 1
46        ParamTypes:
47          - I32
48          - I64
49        ReturnTypes: []
50  - Type: FUNCTION
51    FunctionTypes:
52      - 0
53      - 1
54  - Type: CODE
55    Relocations:
56      - Type: R_WASM_TABLE_INDEX_SLEB
57        Index: 0
58        Offset: 0x00000000
59      - Type: R_WASM_FUNCTION_INDEX_LEB
60        Index: 1
61        Offset: 0x0000000
62    Functions:
63      - Index: 0
64        Locals:
65         - Type: I32
66           Count: 3
67        Body: 010101010B
68      - Index: 1
69        Locals:
70         - Type:  I32
71           Count: 1
72        Body: 010101010B
73  - Type: CUSTOM
74    Name: linking
75    Version: 2
76    SymbolTable:
77      - Index:    0
78        Kind:     FUNCTION
79        Name:     func1
80        Flags:    [  ]
81        Function: 0
82      - Index:    1
83        Kind:     FUNCTION
84        Name:     func2
85        Flags:    [  ]
86        Function: 1
87  - Type: CUSTOM
88    Name: producers
89    Tools:
90      - Name:   clang
91        Version: 9.0.0
92  - Type: CUSTOM
93    Name: foo
94    Payload: ABC123
95