Changeset 219134 in webkit


Ignore:
Timestamp:
Jul 5, 2017 9:51:59 AM (7 years ago)
Author:
jfbastien@apple.com
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:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r219115 r219134  
     12017-07-05  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: implement name section's module name, skip unknown sections
     4        https://bugs.webkit.org/show_bug.cgi?id=172008
     5
     6        Reviewed by Keith Miller.
     7
     8        Parse the WebAssembly module name properly, and skip unknown
     9        sections. This is useful because as toolchains support new types
     10        of names we want to keep displaying the information we know about
     11        and simply ignore new information. That capability was designed
     12        into WebAssembly's name section.
     13
     14        Failure to commit this patch would mean that WebKit won't display
     15        stack trace information, which would make developers sad.
     16
     17        Module names were added here: https://github.com/WebAssembly/design/pull/1055
     18
     19        Note that this patch doesn't do anything with the parsed name! Two
     20        reasons for this: module names aren't supported in binaryen yet,
     21        so I can't write a simple binary test; and using the name is a
     22        slightly riskier change because it requires changing StackVisitor
     23        + StackFrame (where they print "[wasm code]") which requires
     24        figuring out the frame's Module. The latter bit isn't trivial
     25        because we only know wasm frames from their tag bits, and
     26        CodeBlocks are always nullptr.
     27
     28        Binaryen bug: https://github.com/WebAssembly/binaryen/issues/1010
     29
     30        I filed #174098 to use the module name.
     31
     32        * wasm/WasmFormat.h:
     33        (JSC::Wasm::isValidNameType):
     34        * wasm/WasmNameSectionParser.cpp:
     35
    1362017-07-04  Joseph Pecoraro  <pecoraro@apple.com>
    237
  • trunk/Source/JavaScriptCore/wasm/WasmFormat.h

    r217942 r219134  
    237237
    238238enum class NameType : uint8_t {
     239    Module = 0,
    239240    Function = 1,
    240241    Local = 2,
     
    245246{
    246247    switch (val) {
     248    case static_cast<Int>(NameType::Module):
    247249    case static_cast<Int>(NameType::Function):
    248250    case static_cast<Int>(NameType::Local):
     
    253255   
    254256struct NameSection {
     257    Name moduleName;
    255258    Vector<Name> functionNames;
    256259    const Name* get(size_t functionIndexSpace)
  • trunk/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp

    r216597 r219134  
    4343        uint32_t payloadLength;
    4444        WASM_PARSER_FAIL_IF(!parseUInt7(nameType), "can't get name type for payload ", payloadNumber);
    45         WASM_PARSER_FAIL_IF(!isValidNameType(nameType), "name type ", nameType, " is invalid for payload ", payloadNumber);
    4645        WASM_PARSER_FAIL_IF(!parseVarUInt32(payloadLength), "can't get payload length for payload ", payloadNumber);
    4746        WASM_PARSER_FAIL_IF(payloadLength > length() - m_offset, "payload length is too big for payload ", payloadNumber);
    4847        const auto payloadStart = m_offset;
     48       
     49        if (!isValidNameType(nameType)) {
     50            // Unknown name section entries are simply ignored. This allows us to support newer toolchains without breaking older features.
     51            m_offset += payloadLength;
     52            continue;
     53        }
    4954
    5055        switch (static_cast<NameType>(nameType)) {
     56        case NameType::Module: {
     57            uint32_t nameLen;
     58            Name nameString;
     59            WASM_PARSER_FAIL_IF(!parseVarUInt32(nameLen), "can't get module's name length for payload ", payloadNumber);
     60            WASM_PARSER_FAIL_IF(!consumeUTF8String(nameString, nameLen), "can't get module's name of length ", nameLen, " for payload ", payloadNumber);
     61            nameSection.moduleName = WTFMove(nameString);
     62            break;
     63        }
    5164        case NameType::Function: {
    5265            uint32_t count;
Note: See TracChangeset for help on using the changeset viewer.