1# RUN: split-file %s %t 2# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/main.s -o %t/main.o 3# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %t/secondary.s -o %t/secondary.o 4 5## Check that both main.o and secondary.o contain references to the same 6## undefined function and that both are correctly reported. 7# RUN: not wasm-ld --no-gc-sections %t/main.o %t/secondary.o -o /dev/null 2>&1 | \ 8# RUN: FileCheck -check-prefix=ERRUND %s 9# ERRUND: error: {{.*}}main.o: undefined symbol: undef_func 10# ERRUND: error: {{.*}}secondary.o: undefined symbol: undef_func 11 12## report-all is the default one. Check that we get the same error 13# RUN: not wasm-ld --no-gc-sections %t/main.o %t/secondary.o -o /dev/null --unresolved-symbols=report-all 2>&1 | \ 14# RUN: FileCheck -check-prefix=ERRUND %s 15 16## Error out if unknown option value was set. 17# RUN: not wasm-ld %t/main.o -o /dev/null --unresolved-symbols=xxx 2>&1 | \ 18# RUN: FileCheck -check-prefix=ERR1 %s 19# ERR1: unknown --unresolved-symbols value: xxx 20## Check alias. 21# RUN: not wasm-ld %t/main.o -o /dev/null --unresolved-symbols xxx 2>&1 | \ 22# RUN: FileCheck -check-prefix=ERR1 %s 23 24## Ignore all should not produce error and should not produce 25## any imports. It should create a stub function in the place of the missing 26## function symbol. 27# RUN: wasm-ld %t/main.o -o %t2.wasm --unresolved-symbols=ignore-all 28# RUN: obj2yaml %t2.wasm | FileCheck -check-prefix=IGNORE %s 29 30## --warn-unresolved-symbols should behave the same 31# RUN: wasm-ld %t/main.o -o %t2.wasm --warn-unresolved-symbols 32# RUN: obj2yaml %t2.wasm | FileCheck -check-prefix=IGNORE %s 33 34# IGNORE-NOT: - Type: IMPORT 35# IGNORE-NOT: - Type: ELEM 36# 37# IGNORE: - Type: CODE 38# IGNORE-NEXT: Functions: 39# IGNORE-NEXT: - Index: 0 40# IGNORE-NEXT: Locals: [] 41# IGNORE-NEXT: Body: 000B 42# IGNORE-NEXT: - Index: 1 43# IGNORE-NEXT: Locals: [] 44# IGNORE-NEXT: Body: 1080808080001082808080001083808080001A1A0B 45# IGNORE-NEXT: - Index: 2 46# IGNORE-NEXT: Locals: [] 47# IGNORE-NEXT: Body: 4180808080000F0B 48# IGNORE-NEXT: - Index: 3 49# IGNORE-NEXT: Locals: [] 50# IGNORE-NEXT: Body: 4180808080000F0B 51# 52# IGNORE: - Type: CUSTOM 53# IGNORE-NEXT: Name: name 54# IGNORE-NEXT: FunctionNames: 55# IGNORE-NEXT: - Index: 0 56# IGNORE-NEXT: Name: undefined 57# IGNORE-NEXT: - Index: 1 58# IGNORE-NEXT: Name: _start 59# IGNORE-NEXT: - Index: 2 60# IGNORE-NEXT: Name: get_data_addr 61# IGNORE-NEXT: - Index: 3 62# IGNORE-NEXT: Name: get_func_addr 63 64## --import-undefined should handle unresolved functions symbols 65## by importing them but still report errors/warning for missing data symbols. 66## `--allow-undefined` should behave like `--import-undefined` + 67## `--unresolve-symbols=ignore` 68# RUN: wasm-ld %t/main.o -o %t3.wasm --import-undefined --unresolved-symbols=ignore-all 69# RUN: obj2yaml %t3.wasm | FileCheck -check-prefix=IMPORT %s 70# IMPORT: - Type: IMPORT 71# IMPORT-NEXT: Imports: 72# IMPORT-NEXT: - Module: env 73# IMPORT-NEXT: Field: undef_func 74# IMPORT-NEXT: Kind: FUNCTION 75# IMPORT-NEXT: SigIndex: 0 76# IMPORT-NEXT: - Type: FUNCTION 77 78## Check that --import-undefined reports unresolved data symbols. 79# RUN: not wasm-ld %t/main.o -o %t3.wasm --import-undefined --unresolved-symbols=report-all 2>&1 | FileCheck -check-prefix=IMPORTUNDEFINED %s 80# IMPORTUNDEFINED-NOT: error: {{.*}}main.o: undefined symbol: undef_func 81# IMPORTUNDEFINED: error: {{.*}}main.o: undefined symbol: undef_data 82 83## Do not report undefines if linking relocatable. 84# RUN: wasm-ld -r %t/main.o -o %t4.wasm --unresolved-symbols=report-all 85# RUN: llvm-readobj %t4.wasm > /dev/null 2>&1 86 87## import-dynamic should fail due to incompatible relocations. 88# RUN: not wasm-ld %t/main.o -o %t5.wasm --experimental-pic --unresolved-symbols=import-dynamic 2>&1 | FileCheck -check-prefix=ERRNOPIC %s 89# ERRNOPIC: relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `undef_data`; recompile with -fPIC 90# ERRNOPIC: relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `undef_func`; recompile with -fPIC 91 92#--- main.s 93 94.functype undef_func () -> () 95.functype get_data_addr () -> (i32) 96.functype get_func_addr () -> (i32) 97 98.globl _start 99_start: 100 .functype _start () -> () 101 call undef_func 102 call get_data_addr 103 call get_func_addr 104 drop 105 drop 106 end_function 107 108.globl get_data_addr 109get_data_addr: 110 .functype get_data_addr () -> (i32) 111 i32.const undef_data 112 return 113 end_function 114 115.globl get_func_addr 116get_func_addr: 117 .functype get_func_addr () -> (i32) 118 i32.const undef_func 119 return 120 end_function 121 122#--- secondary.s 123 124.functype undef_func () -> () 125.globl foo 126foo: 127 .functype foo () -> () 128 call undef_func 129 end_function 130