Skip to content

Commit 0699c05

Browse files
authored
bump wamr to 2.1.1 and able to consume precompiled content (#380)
- skip leading paddings in .aot section Signed-off-by: [email protected] <[email protected]>
1 parent 7c975bb commit 0699c05

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

bazel/external/wamr.BUILD

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ filegroup(
1212
cmake(
1313
name = "wamr_lib",
1414
generate_args = [
15+
# disable WASI
1516
"-DWAMR_BUILD_LIBC_WASI=0",
16-
"-DWAMR_BUILD_MULTI_MODULE=0",
17+
"-DWAMR_BUILD_LIBC_BUILTIN=0",
18+
# MVP
19+
"-DWAMR_BUILD_BULK_MEMORY=1",
20+
"-DWAMR_BUILD_REF_TYPES=1",
1721
"-DWAMR_BUILD_TAIL_CALL=1",
18-
"-DWAMR_DISABLE_HW_BOUND_CHECK=0",
19-
"-DWAMR_DISABLE_STACK_HW_BOUND_CHECK=1",
22+
# WAMR private features
23+
"-DWAMR_BUILD_MULTI_MODULE=0",
24+
# Some tests have indicated that the following three factors have
25+
# a minimal impact on performance.
26+
# - Get function names from name section
27+
"-DWAMR_BUILD_CUSTOM_NAME_SECTION=1",
28+
"-DWAMR_BUILD_LOAD_CUSTOM_SECTION=1",
29+
# - Show Wasm call stack if met a trap
30+
"-DWAMR_BUILD_DUMP_CALL_STACK=1",
31+
# Cache module files
32+
"-DWAMR_BUILD_WASM_CACHE=0",
2033
"-GNinja",
2134
] + select({
2235
"@proxy_wasm_cpp_host//bazel:engine_wamr_jit": [
@@ -26,6 +39,8 @@ cmake(
2639
"-DWAMR_BUILD_INTERP=0",
2740
"-DWAMR_BUILD_JIT=1",
2841
"-DWAMR_BUILD_SIMD=1",
42+
# linux perf. only for jit and aot
43+
# "-DWAMR_BUILD_LINUX_PERF=1",
2944
],
3045
"//conditions:default": [
3146
"-DWAMR_BUILD_AOT=0",

bazel/repositories.bzl

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ def proxy_wasm_cpp_host_repositories():
198198
http_archive,
199199
name = "com_github_bytecodealliance_wasm_micro_runtime",
200200
build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD",
201-
# WAMR-1.2.1
202-
sha256 = "7548d4bbea8dbb9b005e83bd571f93a12fb3f0b5e87a8b0130f004dd92df4b0b",
203-
strip_prefix = "wasm-micro-runtime-WAMR-1.2.1",
204-
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-1.2.1.zip",
201+
# WAMR-2.1.1
202+
sha256 = "a0824762abbcbb3dd6b7bb07530f198ece5d792a12a879bc2a99100590fdb151",
203+
strip_prefix = "wasm-micro-runtime-WAMR-2.1.1",
204+
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-2.1.1.zip",
205205
)
206206

207207
native.bind(

src/wamr/wamr.cc

+24-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class Wamr : public WasmVm {
5656
Wamr() = default;
5757

5858
std::string_view getEngineName() override { return "wamr"; }
59-
std::string_view getPrecompiledSectionName() override { return ""; }
59+
// must use the exact name given by test-tools/append-aot-to-wasm/append_aot_to_wasm.py
60+
std::string_view getPrecompiledSectionName() override { return "wamr-aot"; }
6061

6162
Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
6263
std::unique_ptr<WasmVm> clone() override;
@@ -118,18 +119,32 @@ class Wamr : public WasmVm {
118119
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
119120
};
120121

121-
bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
122+
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
122123
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
123124
store_ = wasm_store_new(engine());
124125
if (store_ == nullptr) {
125126
return false;
126127
}
127128

128-
wasm_byte_vec_t binary = {.size = bytecode.size(),
129-
.data = (char *)bytecode.data(),
130-
.num_elems = bytecode.size(),
131-
.size_of_elem = sizeof(byte_t),
132-
.lock = nullptr};
129+
wasm_byte_vec_t binary = {0};
130+
if (precompiled.empty()) {
131+
binary.size = bytecode.size();
132+
binary.data = const_cast<char *>(bytecode.data());
133+
binary.num_elems = bytecode.size();
134+
binary.size_of_elem = sizeof(byte_t);
135+
binary.lock = nullptr;
136+
} else {
137+
// skip leading paddings
138+
auto padding_count = static_cast<uint8_t>(precompiled[0]);
139+
precompiled.remove_prefix(padding_count + 1);
140+
141+
binary.size = precompiled.size();
142+
binary.data = const_cast<char *>(precompiled.data());
143+
binary.num_elems = precompiled.size();
144+
binary.size_of_elem = sizeof(byte_t);
145+
binary.lock = nullptr;
146+
}
147+
133148
module_ = wasm_module_new(store_.get(), &binary);
134149
if (module_ == nullptr) {
135150
return false;
@@ -224,8 +239,8 @@ static const char *printValKind(wasm_valkind_t kind) {
224239
return "f32";
225240
case WASM_F64:
226241
return "f64";
227-
case WASM_ANYREF:
228-
return "anyref";
242+
case WASM_EXTERNREF:
243+
return "externref";
229244
case WASM_FUNCREF:
230245
return "funcref";
231246
default:

0 commit comments

Comments
 (0)