Title: [219134] trunk/Source/_javascript_Core
Revision
219134
Author
jfbast...@apple.com
Date
2017-07-05 09:51:59 -0700 (Wed, 05 Jul 2017)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (219133 => 219134)


--- trunk/Source/_javascript_Core/ChangeLog	2017-07-05 16:40:55 UTC (rev 219133)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-07-05 16:51:59 UTC (rev 219134)
@@ -1,3 +1,38 @@
+2017-07-05  JF Bastien  <jfbast...@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  <pecor...@apple.com>
 
         Cleanup some StringBuilder use

Modified: trunk/Source/_javascript_Core/wasm/WasmFormat.h (219133 => 219134)


--- trunk/Source/_javascript_Core/wasm/WasmFormat.h	2017-07-05 16:40:55 UTC (rev 219133)
+++ trunk/Source/_javascript_Core/wasm/WasmFormat.h	2017-07-05 16:51:59 UTC (rev 219134)
@@ -236,6 +236,7 @@
 };
 
 enum class NameType : uint8_t {
+    Module = 0,
     Function = 1,
     Local = 2,
 };
@@ -244,6 +245,7 @@
 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;
@@ -252,6 +254,7 @@
 }
     
 struct NameSection {
+    Name moduleName;
     Vector<Name> functionNames;
     const Name* get(size_t functionIndexSpace)
     {

Modified: trunk/Source/_javascript_Core/wasm/WasmNameSectionParser.cpp (219133 => 219134)


--- trunk/Source/_javascript_Core/wasm/WasmNameSectionParser.cpp	2017-07-05 16:40:55 UTC (rev 219133)
+++ trunk/Source/_javascript_Core/wasm/WasmNameSectionParser.cpp	2017-07-05 16:51:59 UTC (rev 219134)
@@ -42,12 +42,25 @@
         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);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to