1; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o
2; RUN: llc -filetype=obj %s -o %t.o
3; RUN: wasm-ld -r -o %t.wasm %t.hello.o %t.o
4; RUN: obj2yaml %t.wasm | FileCheck %s
5
6target triple = "wasm32-unknown-unknown"
7
8; Function Attrs: nounwind
9define hidden i32 @my_func() local_unnamed_addr {
10entry:
11  %call = tail call i32 @foo_import()
12  %call2 = tail call i32 @bar_import()
13  ret i32 1
14}
15
16declare i32 @foo_import() local_unnamed_addr
17declare extern_weak i32 @bar_import() local_unnamed_addr
18@data_import = external global i64
19
20@func_addr1 = hidden global i32()* @my_func, align 4
21@func_addr2 = hidden global i32()* @foo_import, align 4
22@func_addr3 = hidden global i32()* @bar_import, align 4
23@data_addr1 = hidden global i64* @data_import, align 8
24
25$func_comdat = comdat any
26@data_comdat = weak_odr constant [3 x i8] c"abc", comdat($func_comdat)
27define linkonce_odr i32 @func_comdat() comdat {
28entry:
29  ret i32 ptrtoint ([3 x i8]* @data_comdat to i32)
30}
31
32; Test that __attribute__(used) (i.e NO_STRIP) is preserved in the relocated symbol table
33@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @my_func to i8*)], section "llvm.metadata"
34
35; CHECK:      --- !WASM
36; CHECK-NEXT: FileHeader:
37; CHECK-NEXT:   Version:         0x00000001
38; CHECK-NEXT: Sections:
39; CHECK-NEXT:   - Type:            TYPE
40; CHECK-NEXT:     Signatures:
41; CHECK-NEXT:       - Index:           0
42; CHECK-NEXT:         ParamTypes:
43; CHECK-NEXT:           - I32
44; CHECK-NEXT:         ReturnTypes:     []
45; CHECK-NEXT:       - Index:           1
46; CHECK-NEXT:         ParamTypes:
47; CHECK-NEXT:         ReturnTypes:
48; CHECK-NEXT:           - I32
49; CHECK-NEXT:       - Index:           2
50; CHECK-NEXT:         ParamTypes:
51; CHECK-NEXT:         ReturnTypes:     []
52; CHECK-NEXT:   - Type:            IMPORT
53; CHECK-NEXT:     Imports:
54; CHECK-NEXT:       - Module:          env
55; CHECK-NEXT:         Field:           puts
56; CHECK-NEXT:         Kind:            FUNCTION
57; CHECK-NEXT:         SigIndex:        0
58; CHECK-NEXT:       - Module:          env
59; CHECK-NEXT:         Field:           foo_import
60; CHECK-NEXT:         Kind:            FUNCTION
61; CHECK-NEXT:         SigIndex:        1
62; CHECK-NEXT:       - Module:          env
63; CHECK-NEXT:         Field:           bar_import
64; CHECK-NEXT:         Kind:            FUNCTION
65; CHECK-NEXT:         SigIndex:        1
66; CHECK-NEXT:   - Type:            FUNCTION
67; CHECK-NEXT:     FunctionTypes:   [ 2, 1, 1 ]
68; CHECK-NEXT:   - Type:            TABLE
69; CHECK-NEXT:     Tables:
70; CHECK-NEXT:       - ElemType:        FUNCREF
71; CHECK-NEXT:         Limits:
72; CHECK-NEXT:           Flags:           [ HAS_MAX ]
73; CHECK-NEXT:           Initial:         0x00000004
74; CHECK-NEXT:           Maximum:         0x00000004
75; CHECK-NEXT:   - Type:            MEMORY
76; CHECK-NEXT:     Memories:
77; CHECK-NEXT:      - Initial:         0x00000001
78; CHECK-NEXT:   - Type:            ELEM
79; CHECK-NEXT:     Segments:
80; CHECK-NEXT:       - Offset:
81; CHECK-NEXT:           Opcode:          I32_CONST
82; CHECK-NEXT:           Value:           1
83; CHECK-NEXT:         Functions:       [ 4, 1, 2 ]
84; SHARED-NEXT:  - Type:            DATACOUNT
85; SHARED-NEXT:    Count:           6
86; CHECK-NEXT:   - Type:            CODE
87; CHECK-NEXT:     Relocations:
88; CHECK-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB
89; CHECK-NEXT:         Index:           1
90; CHECK-NEXT:         Offset:          0x00000004
91; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
92; CHECK-NEXT:         Index:           2
93; CHECK-NEXT:         Offset:          0x0000000A
94; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
95; CHECK-NEXT:         Index:           4
96; CHECK-NEXT:         Offset:          0x00000013
97; CHECK-NEXT:       - Type:            R_WASM_FUNCTION_INDEX_LEB
98; CHECK-NEXT:         Index:           5
99; CHECK-NEXT:         Offset:          0x0000001A
100; CHECK-NEXT:       - Type:            R_WASM_MEMORY_ADDR_SLEB
101; CHECK-NEXT:         Index:           7
102; CHECK-NEXT:         Offset:          0x00000026
103; CHECK-NEXT:     Functions:
104; CHECK-NEXT:       - Index:         3
105; CHECK-NEXT:         Locals:
106; CHECK-NEXT:         Body:          4180808080001080808080000B
107; CHECK-NEXT:       - Index:         4
108; CHECK-NEXT:         Locals:
109; CHECK-NEXT:         Body:          1081808080001A1082808080001A41010B
110; CHECK-NEXT:       - Index:         5
111; CHECK-NEXT:         Locals:
112; CHECK-NEXT:         Body:          4187808080000B
113; NORMAL-NEXT:  - Type:            DATA
114; NORMAL-NEXT:    Relocations:
115; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
116; NORMAL-NEXT:        Index:           3
117; NORMAL-NEXT:        Offset:          0x0000001A
118; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
119; NORMAL-NEXT:        Index:           4
120; NORMAL-NEXT:        Offset:          0x00000023
121; NORMAL-NEXT:      - Type:            R_WASM_TABLE_INDEX_I32
122; NORMAL-NEXT:        Index:           5
123; NORMAL-NEXT:        Offset:          0x0000002C
124; NORMAL-NEXT:      - Type:            R_WASM_MEMORY_ADDR_I32
125; NORMAL-NEXT:        Index:           12
126; NORMAL-NEXT:        Offset:          0x00000035
127; NORMAL-NEXT:    Segments:
128; NORMAL-NEXT:      - SectionOffset:   6
129; NORMAL-NEXT:        InitFlags:       0
130; NORMAL-NEXT:        Offset:
131; NORMAL-NEXT:          Opcode:          I32_CONST
132; NORMAL-NEXT:          Value:           0
133; NORMAL-NEXT:        Content:         68656C6C6F0A00
134; NORMAL-NEXT:      - SectionOffset:   18
135; NORMAL-NEXT:        InitFlags:       0
136; NORMAL-NEXT:        Offset:
137; NORMAL-NEXT:          Opcode:          I32_CONST
138; NORMAL-NEXT:          Value:           7
139; NORMAL-NEXT:        Content:         '616263'
140; NORMAL-NEXT:      - SectionOffset:   26
141; NORMAL-NEXT:        InitFlags:       0
142; NORMAL-NEXT:        Offset:
143; NORMAL-NEXT:          Opcode:          I32_CONST
144; NORMAL-NEXT:          Value:           12
145; NORMAL-NEXT:        Content:         '01000000'
146; NORMAL-NEXT:      - SectionOffset:   35
147; NORMAL-NEXT:        InitFlags:       0
148; NORMAL-NEXT:        Offset:
149; NORMAL-NEXT:          Opcode:          I32_CONST
150; NORMAL-NEXT:          Value:           16
151; NORMAL-NEXT:        Content:         '02000000'
152; NORMAL-NEXT:      - SectionOffset:   44
153; NORMAL-NEXT:        InitFlags:       0
154; NORMAL-NEXT:        Offset:
155; NORMAL-NEXT:          Opcode:          I32_CONST
156; NORMAL-NEXT:          Value:           20
157; NORMAL-NEXT:        Content:         '03000000'
158; NORMAL-NEXT:      - SectionOffset:   53
159; NORMAL-NEXT:        InitFlags:       0
160; NORMAL-NEXT:        Offset:
161; NORMAL-NEXT:          Opcode:          I32_CONST
162; NORMAL-NEXT:          Value:           24
163; NORMAL-NEXT:        Content:         '00000000'
164; NORMAL-NEXT:  - Type:            CUSTOM
165; NORMAL-NEXT:    Name:            linking
166; NORMAL-NEXT:    Version:         2
167; NORMAL-NEXT:    SymbolTable:
168; NORMAL-NEXT:      - Index:           0
169; NORMAL-NEXT:        Kind:            FUNCTION
170; NORMAL-NEXT:        Name:            hello
171; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
172; NORMAL-NEXT:        Function:        3
173; NORMAL-NEXT:      - Index:           1
174; NORMAL-NEXT:        Kind:            DATA
175; NORMAL-NEXT:        Name:            hello_str
176; NORMAL-NEXT:        Flags:           [  ]
177; NORMAL-NEXT:        Segment:         0
178; NORMAL-NEXT:        Size:            7
179; NORMAL-NEXT:      - Index:           2
180; NORMAL-NEXT:        Kind:            FUNCTION
181; NORMAL-NEXT:        Name:            puts
182; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
183; NORMAL-NEXT:        Function:        0
184; NORMAL-NEXT:      - Index:           3
185; NORMAL-NEXT:        Kind:            FUNCTION
186; NORMAL-NEXT:        Name:            my_func
187; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN, NO_STRIP ]
188; NORMAL-NEXT:        Function:        4
189; NORMAL-NEXT:      - Index:           4
190; NORMAL-NEXT:        Kind:            FUNCTION
191; NORMAL-NEXT:        Name:            foo_import
192; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
193; NORMAL-NEXT:        Function:        1
194; NORMAL-NEXT:      - Index:           5
195; NORMAL-NEXT:        Kind:            FUNCTION
196; NORMAL-NEXT:        Name:            bar_import
197; NORMAL-NEXT:        Flags:           [ BINDING_WEAK, UNDEFINED ]
198; NORMAL-NEXT:        Function:        2
199; NORMAL-NEXT:      - Index:           6
200; NORMAL-NEXT:        Kind:            FUNCTION
201; NORMAL-NEXT:        Name:            func_comdat
202; NORMAL-NEXT:        Flags:           [ BINDING_WEAK ]
203; NORMAL-NEXT:        Function:        5
204; NORMAL-NEXT:      - Index:           7
205; NORMAL-NEXT:        Kind:            DATA
206; NORMAL-NEXT:        Name:            data_comdat
207; NORMAL-NEXT:        Flags:           [ BINDING_WEAK ]
208; NORMAL-NEXT:        Segment:         1
209; NORMAL-NEXT:        Size:            3
210; NORMAL-NEXT:      - Index:           8
211; NORMAL-NEXT:        Kind:            DATA
212; NORMAL-NEXT:        Name:            func_addr1
213; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
214; NORMAL-NEXT:        Segment:         2
215; NORMAL-NEXT:        Size:            4
216; NORMAL-NEXT:      - Index:           9
217; NORMAL-NEXT:        Kind:            DATA
218; NORMAL-NEXT:        Name:            func_addr2
219; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
220; NORMAL-NEXT:        Segment:         3
221; NORMAL-NEXT:        Size:            4
222; NORMAL-NEXT:      - Index:           10
223; NORMAL-NEXT:        Kind:            DATA
224; NORMAL-NEXT:        Name:            func_addr3
225; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
226; NORMAL-NEXT:        Segment:         4
227; NORMAL-NEXT:        Size:            4
228; NORMAL-NEXT:      - Index:           11
229; NORMAL-NEXT:        Kind:            DATA
230; NORMAL-NEXT:        Name:            data_addr1
231; NORMAL-NEXT:        Flags:           [ VISIBILITY_HIDDEN ]
232; NORMAL-NEXT:        Segment:         5
233; NORMAL-NEXT:        Size:            4
234; NORMAL-NEXT:      - Index:           12
235; NORMAL-NEXT:        Kind:            DATA
236; NORMAL-NEXT:        Name:            data_import
237; NORMAL-NEXT:        Flags:           [ UNDEFINED ]
238; NORMAL-NEXT:    SegmentInfo:
239; NORMAL-NEXT:      - Index:           0
240; NORMAL-NEXT:        Name:            .rodata.hello_str
241; NORMAL-NEXT:        Alignment:       0
242; NORMAL-NEXT:        Flags:           [  ]
243; NORMAL-NEXT:      - Index:           1
244; NORMAL-NEXT:        Name:            .rodata.data_comdat
245; NORMAL-NEXT:        Alignment:       0
246; NORMAL-NEXT:        Flags:           [  ]
247; NORMAL-NEXT:      - Index:           2
248; NORMAL-NEXT:        Name:            .data.func_addr1
249; NORMAL-NEXT:        Alignment:       2
250; NORMAL-NEXT:        Flags:           [  ]
251; NORMAL-NEXT:      - Index:           3
252; NORMAL-NEXT:        Name:            .data.func_addr2
253; NORMAL-NEXT:        Alignment:       2
254; NORMAL-NEXT:        Flags:           [  ]
255; NORMAL-NEXT:      - Index:           4
256; NORMAL-NEXT:        Name:            .data.func_addr3
257; NORMAL-NEXT:        Alignment:       2
258; NORMAL-NEXT:        Flags:           [  ]
259; NORMAL-NEXT:      - Index:           5
260; NORMAL-NEXT:        Name:            .data.data_addr1
261; NORMAL-NEXT:        Alignment:       3
262; NORMAL-NEXT:        Flags:           [  ]
263; NORMAL-NEXT:    Comdats:
264; NORMAL-NEXT:      - Name:            func_comdat
265; NORMAL-NEXT:        Entries:
266; NORMAL-NEXT:          - Kind:            FUNCTION
267; NORMAL-NEXT:            Index:           5
268; NORMAL-NEXT:          - Kind:            DATA
269; NORMAL-NEXT:            Index:           1
270; NORMAL-NEXT:  - Type:            CUSTOM
271; NORMAL-NEXT:    Name:            name
272; NORMAL-NEXT:    FunctionNames:
273; NORMAL-NEXT:      - Index:           0
274; NORMAL-NEXT:        Name:            puts
275; NORMAL-NEXT:      - Index:           1
276; NORMAL-NEXT:        Name:            foo_import
277; NORMAL-NEXT:      - Index:           2
278; NORMAL-NEXT:        Name:            bar_import
279; NORMAL-NEXT:      - Index:           3
280; NORMAL-NEXT:        Name:            hello
281; NORMAL-NEXT:      - Index:           4
282; NORMAL-NEXT:        Name:            my_func
283; NORMAL-NEXT:      - Index:           5
284; NORMAL-NEXT:        Name:            func_comdat
285; NORMAL-NEXT:...
286