Skip to content

Commit 017e0a5

Browse files
authored
Merge pull request #907 from bytecodealliance/main
Merge main into dev/refactor_orc_jit
2 parents 5a08e30 + af251e4 commit 017e0a5

40 files changed

+1196
-523
lines changed

ATTRIBUTIONS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ WAMR project reused some components from other open source project:
66
- **contiki-ng**: for the coap protocol implementation
77
- **freebsd libm**: used in core/shared/platform/alios/bh_math.c
88
- **littlevgl**: for the gui samples and wrapped the wasm graphic layer
9-
- **llvm**. for the AOT/JIT compilation
10-
- **wasm-c-api**. to implement the C-APIs of wasm. using headers and sameples
9+
- **llvm**: for the AOT/JIT compilation
10+
- **wasm-c-api**: to implement the C-APIs of wasm. using headers and sameples
1111
- **wasmtime**: for the wasi libc implementation
12-
- **zephyr**. for several platform specific examples
12+
- **zephyr**: for several platform specific examples
13+
- **WebAssembly debugging patch for LLDB**: for extending the ability of LLDB to support wasm debugging
1314

1415
The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
1516

@@ -23,6 +24,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
2324
| wasm-c-api | ac9b509f4df86e40e56e9b01f3f49afab0100037 | c9d31284651b975f05ac27cee0bab1377560b87e | https://github.com/WebAssembly/wasm-c-api | |
2425
| wasmtime | unspecified | v0.26.0 | https://github.com/bytecodealliance/wasmtime | |
2526
| zephyr | unspecified | v2.5.0 | https://www.zephyrproject.org/ | https://www.cvedetails.com/vendor/19255/Zephyrproject.html |
27+
| WebAssembly debugging patch for LLDB | unspecified | unspecified | https://reviews.llvm.org/D78801 | |
2628

2729
## Licenses
2830

ci/coding_guidelines_check.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import shutil
1212
import subprocess
1313
import sys
14+
import unittest
1415

1516
CLANG_FORMAT_CMD = "clang-format-12"
1617
GIT_CLANG_FORMAT_CMD = "git-clang-format-12"
@@ -155,7 +156,7 @@ def run_aspell(file_path: pathlib, root: pathlib) -> bool:
155156

156157

157158
def check_dir_name(path: pathlib, root: pathlib) -> bool:
158-
m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root)))
159+
m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root).parent))
159160
if m:
160161
print(f"--- found a character '_' in {m.groups()} in {path}")
161162

@@ -271,5 +272,30 @@ def main() -> int:
271272
return process_entire_pr(wamr_root, options.commits)
272273

273274

275+
# run with python3 -m unitest ci/coding_guidelines_check.py
276+
class TestCheck(unittest.TestCase):
277+
def test_check_dir_name_failed(self):
278+
root = pathlib.Path("/root/Workspace/")
279+
new_file_path = root.joinpath("core/shared/platform/esp_idf/espid_memmap.c")
280+
self.assertFalse(check_dir_name(new_file_path, root))
281+
282+
def test_check_dir_name_pass(self):
283+
root = pathlib.Path("/root/Workspace/")
284+
new_file_path = root.joinpath("core/shared/platform/esp-idf/espid_memmap.c")
285+
self.assertTrue(check_dir_name(new_file_path, root))
286+
287+
def test_check_file_name_failed(self):
288+
new_file_path = pathlib.Path(
289+
"/root/Workspace/core/shared/platform/esp-idf/espid-memmap.c"
290+
)
291+
self.assertFalse(check_file_name(new_file_path))
292+
293+
def test_check_file_name_pass(self):
294+
new_file_path = pathlib.Path(
295+
"/root/Workspace/core/shared/platform/esp-idf/espid_memmap.c"
296+
)
297+
self.assertTrue(check_file_name(new_file_path))
298+
299+
274300
if __name__ == "__main__":
275301
sys.exit(0 if main() else 1)

core/iwasm/aot/aot_intrinsic.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
6161
{ "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64 },
6262
{ "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP },
6363
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP },
64+
{ "f32.const", NULL, AOT_INTRINSIC_FLAG_F32_CONST},
65+
{ "f64.const", NULL, AOT_INTRINSIC_FLAG_F64_CONST},
6466
};
6567
/* clang-format on */
6668

