Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a module name to the name section #1055

Merged
merged 2 commits into from
May 11, 2017
Merged

Add a module name to the name section #1055

merged 2 commits into from
May 11, 2017

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented May 5, 2017

This will make distinguishing modules (e.g. in a stack trace containing dynamically-linked modules) much easier; especially when using the ArrayBuffer API.

@jfbastien
Copy link
Member

Do we expect people to have name sections with just a module name and nothing else (no functions or locals)?

@RyanLamansky
Copy link

@jfbastien Seems unlikely to me, but allowing it only costs a byte and is backward compatible 🙂

@jfbastien
Copy link
Member

@RyanLamansky not quite: I've heard that folks may want to take the presence of a name section as indication that debugging is intended, and lower performance is acceptable. If we expect the section to sometimes just contain a module name even in release then the approach is invalid.

I don't want to judge which usecase / heuristic is valid for now, I just want to understand if we expect their interaction to matter at all.

@dschuff
Copy link
Member Author

dschuff commented May 8, 2017

I had thought that I'd probably just have emscripten always include a module name even in release mode, since that would cost very little and would ensure that the VM would always have at least a potentially-meaningful thing to print e.g. in stack traces (otherwise for the ArrayBuffer APIs there might not be anything other than the instantiation site). But that's a good point about debugging intent. I guess you could make the heuristic more complicated by checking for the existence of function or local names, but that's starting to get slightly ugly; and then when we add source maps and other external debug info which maybe used on demand, it makes even less sense.

@jfbastien
Copy link
Member

Yeah I like the idea of having the module name, I'm just not sure it should be in the name section... Which is sad in itself! Maybe @lukewagner has some wisdom on this topic?

@lukewagner
Copy link
Member

Nice connection @jfbastien! Technically, the predicate we use for "should we preserve the bytecode in instances?" is !metadata->funcNames.empty() so we're actually doing what @dschuff is proposing already ;)

So overall, I think this is a good idea.

@@ -451,6 +451,8 @@ be skipped over by an engine. The current list of valid `name_type` codes are:
| --------- | ---- | ----------- |
| [Function](#function-names) | `1` | Assigns names to functions |
| [Local](#local-names) | `2` | Assigns names to locals in functions |
| [Module](#module-name) | `3` | Assigns a name to the module |
Copy link
Member

Choose a reason for hiding this comment

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

Could we make the code be 0 so that it looks like we meant to do this all along ;) ?

@dschuff
Copy link
Member Author

dschuff commented May 10, 2017

Made the name type code be 0 (of course we always intended it to be this way...)

@jfbastien wrt debugging intention and weirdness, I'm ambivalent: on one hand having things be explicit is probably better than implicit (e.g. a. complex opaque heuristic to decide when the browser things you're going to debug). But OTOH it's not that bad I hope that before long we'll have more debug info than just the names section, at which point we won't need to rely on it, and the platform/spec won't have weird warts that were important at some time in the past.

Copy link
Member

@jfbastien jfbastien left a comment

Choose a reason for hiding this comment

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

lgtm

@dschuff dschuff merged commit dfc0d51 into master May 11, 2017
hubot pushed a commit to WebKit/WebKit-http that referenced this pull request Jul 5, 2017
https://bugs.webkit.org/show_bug.cgi?id=172008

Reviewed by Keith Miller.

Parse the WebAssembly module name properly, and skip unknown
sections. This is useful because as toolchains support new types
of names we want to keep displaying the information we know about
and simply ignore new information. That capability was designed
into WebAssembly's name section.

Failure to commit this patch would mean that WebKit won't display
stack trace information, which would make developers sad.

Module names were added here: WebAssembly/design#1055

Note that this patch doesn't do anything with the parsed name! Two
reasons for this: module names aren't supported in binaryen yet,
so I can't write a simple binary test; and using the name is a
slightly riskier change because it requires changing StackVisitor
+ StackFrame (where they print "[wasm code]") which requires
figuring out the frame's Module. The latter bit isn't trivial
because we only know wasm frames from their tag bits, and
CodeBlocks are always nullptr.

Binaryen bug: WebAssembly/binaryen#1010

I filed #174098 to use the module name.

* wasm/WasmFormat.h:
(JSC::Wasm::isValidNameType):
* wasm/WasmNameSectionParser.cpp:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@219134 268f45cc-cd09-0410-ab3c-d52691b4dbfc
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.

4 participants