diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast_utils.h | 12 | ||||
-rw-r--r-- | src/js/wasm.js-post.js | 4 | ||||
-rw-r--r-- | src/wasm-binary.h | 2 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 19 |
4 files changed, 26 insertions, 11 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index 2565ee24a..159762d0b 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -296,7 +296,7 @@ struct ExpressionManipulator { return ret; } Expression* visitCallIndirect(CallIndirect *curr) { - auto* ret = builder.makeCallIndirect(curr->fullType, curr->target, {}, curr->type); + auto* ret = builder.makeCallIndirect(curr->fullType, copy(curr->target), {}, curr->type); for (Index i = 0; i < curr->operands.size(); i++) { ret->operands.push_back(copy(curr->operands[i])); } @@ -714,6 +714,16 @@ struct ExpressionAnalyzer { continue; } hash(curr->_id); + // we often don't need to hash the type, as it is tied to other values + // we are hashing anyhow, but there are exceptions: for example, a + // get_local's type is determined by the function, so if we are + // hashing only expression fragments, then two from different + // functions may turn out the same even if the type differs. Likewise, + // if we hash between modules, then we need to take int account + // call_imports type, etc. The simplest thing is just to hash the + // type for all of them. + hash(curr->type); + #define PUSH(clazz, what) \ stack.push_back(curr->cast<clazz>()->what); #define HASH(clazz, what) \ diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index 02c99994e..e7a10f49a 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -104,7 +104,7 @@ function integrateWasmJS(Module) { // If we have a mem init file, do not trample it if (!memoryInitializer) { - oldView.set(newView.subarray(STATIC_BASE, STATIC_BASE + STATIC_BUMP), STATIC_BASE); + oldView.set(newView.subarray(Module['STATIC_BASE'], Module['STATIC_BASE'] + Module['STATIC_BUMP']), Module['STATIC_BASE']); } newView.set(oldView); @@ -312,7 +312,7 @@ function integrateWasmJS(Module) { } if (!env['memoryBase']) { - env['memoryBase'] = STATIC_BASE; // tell the memory segments where to place themselves + env['memoryBase'] = Module['STATIC_BASE']; // tell the memory segments where to place themselves } if (!env['tableBase']) { env['tableBase'] = 0; // table starts at 0 by default, in dynamic linking this will change diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 6ec55f757..1edd3fa12 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -638,7 +638,7 @@ public: WasmBinaryBuilder(Module& wasm, std::vector<char>& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {} void read(); - bool readUserSection(); + void readUserSection(); bool more() { return pos < input.size();} uint8_t getInt8(); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ab26aa3ac..ebbc5a8ee 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -890,6 +890,8 @@ void WasmBinaryBuilder::read() { uint32_t payloadLen = getU32LEB(); if (pos + payloadLen > input.size()) throw ParseException("Section extends beyond end of input"); + auto oldPos = pos; + switch (sectionCode) { case BinaryConsts::Section::Start: readStart(); break; case BinaryConsts::Section::Memory: readMemory(); break; @@ -909,23 +911,26 @@ void WasmBinaryBuilder::read() { } case BinaryConsts::Section::Data: readDataSegments(); break; case BinaryConsts::Section::Table: readFunctionTableDeclaration(); break; - - default: - if (!readUserSection()) abort(); + default: { + readUserSection(); + pos = oldPos + payloadLen; + } } + + // make sure we advanced exactly past this section + assert(pos == oldPos + payloadLen); } processFunctions(); } -bool WasmBinaryBuilder::readUserSection() { +void WasmBinaryBuilder::readUserSection() { Name sectionName = getInlineString(); if (sectionName.equals(BinaryConsts::UserSections::Name)) { readNames(); - return true; + } else { + std::cerr << "unfamiliar section: " << sectionName << std::endl; } - std::cerr << "unfamiliar section: " << sectionName << std::endl; - return false; } uint8_t WasmBinaryBuilder::getInt8() { |