Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
WebAssembly: implement name section's module name, skip unknown sections
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jfbastien@apple.com committed Jul 5, 2017
1 parent 4857492 commit d1682b3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Source/JavaScriptCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
2017-07-05 JF Bastien <jfbastien@apple.com>

WebAssembly: implement name section's module name, skip unknown sections
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: https://github.com/WebAssembly/design/pull/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: https://github.com/WebAssembly/binaryen/issues/1010

I filed #174098 to use the module name.

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

2017-07-04 Joseph Pecoraro <pecoraro@apple.com>

Cleanup some StringBuilder use
Expand Down
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/wasm/WasmFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ struct CustomSection {
};

enum class NameType : uint8_t {
Module = 0,
Function = 1,
Local = 2,
};
Expand All @@ -244,6 +245,7 @@ template<typename Int>
inline bool isValidNameType(Int val)
{
switch (val) {
case static_cast<Int>(NameType::Module):
case static_cast<Int>(NameType::Function):
case static_cast<Int>(NameType::Local):
return true;
Expand All @@ -252,6 +254,7 @@ inline bool isValidNameType(Int val)
}

struct NameSection {
Name moduleName;
Vector<Name> functionNames;
const Name* get(size_t functionIndexSpace)
{
Expand Down
15 changes: 14 additions & 1 deletion Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,25 @@ auto NameSectionParser::parse() -> Result
uint8_t nameType;
uint32_t payloadLength;
WASM_PARSER_FAIL_IF(!parseUInt7(nameType), "can't get name type for payload ", payloadNumber);
WASM_PARSER_FAIL_IF(!isValidNameType(nameType), "name type ", nameType, " is invalid for payload ", payloadNumber);
WASM_PARSER_FAIL_IF(!parseVarUInt32(payloadLength), "can't get payload length for payload ", payloadNumber);
WASM_PARSER_FAIL_IF(payloadLength > length() - m_offset, "payload length is too big for payload ", payloadNumber);
const auto payloadStart = m_offset;

if (!isValidNameType(nameType)) {
// Unknown name section entries are simply ignored. This allows us to support newer toolchains without breaking older features.
m_offset += payloadLength;
continue;
}

switch (static_cast<NameType>(nameType)) {
case NameType::Module: {
uint32_t nameLen;
Name nameString;
WASM_PARSER_FAIL_IF(!parseVarUInt32(nameLen), "can't get module's name length for payload ", payloadNumber);
WASM_PARSER_FAIL_IF(!consumeUTF8String(nameString, nameLen), "can't get module's name of length ", nameLen, " for payload ", payloadNumber);
nameSection.moduleName = WTFMove(nameString);
break;
}
case NameType::Function: {
uint32_t count;
WASM_PARSER_FAIL_IF(!parseVarUInt32(count), "can't get function count for payload ", payloadNumber);
Expand Down

0 comments on commit d1682b3

Please sign in to comment.