Skip to content

Commit d807f06

Browse files
committed
Use BytecodeUtil in WAVM for precompiled section
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent a103f8f commit d807f06

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/wavm/wavm.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <utility>
2828
#include <vector>
2929

30+
#include "src/common/wasm_util.h"
31+
3032
#include "WAVM/IR/Module.h"
3133
#include "WAVM/IR/Operators.h"
3234
#include "WAVM/IR/Types.h"
@@ -301,19 +303,18 @@ bool Wavm::load(const std::string &code, bool allow_precompiled) {
301303
return false;
302304
}
303305
getAbiVersion(); // Cache ABI version.
304-
const CustomSection *precompiled_object_section = nullptr;
306+
std::string_view precompiled = {};
305307
if (allow_precompiled) {
306-
for (const CustomSection &customSection : ir_module_.customSections) {
307-
if (customSection.name == getPrecompiledSectionName()) {
308-
precompiled_object_section = &customSection;
309-
break;
310-
}
308+
if (!common::BytecodeUtil::getCustomSection(code, getPrecompiledSectionName(), precompiled)) {
309+
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
310+
return false;
311311
}
312312
}
313-
if (!precompiled_object_section) {
313+
if (precompiled.empty()) {
314314
module_ = WAVM::Runtime::compileModule(ir_module_);
315315
} else {
316-
module_ = WAVM::Runtime::loadPrecompiledModule(ir_module_, precompiled_object_section->data);
316+
module_ = WAVM::Runtime::loadPrecompiledModule(
317+
ir_module_, {precompiled.data(), precompiled.data() + precompiled.size()});
317318
}
318319
return true;
319320
}

0 commit comments

Comments
 (0)