@@ -617,6 +619,13 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
617619
add_f64_common_intrinsics(comp_ctx);
618620
add_common_float_integer_convertion(comp_ctx);
619621
}
622+
else {
623+
/*
624+
* Use constant value table by default
625+
*/
626+
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
627+
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
628+
}
620629
}
621630

622631
#endif /* WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 */

core/iwasm/aot/aot_intrinsic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern "C" {
5757
#define AOT_INTRINSIC_FLAG_F32_TO_U64 AOT_INTRINSIC_FLAG(0, 23)
5858
#define AOT_INTRINSIC_FLAG_F32_TO_F64 AOT_INTRINSIC_FLAG(0, 24)
5959
#define AOT_INTRINSIC_FLAG_F32_CMP AOT_INTRINSIC_FLAG(0, 25)
60+
#define AOT_INTRINSIC_FLAG_F32_CONST AOT_INTRINSIC_FLAG(0, 26)
6061

6162
#define AOT_INTRINSIC_FLAG_F64_FADD AOT_INTRINSIC_FLAG(1, 0)
6263
#define AOT_INTRINSIC_FLAG_F64_FSUB AOT_INTRINSIC_FLAG(1, 1)
@@ -84,6 +85,7 @@ extern "C" {
8485
#define AOT_INTRINSIC_FLAG_F64_TO_U64 AOT_INTRINSIC_FLAG(1, 23)
8586
#define AOT_INTRINSIC_FLAG_F64_TO_F32 AOT_INTRINSIC_FLAG(1, 24)
8687
#define AOT_INTRINSIC_FLAG_F64_CMP AOT_INTRINSIC_FLAG(1, 25)
88+
#define AOT_INTRINSIC_FLAG_F64_CONST AOT_INTRINSIC_FLAG(1, 26)
8789
/* clang-format on */
8890

8991
float32

core/iwasm/aot/aot_loader.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ get_native_symbol_by_name(const char *name)
465465
return func;
466466
}
467467

468+
static bool
469+
str2uint32(const char *buf, uint32 *p_res);
470+
471+
static bool
472+
str2uint64(const char *buf, uint64 *p_res);
473+
468474
static bool
469475
load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
470476
AOTModule *module, bool is_load_from_file_buf,
@@ -487,11 +493,39 @@ load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
487493

488494
for (i = cnt - 1; i >= 0; i--) {
489495
read_string(p, p_end, symbol);
490-
module->native_symbol_list[i] = get_native_symbol_by_name(symbol);
491-
if (module->native_symbol_list[i] == NULL) {
492-
set_error_buf_v(error_buf, error_buf_size,
493-
"missing native symbol: %s", symbol);
494-
goto fail;
496+
if (!strncmp(symbol, "f32#", 4)) {
497+
uint32 u32;
498+
/* Resolve the raw int bits of f32 const */
499+
if (!str2uint32(symbol + 4, &u32)) {
500+
set_error_buf_v(error_buf, error_buf_size,
501+
"resolve symbol %s failed", symbol);
502+
goto fail;
503+
}
504+
*(uint32 *)(&module->native_symbol_list[i]) = u32;
505+
}
506+
else if (!strncmp(symbol, "f64#", 4)) {
507+
uint64 u64;
508+
/* Resolve the raw int bits of f64 const */
509+
if (!str2uint64(symbol + 4, &u64)) {
510+
set_error_buf_v(error_buf, error_buf_size,
511+
"resolve symbol %s failed", symbol);
512+
goto fail;
513+
}
514+
*(uint64 *)(&module->native_symbol_list[i]) = u64;
515+
}
516+
else if (!strncmp(symbol, "__ignore", 8)) {
517+
/* Padding bytes to make f64 on 8-byte aligned address,
518+
or it is the second 32-bit slot in 32-bit system */
519+
continue;
520+
}
521+
else {
522+
module->native_symbol_list[i] =
523+
get_native_symbol_by_name(symbol);
524+
if (module->native_symbol_list[i] == NULL) {
525+
set_error_buf_v(error_buf, error_buf_size,
526+
"missing native symbol: %s", symbol);
527+
goto fail;
528+
}
495529
}
496530
}
497531
}
@@ -1711,7 +1745,6 @@ is_literal_relocation(const char *reloc_sec_name)
17111745
return !strcmp(reloc_sec_name, ".rela.literal");
17121746
}
17131747

1714-
#if defined(BH_PLATFORM_WINDOWS)
17151748
static bool
17161749
str2uint32(const char *buf, uint32 *p_res)
17171750
{
@@ -1757,7 +1790,6 @@ str2uint64(const char *buf, uint64 *p_res)
17571790
*p_res = res;
17581791
return true;
17591792
}
1760-
#endif
17611793

17621794
static bool
17631795
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,

core/iwasm/aot/aot_runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
14031403
bool ret;
14041404

14051405
if (argc < func_type->param_cell_num) {
1406-
char buf[128];
1406+
char buf[108];
14071407
snprintf(buf, sizeof(buf),
14081408
"invalid argument count %u, must be no smaller than %u", argc,
14091409
func_type->param_cell_num);

core/iwasm/aot/arch/aot_reloc_riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
357357
if (error_buf != NULL)
358358
snprintf(error_buf, error_buf_size,
359359
"Load relocation section failed: "
360-
"invalid relocation type %d.",
360+
"invalid relocation type %" PRIu32 ".",
361361
reloc_type);
362362
return false;
363363
}

core/iwasm/common/wasm_application.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
417417
char *endptr = NULL;
418418
bh_assert(argv[i] != NULL);
419419
if (argv[i][0] == '\0') {
420-
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
420+
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
421421
wasm_runtime_set_exception(module_inst, buf);
422422
goto fail;
423423
}
@@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
554554
break;
555555
}
556556
if (endptr && *endptr != '\0' && *endptr != '_') {
557-
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
558-
argv[i]);
557+
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
558+
i, argv[i]);
559559
wasm_runtime_set_exception(module_inst, buf);
560560
goto fail;
561561
}
@@ -573,7 +573,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
573573
switch (type->types[type->param_count + j]) {
574574
case VALUE_TYPE_I32:
575575
{
576-
os_printf("0x%x:i32", argv1[k]);
576+
os_printf("0x%" PRIx32 ":i32", argv1[k]);
577577
k++;
578578
break;
579579
}
@@ -586,16 +586,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
586586
u.parts[0] = argv1[k];
587587
u.parts[1] = argv1[k + 1];
588588
k += 2;
589-
#ifdef PRIx64
590589
os_printf("0x%" PRIx64 ":i64", u.val);
591-
#else
592-
char buf[16];
593-
if (sizeof(long) == 4)
594-
snprintf(buf, sizeof(buf), "%s", "0x%llx:i64");
595-
else
596-
snprintf(buf, sizeof(buf), "%s", "0x%lx:i64");
597-
os_printf(buf, u.val);
598-
#endif
599590
break;
600591
}
601592
case VALUE_TYPE_F32:
@@ -645,17 +636,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
645636
case VALUE_TYPE_V128:
646637
{
647638
uint64 *v = (uint64 *)(argv1 + k);
648-
#if defined(PRIx64)
649639
os_printf("<0x%016" PRIx64 " 0x%016" PRIx64 ">:v128", *v,
650640
*(v + 1));
651-
#else
652-
if (4 == sizeof(long)) {
653-
os_printf("<0x%016llx 0x%016llx>:v128", *v, *(v + 1));
654-
}
655-
else {
656-
os_printf("<0x%016lx 0x%016lx>:v128", *v, *(v + 1));
657-
}
658-
#endif /* PRIx64 */
659641
k += 4;
660642
break;
661643
}

core/iwasm/compilation/aot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ typedef struct AOTCompData {
268268

269269
typedef struct AOTNativeSymbol {
270270
bh_list_link link;
271-
const char *symbol;
271+
char symbol[32];
272272
int32 index;
273273
} AOTNativeSymbol;
274274

core/iwasm/compilation/aot_compiler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ read_leb(const uint8 *buf, const uint8 *buf_end, uint32 *p_offset,
6464
}
6565
bcnt += 1;
6666
}
67-
if (bcnt > (((maxbits + 8) >> 3) - (maxbits + 8))) {
68-
aot_set_last_error("read leb failed: unsigned leb overflow.");
67+
if (bcnt > (maxbits + 6) / 7) {
68+
aot_set_last_error("read leb failed: "
69+
"integer representation too long");
6970
return false;
7071
}
7172
if (sign && (shift < maxbits) && (byte & 0x40)) {

0 commit comments

Comments
 (0)