Skip to content
Snippets Groups Projects
Commit d333cd74 authored by Cheng Shao's avatar Cheng Shao :beach:
Browse files

wasm: do not use wasm type reflection in dyld

The wasm dynamic linker used to depend on v8's experimental wasm type
reflection support to generate stub functions when treating GOT.func
items that aren't exported by any loaded library yet. However, as we
work towards wasm ghci browser mode (#25399), we need to ensure the
wasm dyld logic is portable across browsers. So this commit removes
the usage of wasm type reflection in wasm dyld, and it shall only be
added many months later when this feature is widely available in
browsers.

(cherry picked from commit cca68421)
(cherry picked from commit a398fae2)
parent a5e5b1bf
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env -S node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --max-old-space-size=65536 --no-turbo-fast-api-calls --wasm-lazy-validation #!/usr/bin/env -S node --disable-warning=ExperimentalWarning --max-old-space-size=65536 --no-turbo-fast-api-calls --wasm-lazy-validation
// Note [The Wasm Dynamic Linker] // Note [The Wasm Dynamic Linker]
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -691,30 +691,15 @@ class DyLD { ...@@ -691,30 +691,15 @@ class DyLD {
continue; continue;
} }
// For lazy GOT.func entries we can do better than poison: // Can't find this function, so poison it like GOT.mem.
// insert a stub in the table, so we at least get an error // TODO: when wasm type reflection is widely available in
// message that includes the missing function's name, not a // browsers, use the WebAssembly.Function constructor to
// mysterious table trap. The function type is Cmm function // dynamically create a stub function that does better error
// type as a best effort guess, if there's a type mismatch // reporting
// then call_indirect would trap.
//
// Also set a __poison field since we can't compare value
// against DyLD.#poison.
this.#gotFunc[name] = new WebAssembly.Global( this.#gotFunc[name] = new WebAssembly.Global(
{ value: "i32", mutable: true }, { value: "i32", mutable: true },
this.#table.grow( DyLD.#poison
1,
new WebAssembly.Function(
{ parameters: [], results: ["i32"] },
() => {
throw new WebAssembly.RuntimeError(
`non-existent function ${name}`
);
}
)
)
); );
this.#gotFunc[name].__poison = true;
continue; continue;
} }
...@@ -752,8 +737,7 @@ class DyLD { ...@@ -752,8 +737,7 @@ class DyLD {
if (this.#gotFunc[k]) { if (this.#gotFunc[k]) {
// ghc-prim/ghc-internal may export functions imported by // ghc-prim/ghc-internal may export functions imported by
// rts // rts
assert(this.#gotFunc[k].__poison); assert(this.#gotFunc[k].value === DyLD.#poison);
delete this.#gotFunc[k].__poison;
this.#table.set(this.#gotFunc[k].value, v); this.#table.set(this.#gotFunc[k].value, v);
} }
continue; continue;
...@@ -828,7 +812,7 @@ class DyLD { ...@@ -828,7 +812,7 @@ class DyLD {
if (this.#gotMem[sym] && this.#gotMem[sym].value !== DyLD.#poison) { if (this.#gotMem[sym] && this.#gotMem[sym].value !== DyLD.#poison) {
return this.#gotMem[sym].value; return this.#gotMem[sym].value;
} }
if (this.#gotFunc[sym] && !this.#gotFunc[sym].__poison) { if (this.#gotFunc[sym] && this.#gotFunc[sym].value !== DyLD.#poison) {
return this.#gotFunc[sym].value; return this.#gotFunc[sym].value;
} }
// Not in GOT.func yet, create the entry on demand // Not in GOT.func yet, create the entry on demand
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment