Skip to content

Commit 534c493

Browse files
wenyonghTianlongLiangZzzabiyakaDeniz Sokmenxdoardo
authored
Merge branch main into dev/instantiate_linking (#3915)
* Exclude fuzz test python and npm packages in scoreboard scan (#3871) * Fix out of bounds issues after memory.grow on non-aot non-threads builds (#3872) * fix(ios): Remove `float-abi` flag (#3889) * build(deps): bump github/codeql-action from 3.26.13 to 3.27.0 (#3888) * Refine looking up aot function with index (#3882) * Bump AOT_CURRENT_VERSION for WAMR 2.x (gc, memory64) (#3880) * Fix mmap flags for AOT loader on non-Linux SGX platforms (#3890) * Fix out of bounds issue in is_native_addr_in_shared_heap function (#3886) * Refactor AOT loader to support compatible versions (#3891) * Wasm loader enhancement: check code size in code entry (#3892) * Fix linked global initialization in multimodule (#3905) * build(deps): bump github/codeql-action from 3.27.0 to 3.27.1 (#3902) * GlobalValueSet was moved to IRPartitionLayer recently, but we have a local definition anyway (#3899) * Fix a leak in wasm_loader_emit_br_info (#3900) * Correct the table index calculation in aot_instantiation (#3903) * build(deps): bump github/codeql-action from 3.27.1 to 3.27.4 (#3912) * Support external toolchain on Windows for aot compiler (#3911) * Fix CI wamr-ide error (#3913) Co-authored-by: TianlongLiang <[email protected]> Co-authored-by: Maks Litskevich <[email protected]> Co-authored-by: Deniz Sokmen <[email protected]> Co-authored-by: edoardo <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: YAMAMOTO Takashi <[email protected]> Co-authored-by: liang.he <[email protected]> Co-authored-by: Fadumina Barre <[email protected]> Co-authored-by: Marcin Kolny <[email protected]> Co-authored-by: James Ring <[email protected]>
1 parent 9b5058c commit 534c493

File tree

31 files changed

+394
-153
lines changed

31 files changed

+394
-153
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
56-
uses: github/codeql-action/init@v3.26.13
56+
uses: github/codeql-action/init@v3.27.4
5757
with:
5858
languages: ${{ matrix.language }}
5959

@@ -70,7 +70,7 @@ jobs:
7070
- run: |
7171
./.github/scripts/codeql_buildscript.sh
7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@v3.26.13
73+
uses: github/codeql-action/analyze@v3.27.4
7474
with:
7575
category: "/language:${{matrix.language}}"
7676
upload: false
@@ -99,7 +99,7 @@ jobs:
9999
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
100100

101101
- name: Upload CodeQL results to code scanning
102-
uses: github/codeql-action/upload-sarif@v3.26.13
102+
uses: github/codeql-action/upload-sarif@v3.27.4
103103
with:
104104
sarif_file: ${{ steps.step1.outputs.sarif-output }}
105105
category: "/language:${{matrix.language}}"

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ jobs:
828828
run: |
829829
mkdir build
830830
cd build
831-
cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
831+
cmake .. -DWAMR_BUILD_DEBUG_INTERP=1 -DWAMR_BUILD_REF_TYPES=1
832832
make
833833
working-directory: product-mini/platforms/linux
834834

.github/workflows/supply_chain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ jobs:
6060

6161
# Upload the results to GitHub's code scanning dashboard.
6262
- name: "Upload to code-scanning"
63-
uses: github/codeql-action/upload-sarif@af56b044b5d41c317aef5d19920b3183cb4fbbec # v2.2.4
63+
uses: github/codeql-action/upload-sarif@a1695c562bbfa68dc5ab58c9b5e9f616b52bf5be # v2.2.4
6464
with:
6565
sarif_file: results.sarif

build-scripts/build_llvm.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,27 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
102102
"default": [],
103103
}
104104

105+
experimental_backends = ["ARC", "Xtensa"]
106+
normal_backends = [s for s in backends if s not in experimental_backends]
107+
105108
LLVM_TARGETS_TO_BUILD = [
106-
'-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(backends) + '"'
107-
if backends
109+
'-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(normal_backends) + '"'
110+
if normal_backends
108111
else '-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;Mips;RISCV;X86"'
109112
]
110113

114+
# if not on ARC platform, but want to add expeirmental backend ARC as target
115+
if platform != "ARC" and "ARC" in backends:
116+
LLVM_TARGETS_TO_BUILD.extend(
117+
LLVM_EXTRA_COMPILE_OPTIONS["arc"]
118+
)
119+
120+
if platform != "Xtensa" and "Xtensa" in backends:
121+
print(
122+
"Currently it's not supported to build Xtensa backend on non-Xtensa platform"
123+
)
124+
return None
125+
111126
LLVM_PROJECTS_TO_BUILD = [
112127
'-DLLVM_ENABLE_PROJECTS:STRING="' + ";".join(projects) + '"' if projects else ""
113128
]
@@ -240,6 +255,7 @@ def main():
240255
"X86",
241256
"Xtensa",
242257
],
258+
default=[],
243259
help="identify LLVM supported backends, separate by space, like '--arch ARM Mips X86'",
244260
)
245261
parser.add_argument(

ci/coding_guidelines_check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def check_file_name(path: Path) -> bool:
180180
"docker-compose",
181181
"package-lock",
182182
"vite-env.d",
183+
"osv-scanner",
183184
]:
184185
return True
185186

