Issue |
136594
|
Summary |
Impossible to use `wasm:js-string` functions in webassembly
|
Labels |
new issue
|
Assignees |
|
Reporter |
socketpair
|
Here you can see an example of WASM code how to use `concat` JS builtin:
https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/_javascript__builtins#wasm_module
```wat
(func $concat (import "wasm:js-string" "concat")
(param externref externref) (result (ref extern)))
```
So, in C I defined it in the following way:
```C
__externref_t js_concat(__externref_t, __externref_t)
__attribute__((import_module("wasm:js-string"), import_name("concat")));
```
Next, I'm trying to run the code that uses definition above in the following way:
```js
const { instance } = await WebAssembly.instantiateStreaming(
fetch('trie_search.wasm'),
{
env: { },
},
{
builtins: ["js-string"],
importedStringConstants: "Something",
},
);
instance.exports.my_function();
```
Browser console says:
```
Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming():
Imported builtin function "wasm:js-string" "concat" has incorrect signature
```
I guess, the problem in return value. in WAT language it should look like `(ref extern)`. How to express it in C (Clang)?
https://github.com/WebAssembly/js-string-builtins/blob/main/proposals/js-string-builtins/Overview.md#wasmjs-string-concat
https://github.com/WebAssembly/function-references/blob/master/proposals/function-references/Overview.md#binary-format
```wat
(module
(global $h (import "string_constants" "hello ") externref)
(global $w (import "string_constants" "world!") externref)
(func $concat (import "wasm:js-string" "concat")
(param externref externref) (result (ref extern)))
(func $log (import "m" "log") (param externref))
(func (export "main")
(call $log (call $concat (global.get $h) (global.get $w))))
)
```
Compiles perfectly well using `binryen`, but how to write an equivalent using C and clang ?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs