Skip to content

Commit c6adf0e

Browse files
committed
fix: update AOT compiler configuration and enhance error handling in fuzz tests
1 parent e41465d commit c6adf0e

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

tests/fuzz/wasm-mutator-fuzz/aot-compiler/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Copyright (C) 2025 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
# Set default build options with the ability to override from the command line
5-
if(NOT WAMR_BUILD_INTERP)
6-
set(WAMR_BUILD_INTERP 1)
7-
endif()
8-
9-
set(WAMR_BUILD_WAMR_COMPILER 1)
104
set(WAMR_BUILD_AOT 0)
115
set(WAMR_BUILD_INTERP 1)
126
set(WAMR_BUILD_JIT 0)

tests/fuzz/wasm-mutator-fuzz/aot-compiler/aot_compiler_fuzz.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
3131
AOTCompOption option = { 0 };
3232
aot_comp_data_t comp_data = NULL;
3333
aot_comp_context_t comp_ctx = NULL;
34+
uint8 *aot_file_buf = NULL;
35+
uint32 aot_file_size = 0;
36+
wasm_module_t aot_module = NULL;
37+
wasm_module_inst_t inst = NULL;
3438

3539
/* libfuzzer don't allow to modify the given Data, so make a copy here */
3640
std::vector<uint8_t> myData(Data, Data + Size);
@@ -78,6 +82,31 @@ LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
7882
goto DESTROY_COMP_CTX;
7983
}
8084

85+
aot_file_buf = aot_emit_aot_file_buf(comp_ctx, comp_data, &aot_file_size);
86+
if (!aot_file_buf) {
87+
handle_aot_recent_error("[EMITTING AOT FILE]");
88+
goto DESTROY_COMP_CTX;
89+
}
90+
91+
aot_module =
92+
wasm_runtime_load(aot_file_buf, aot_file_size, error_buf, 128);
93+
if (!aot_module) {
94+
std::cout << "[LOADING AOT MODULE] " << error_buf << std::endl;
95+
goto RELEASE_AOT_FILE_BUF;
96+
}
97+
98+
inst = wasm_runtime_instantiate(aot_module, 1024*8, 0, error_buf, 128);
99+
if (!inst) {
100+
std::cout << "[INSTANTIATING AOT MODULE] " << error_buf << std::endl;
101+
goto UNLOAD_AOT_MODULE;
102+
}
103+
104+
DEINSTANTIZE_AOT_MODULE:
105+
wasm_runtime_deinstantiate(inst);
106+
UNLOAD_AOT_MODULE:
107+
wasm_runtime_unload(aot_module);
108+
RELEASE_AOT_FILE_BUF:
109+
wasm_runtime_free(aot_file_buf);
81110
DESTROY_COMP_CTX:
82111
aot_destroy_comp_context(comp_ctx);
83112
DESTROY_COMP_DATA:

0 commit comments

Comments
 (0)