core/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#endif
8585

8686
#define AOT_MAGIC_NUMBER 0x746f6100
87-
#define AOT_CURRENT_VERSION 3
87+
#define AOT_CURRENT_VERSION 4
8888

8989
#ifndef WASM_ENABLE_JIT
9090
#define WASM_ENABLE_JIT 0

core/iwasm/aot/aot_loader.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,13 @@ loader_mmap(uint32 size, bool prot_exec, char *error_buf, uint32 error_buf_size)
304304
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
305305
|| defined(BUILD_TARGET_RISCV64_LP64D) \
306306
|| defined(BUILD_TARGET_RISCV64_LP64)
307-
#ifndef __APPLE__
307+
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX)
308308
/* The mmapped AOT data and code in 64-bit targets had better be in
309309
range 0 to 2G, or aot loader may fail to apply some relocations,
310310
e.g., R_X86_64_32/R_X86_64_32S/R_X86_64_PC32/R_RISCV_32.
311311
We try to mmap with MMAP_MAP_32BIT flag first, and if fails, mmap
312312
again without the flag. */
313+
/* sgx_tprotect_rsrv_mem() and sgx_alloc_rsrv_mem() will ignore flags */
313314
map_flags = MMAP_MAP_32BIT;
314315
if ((mem = os_mmap(NULL, size, map_prot, map_flags,
315316
os_get_invalid_handle()))) {
@@ -4290,6 +4291,16 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
42904291
return false;
42914292
}
42924293

4294+
static bool
4295+
aot_compatible_version(uint32 version)
4296+
{
4297+
/*
4298+
* refer to "AoT-compiled module compatibility among WAMR versions" in
4299+
* ./doc/biuld_wasm_app.md
4300+
*/
4301+
return version == 4 || version == 3;
4302+
}
4303+
42934304
static bool
42944305
load(const uint8 *buf, uint32 size, AOTModule *module,
42954306
bool wasm_binary_freeable, bool no_resolve, char *error_buf,
@@ -4308,7 +4319,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module,
43084319
}
43094320

43104321
read_uint32(p, p_end, version);
4311-
if (version != AOT_CURRENT_VERSION) {
4322+
if (!aot_compatible_version(version)) {
43124323
set_error_buf(error_buf, error_buf_size, "unknown binary version");
43134324
return false;
43144325
}

core/iwasm/aot/aot_runtime.c

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,11 @@ aot_get_default_memory(AOTModuleInstance *module_inst)
11291129
}
11301130

11311131
AOTMemoryInstance *
1132-
aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index)
1132+
aot_get_memory_with_idx(AOTModuleInstance *module_inst, uint32 mem_idx)
11331133
{
1134-
if ((index >= module_inst->memory_count) || !module_inst->memories)
1134+
if ((mem_idx >= module_inst->memory_count) || !module_inst->memories)
11351135
return NULL;
1136-
return module_inst->memories[index];
1136+
return module_inst->memories[mem_idx];
11371137
}
11381138

