Skip to content

Commit 52953f3

Browse files
authored
[wat2wasm] Don't crash on unsupported reloc type (#1202)
TypeIndexLEB relocations (used by call_indirect) doesn't seem to be supported.
1 parent 7816cb1 commit 52953f3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/binary-writer.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ Index BinaryWriter::GetSymbolIndex(RelocType reloc_type, Index index) {
317317
name = module_->globals[index]->name;
318318
break;
319319
default:
320-
WABT_UNREACHABLE;
320+
// TODO: Add support for TypeIndexLEB.
321+
fprintf(stderr, "warning: unsupported relocation type: %s\n",
322+
GetRelocTypeName(reloc_type));
323+
return kInvalidIndex;
321324
}
322325
auto iter = symtab_.find(name);
323326
if (iter != symtab_.end()) {

test/regress/regress-35.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
;;; TOOL: wat2wasm
2+
;;; ARGS: -r
3+
(module
4+
;; (type (func (param i32)(param i32)(result i32))) ;; fails, even if present
5+
(func $add (param i32)(param i32)(result i32)
6+
get_local 0
7+
get_local 1
8+
i32.add
9+
return
10+
)
11+
(table 1 anyfunc)
12+
(elem (i32.const 0) $add)
13+
(func $run
14+
i32.const 4444
15+
i32.const 5555
16+
i32.const 0
17+
;;call_indirect (type 0) ;; fails
18+
call_indirect (param i32)(param i32)(result i32) ;; fails
19+
drop
20+
)
21+
(export "run" (func $run))
22+
)
23+
(;; STDERR ;;;
24+
warning: unsupported relocation type: R_WASM_TYPE_INDEX_LEB
25+
;;; STDERR ;;)

0 commit comments

Comments
 (0)