diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index ce1a18be6bc66..0277f36097c87 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,38 @@ +2017-07-05 JF Bastien + + 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 Cleanup some StringBuilder use diff --git a/Source/JavaScriptCore/wasm/WasmFormat.h b/Source/JavaScriptCore/wasm/WasmFormat.h index 618a378e9dc66..cc659711bf53e 100644 --- a/Source/JavaScriptCore/wasm/WasmFormat.h +++ b/Source/JavaScriptCore/wasm/WasmFormat.h @@ -236,6 +236,7 @@ struct CustomSection { }; enum class NameType : uint8_t { + Module = 0, Function = 1, Local = 2, }; @@ -244,6 +245,7 @@ template inline bool isValidNameType(Int val) { switch (val) { + case static_cast(NameType::Module): case static_cast(NameType::Function): case static_cast(NameType::Local): return true; @@ -252,6 +254,7 @@ inline bool isValidNameType(Int val) } struct NameSection { + Name moduleName; Vector functionNames; const Name* get(size_t functionIndexSpace) { diff --git a/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp b/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp index 8c04f58810432..a58289f2f0312 100644 --- a/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp +++ b/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp @@ -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)) { + 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);