11391139
static bool
@@ -1428,21 +1428,78 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
14281428
return true;
14291429
}
14301430

1431+
static int
1432+
cmp_export_func_map(const void *a, const void *b)
1433+
{
1434+
uint32 func_idx1 = ((const ExportFuncMap *)a)->func_idx;
1435+
uint32 func_idx2 = ((const ExportFuncMap *)b)->func_idx;
1436+
return func_idx1 < func_idx2 ? -1 : (func_idx1 > func_idx2 ? 1 : 0);
1437+
}
1438+
14311439
AOTFunctionInstance *
1432-
aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx)
1440+
aot_lookup_function_with_idx(AOTModuleInstance *module_inst, uint32 func_idx)
14331441
{
1434-
AOTModule *module = (AOTModule *)module_inst->module;
14351442
AOTModuleInstanceExtra *extra = (AOTModuleInstanceExtra *)module_inst->e;
14361443
AOTFunctionInstance *export_funcs =
14371444
(AOTFunctionInstance *)module_inst->export_functions;
1445+
AOTFunctionInstance *func_inst = NULL;
1446+
ExportFuncMap *export_func_maps, *export_func_map, key;
1447+
uint64 size;
14381448
uint32 i;
14391449

1440-
/* export functions are pre-instantiated */
1441-
for (i = 0; i < module_inst->export_func_count; i++) {
1442-
if (export_funcs[i].func_index == func_idx)
1443-
return &export_funcs[i];
1450+
if (module_inst->export_func_count == 0)
1451+
return NULL;
1452+
1453+
exception_lock(module_inst);
1454+
1455+
/* create the func_idx to export_idx maps if it hasn't been created */
1456+
if (!extra->export_func_maps) {
1457+
size = sizeof(ExportFuncMap) * (uint64)module_inst->export_func_count;
1458+
if (!(export_func_maps = extra->export_func_maps =
1459+
runtime_malloc(size, NULL, 0))) {
1460+
/* allocate memory failed, lookup the export function one by one */
1461+
for (i = 0; i < module_inst->export_func_count; i++) {
1462+
if (export_funcs[i].func_index == func_idx) {
1463+
func_inst = &export_funcs[i];
1464+
break;
1465+
}
1466+
}
1467+
goto unlock_and_return;
1468+
}
1469+
1470+
for (i = 0; i < module_inst->export_func_count; i++) {
1471+
export_func_maps[i].func_idx = export_funcs[i].func_index;
1472+
export_func_maps[i].export_idx = i;
1473+
}
1474+
1475+
qsort(export_func_maps, module_inst->export_func_count,
1476+
sizeof(ExportFuncMap), cmp_export_func_map);
14441477
}
14451478

1479+
/* lookup the map to get the export_idx of the func_idx */
1480+
key.func_idx = func_idx;
1481+
export_func_map =
1482+
bsearch(&key, extra->export_func_maps, module_inst->export_func_count,
1483+
sizeof(ExportFuncMap), cmp_export_func_map);
1484+
if (export_func_map)
1485+
func_inst = &export_funcs[export_func_map->export_idx];
1486+
1487+
unlock_and_return:
1488+
exception_unlock(module_inst);
1489+
return func_inst;
1490+
}
1491+
1492+
AOTFunctionInstance *
1493+
aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx)
1494+
{
1495+
AOTModule *module = (AOTModule *)module_inst->module;
1496+
AOTModuleInstanceExtra *extra = (AOTModuleInstanceExtra *)module_inst->e;
1497+
AOTFunctionInstance *func_inst;
1498+
1499+
/* lookup from export functions first */
1500+
if ((func_inst = aot_lookup_function_with_idx(module_inst, func_idx)))
1501+
return func_inst;
1502+
14461503
exception_lock(module_inst);
14471504

14481505
/* allocate functions array if needed */
@@ -1891,7 +1948,7 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
18911948
}
18921949
#endif
18931950

