Skip to content

Add --emit-module-names to wasm-opt#8860

Merged
kripken merged 10 commits into
WebAssembly:mainfrom
mkustermann:module-name
Jun 25, 2026
Merged

Add --emit-module-names to wasm-opt#8860
kripken merged 10 commits into
WebAssembly:mainfrom
mkustermann:module-name

Conversation

@mkustermann

@mkustermann mkustermann commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The wasm-split command has this --emit-module-names flag already and this adds it to wasm-opt as well.

Wasm runtimes may not know the URL where a wasm file came from, it may only be given the bytes.
If so, then e.g. V8 prints a wasm-runtime-specific hash of the wasm bytes in stack traces. If a stack trace has
frames of different wasm modules, these hashes do not allow mapping the frames back to the original wasm files.

If we have the ability to keep module names, then it would print the module name (**) (instead of the hash) --
which would allow a stack trace decoding tool to tie the module name back to the right wasm module of an app.

(**) It prefers the wasm file url. If that isn't available it falls back to module name. If that isn't available it falls back to hash of wasm bytes.

See also https://issues.chromium.org/issues/42201791

@mkustermann mkustermann requested a review from a team as a code owner June 18, 2026 09:16
@mkustermann mkustermann requested review from kripken and removed request for a team June 18, 2026 09:16
The `wasm-split` command has this `--emit-module-names` flag already and
this adds it to `wasm-opt` as well.

Wasm runtimes may not know the URL where a wasm file came from, it may
only be given the bytes. Currently e.g. V8 prints a V8 specific hash of
the wasm file in stack traces.

If we have the ability to keep module names, then it would print the
module name (fallback if the url is not available) -- which would allow
a stack trace decoding tool to tie the module name back to the right
wasm module of an app.
@kripken

kripken commented Jun 18, 2026

Copy link
Copy Markdown
Member
  1. I see the wasm-split code for this says it is temporary:
      "Emit module names, even if not emitting the rest of the names section. "
      "Can help differentiate the modules in stack traces. This option will be "
      "removed once simpler ways of naming modules are widely available. See "
      "https://bugs.chromium.org/p/v8/issues/detail?id=11808.",
    
    Is that still the case @tlively @aheejin ?
  2. If we do want this option more generally, perhaps we should add it to ToolOptions (so all tools have it)?

@tlively

tlively commented Jun 18, 2026

Copy link
Copy Markdown
Member

It's not clear to me that the fix for that chromium issue constitutes a "simpler way of naming modules," so I'd be happy to have this flag added to ToolOptions.

@mkustermann

Copy link
Copy Markdown
Contributor Author

It's not clear to me that the fix for that chromium issue constitutes a "simpler way of naming modules," so I'd be happy to have this flag added to ToolOptions.

Precisely. The V8 bug was closed by making V8 stack frames contain a hash of the module bytes via an V8-internal hash function -- outside tooling that gets a stack trace with those hash codes cannot do anything with them (it's not a wasm spec'ed hash code function)

@mkustermann

Copy link
Copy Markdown
Contributor Author

I've moved the option to ToolOptions now

Comment thread src/tools/wasm-opt.cpp Outdated
Comment thread src/wasm-io.h
void setSourceMapUrl(std::string sourceMapUrl_) {
sourceMapUrl = sourceMapUrl_;
}
void setEmitModuleName(bool set) { emitModuleName = set; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we prefer functions like this over booleans passed to constructors - the boolean is less explicit about what it is.

I get the idea that making it non-optional is safer, but it is less clear when reading the code, and tests can check that we do actually use this properly. So I think it would be better to keep setEmitModuleName and use that from the tools. Though I hope we can wrap around wasm-io in the tools so they all use a shared path? Perhaps adding a helper function to ToolOptions "write" which does all the writing, applying this flag as needed?

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kripken kripken merged commit 9926156 into WebAssembly:main Jun 25, 2026
16 checks passed
@mkustermann

Copy link
Copy Markdown
Contributor Author

Thanks for merging, @kripken !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants