1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t1.o
2
3## Check that %t1.o contains undefined symbol undef_func.
4# RUN: not wasm-ld %t1.o -o /dev/null 2>&1 | \
5# RUN:   FileCheck -check-prefix=ERRUND %s
6# ERRUND: error: {{.*}}1.o: undefined symbol: undef_func
7
8## report-all is the default one. Check that we get the same error
9# RUN: not wasm-ld %t1.o -o /dev/null --unresolved-symbols=report-all 2>&1 | \
10# RUN:   FileCheck -check-prefix=ERRUND %s
11
12## Error out if unknown option value was set.
13# RUN: not wasm-ld %t1.o -o /dev/null --unresolved-symbols=xxx 2>&1 | \
14# RUN:   FileCheck -check-prefix=ERR1 %s
15# ERR1: unknown --unresolved-symbols value: xxx
16## Check alias.
17# RUN: not wasm-ld %t1.o -o /dev/null --unresolved-symbols xxx 2>&1 | \
18# RUN:   FileCheck -check-prefix=ERR1 %s
19
20## Ignore all should not produce error and should not produce
21# any imports.  It should create a stub function in the place of the missing
22# function symbol.
23# RUN: wasm-ld %t1.o -o %t2.wasm --unresolved-symbols=ignore-all
24# RUN: obj2yaml %t2.wasm | FileCheck -check-prefix=IGNORE %s
25# IGNORE-NOT: - Type:            IMPORT
26# IGNORE-NOT: - Type:            ELEM
27#
28#      IGNORE:  - Type:            CODE
29# IGNORE-NEXT:    Functions:
30# IGNORE-NEXT:      - Index:           0
31# IGNORE-NEXT:        Locals:          []
32# IGNORE-NEXT:        Body:            000B
33# IGNORE-NEXT:      - Index:           1
34# IGNORE-NEXT:        Locals:          []
35# IGNORE-NEXT:        Body:            1080808080001082808080001083808080001A1A0B
36# IGNORE-NEXT:      - Index:           2
37# IGNORE-NEXT:        Locals:          []
38# IGNORE-NEXT:        Body:            4180808080000F0B
39# IGNORE-NEXT:      - Index:           3
40# IGNORE-NEXT:        Locals:          []
41# IGNORE-NEXT:        Body:            4180808080000F0B
42#
43#      IGNORE:  - Type:            CUSTOM
44# IGNORE-NEXT:    Name:            name
45# IGNORE-NEXT:    FunctionNames:
46# IGNORE-NEXT:      - Index:           0
47# IGNORE-NEXT:        Name:            undefined
48# IGNORE-NEXT:      - Index:           1
49# IGNORE-NEXT:        Name:            _start
50# IGNORE-NEXT:      - Index:           2
51# IGNORE-NEXT:        Name:            get_data_addr
52# IGNORE-NEXT:      - Index:           3
53# IGNORE-NEXT:        Name:            get_func_addr
54
55## --import-undefined should handle unresolved funtions symbols
56# by importing them but still report errors/warning for missing data symbols.
57# `--allow-undefined` should behave like `--import-undefined` +
58# `--unresolve-symbols=ignore`
59# RUN: wasm-ld %t1.o -o %t3.wasm --import-undefined --unresolved-symbols=ignore-all
60# RUN: obj2yaml %t3.wasm | FileCheck -check-prefix=IMPORT %s
61#      IMPORT:  - Type:            IMPORT
62# IMPORT-NEXT:    Imports:
63# IMPORT-NEXT:      - Module:          env
64# IMPORT-NEXT:        Field:           undef_func
65# IMPORT-NEXT:        Kind:            FUNCTION
66# IMPORT-NEXT:        SigIndex:        0
67# IMPORT-NEXT:  - Type:            FUNCTION
68
69## Check that --import-undefined reports unresolved data symbols.
70# RUN: not wasm-ld %t1.o -o %t3.wasm --import-undefined --unresolved-symbols=report-all 2>&1 | FileCheck -check-prefix=IMPORTUNDEFINED %s
71# IMPORTUNDEFINED-NOT: error: {{.*}}1.o: undefined symbol: undef_func
72# IMPORTUNDEFINED: error: {{.*}}1.o: undefined symbol: undef_data
73
74## Do not report undefines if linking relocatable.
75# RUN: wasm-ld -r %t1.o -o %t4.wasm --unresolved-symbols=report-all
76# RUN: llvm-readobj %t4.wasm > /dev/null 2>&1
77
78.functype undef_func () -> ()
79.functype get_data_addr () -> (i32)
80.functype get_func_addr () -> (i32)
81
82.globl _start
83_start:
84    .functype _start () -> ()
85    call undef_func
86    call get_data_addr
87    call get_func_addr
88    drop
89    drop
90    end_function
91
92.globl get_data_addr
93get_data_addr:
94    .functype get_data_addr () -> (i32)
95    i32.const undef_data
96    return
97    end_function
98
99.globl get_func_addr
100get_func_addr:
101    .functype get_func_addr () -> (i32)
102    i32.const undef_func
103    return
104    end_function
105