1894-
/* Check heap size */
1951+
/* Align and validate heap size */
18951952
heap_size = align_uint(heap_size, 8);
18961953
if (heap_size > APP_HEAP_SIZE_MAX)
18971954
heap_size = APP_HEAP_SIZE_MAX;
@@ -2118,7 +2175,11 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
21182175
AOTTableInstance *table_inst;
21192176
table_elem_type_t *table_data;
21202177

2121-
table = &module->tables[i];
2178+
/* bypass imported table since AOTImportTable doesn't have init_expr */
2179+
if (i < module->import_table_count)
2180+
continue;
2181+
2182+
table = &module->tables[i - module->import_table_count];
21222183
bh_assert(table);
21232184

21242185
if (table->init_expr.init_expr_type == INIT_EXPR_NONE) {
@@ -2342,6 +2403,9 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
23422403
if (module_inst->export_functions)
23432404
wasm_runtime_free(module_inst->export_functions);
23442405

2406+
if (extra->export_func_maps)
2407+
wasm_runtime_free(extra->export_func_maps);
2408+
23452409
if (module_inst->export_globals)
23462410
wasm_runtime_free(module_inst->export_globals);
23472411

core/iwasm/aot/aot_runtime.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ typedef struct AOTFunctionInstance {
109109
} u;
110110
} AOTFunctionInstance;
111111

112+
/* Map of a function index to the element ith in
113+
the export functions array */
114+
typedef struct ExportFuncMap {
115+
uint32 func_idx;
116+
uint32 export_idx;
117+
} ExportFuncMap;
118+
112119
typedef struct AOTModuleInstanceExtra {
113120
DefPointer(const uint32 *, stack_sizes);
114121
/*
@@ -120,6 +127,13 @@ typedef struct AOTModuleInstanceExtra {
120127
MemBound shared_heap_start_off;
121128

122129
WASMModuleInstanceExtraCommon common;
130+
131+
/**
132+
* maps of func indexes to export func indexes, which
133+
* is sorted by func index for a quick lookup and is
134+
* created only when first time used.
135+
*/
136+
ExportFuncMap *export_func_maps;
123137
AOTFunctionInstance **functions;
124138
uint32 function_count;
125139
#if WASM_ENABLE_MULTI_MODULE != 0
@@ -561,14 +575,21 @@ aot_destroy_memory(AOTMemoryInstance *memory);
561575
AOTFunctionInstance *
562576
aot_lookup_function(const AOTModuleInstance *module_inst, const char *name);
563577

578+
/**
579+
* Lookup an exported function in the AOT module instance with
580+
* the function index.
581+
*/
582+
AOTFunctionInstance *
583+
aot_lookup_function_with_idx(AOTModuleInstance *module_inst, uint32 func_idx);
584+
564585
AOTMemoryInstance *
565586
aot_lookup_memory(AOTModuleInstance *module_inst, char const *name);
566587

567588
AOTMemoryInstance *
568589
aot_get_default_memory(AOTModuleInstance *module_inst);
569590

570591
AOTMemoryInstance *
571-
aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index);
592+
aot_get_memory_with_idx(AOTModuleInstance *module_inst, uint32 mem_idx);
572593

573594
/**
574595
* Get a function in the AOT module instance.
@@ -579,7 +600,7 @@ aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index);
579600
* @return the function instance found
580601
*/
581602
AOTFunctionInstance *
582-
aot_get_function_instance(AOTModuleInstance *module_inst, uint32_t func_idx);
603+
aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx);
583604

584605
/**
585606
* Call the given AOT function of a AOT module instance with

core/iwasm/common/wasm_application.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
105105
bool ret, is_import_func = true, is_memory64 = false;
106106
#if WASM_ENABLE_MEMORY64 != 0
107107
WASMModuleInstance *wasm_module_inst = (WASMModuleInstance *)module_inst;
108-
is_memory64 = wasm_module_inst->memories[0]->is_memory64;
108+
if (wasm_module_inst->memory_count > 0)
109+
is_memory64 = wasm_module_inst->memories[0]->is_memory64;
109110
#endif
110111

111112
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);

0 commit comments

Comments
 (0)