Skip to content

Commit e352f0a

Browse files
authored
Refactor AOT loader to support compatible versions (#3891)
This commit refactors the AOT loader in `aot_loader.c` to support compatible versions of the AOT_CURRENT_VERSION constant. Previously, the loader only accepted the exact AOT_CURRENT_VERSION value, but now it also accepts version 3. This change ensures that the runtime can load modules AoT-compiled with different versions of wamrc as long as they have compatible AOT_CURRENT_VERSION values. Related to #3880.
1 parent c7b2683 commit e352f0a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,6 +4236,16 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
42364236
return false;
42374237
}
42384238

4239+
static bool
4240+
aot_compatible_version(uint32 version)
4241+
{
4242+
/*
4243+
* refer to "AoT-compiled module compatibility among WAMR versions" in
4244+
* ./doc/biuld_wasm_app.md
4245+
*/
4246+
return version == 4 || version == 3;
4247+
}
4248+
42394249
static bool
42404250
load(const uint8 *buf, uint32 size, AOTModule *module,
42414251
bool wasm_binary_freeable, bool no_resolve, char *error_buf,
@@ -4254,7 +4264,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module,
42544264
}
42554265

42564266
read_uint32(p, p_end, version);
4257-
if (version != AOT_CURRENT_VERSION) {
4267+
if (!aot_compatible_version(version)) {
42584268
set_error_buf(error_buf, error_buf_size, "unknown binary version");
42594269
return false;
42604270
}

doc/build_wasm_app.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,23 @@ Examples: wamrc -o test.aot test.wasm
377377
When making major ABI changes for AoT-compiled modules, we bump
378378
`AOT_CURRENT_VERSION` constant in `core/config.h` header.
379379
The runtime rejects to load a module AoT-compiled with wamrc with
380-
a different `AOT_CURRENT_VERSION`.
380+
a non-compatible`AOT_CURRENT_VERSION`.
381381
382382
We try our best to maintain our runtime ABI for AoT-compiled modules
383-
compatible among WAMR versions with the same `AOT_CURRENT_VERSION`
383+
compatible among WAMR versions with compatible `AOT_CURRENT_VERSION`
384384
so that combinations of older wamrc and newer runtime usually work.
385385
However, there might be minor incompatibilities time to time.
386-
For productions, we recommend to use the exactly same version of
386+
For productions, we recommend to use compatible versions of
387387
wamrc and the runtime.
388388
389+
| WAMR version | AOT_CURRENT_VERSION | Compatible AOT version |
390+
| ------------ | ------------------- | ---------------------- |
391+
| 1.x | 3 | 3 |
392+
| 2.0.0 | 3 | 3 |
393+
| 2.1.x | 3 | 3 |
394+
| 2.2.0 | 3 | 3 |
395+
| next | 4 | 3,4 |
396+
389397
## AoT compilation with 3rd-party toolchains
390398
391399
`wamrc` uses LLVM to compile wasm bytecode to AoT file, this works for most of the architectures, but there may be circumstances where you want to use 3rd-party toolchains to take over some steps of the compilation pipeline, e.g.

0 commit comments

Comments
 (0)