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

Commit d1682b3

Browse files
author
jfbastien@apple.com
committedJul 5, 2017
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: 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
1 parent 4857492 commit d1682b3

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
 

‎Source/JavaScriptCore/ChangeLog

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
2017-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+
136
2017-07-04 Joseph Pecoraro <pecoraro@apple.com>
237

338
Cleanup some StringBuilder use

‎Source/JavaScriptCore/wasm/WasmFormat.h

+3
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ struct CustomSection {
236236
};
237237

238238
enum class NameType : uint8_t {
239+
Module = 0,
239240
Function = 1,
240241
Local = 2,
241242
};
@@ -244,6 +245,7 @@ template<typename Int>
244245
inline bool isValidNameType(Int val)
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):
249251
return true;
@@ -252,6 +254,7 @@ inline bool isValidNameType(Int val)
252254
}
253255

254256
struct NameSection {
257+
Name moduleName;
255258
Vector<Name> functionNames;
256259
const Name* get(size_t functionIndexSpace)
257260
{

‎Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,25 @@ auto NameSectionParser::parse() -> Result
4242
uint8_t nameType;
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;
5366
WASM_PARSER_FAIL_IF(!parseVarUInt32(count), "can't get function count for payload ", payloadNumber);

0 commit comments

Comments
 (0)
This repository has been archived.