Skip to content

Commit 02d27e1

Browse files
authored
Fix some compilation warnings and enable Windows JIT (#586)
1 parent a4e4d41 commit 02d27e1

File tree

14 files changed

+119
-29
lines changed

14 files changed

+119
-29
lines changed

build-scripts/config_common.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ if (WAMR_BUILD_JIT EQUAL 1)
7979
if (WAMR_BUILD_AOT EQUAL 1)
8080
add_definitions("-DWASM_ENABLE_JIT=1")
8181
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
82-
if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
83-
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
82+
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
83+
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
84+
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
8485
endif ()
85-
set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
86+
if (NOT EXISTS "${LLVM_BUILD_ROOT}")
87+
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
88+
endif ()
89+
set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
8690
find_package(LLVM REQUIRED CONFIG)
8791
include_directories(${LLVM_INCLUDE_DIRS})
8892
add_definitions(${LLVM_DEFINITIONS})

core/iwasm/aot/aot_loader.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end,
574574
data_list[i]->offset.init_expr_type = (uint8)init_expr_type;
575575
data_list[i]->offset.u.i64 = (int64)init_expr_value;
576576
data_list[i]->func_index_count = func_index_count;
577-
read_byte_array(buf, buf_end, data_list[i]->func_indexes, size1);
577+
read_byte_array(buf, buf_end, data_list[i]->func_indexes, (uint32)size1);
578578
}
579579

580580
*p_buf = buf;
@@ -1444,15 +1444,15 @@ do_text_relocation(AOTModule *module,
14441444
bh_memcpy_s(xmm_buf, sizeof(xmm_buf),
14451445
symbol + strlen(XMM_PLT_PREFIX) + 16, 16);
14461446
if (!str2uint64(xmm_buf, (uint64*)symbol_addr)) {
1447-
set_error_buf_v(error_buf, error_buf,
1447+
set_error_buf_v(error_buf, error_buf_size,
14481448
"resolve symbol %s failed", symbol);
14491449
goto check_symbol_fail;
14501450
}
14511451

14521452
bh_memcpy_s(xmm_buf, sizeof(xmm_buf),
14531453
symbol + strlen(XMM_PLT_PREFIX), 16);
14541454
if (!str2uint64(xmm_buf, (uint64*)((uint8*)symbol_addr + 8))) {
1455-
set_error_buf_v(error_buf, error_buf,
1455+
set_error_buf_v(error_buf, error_buf_size,
14561456
"resolve symbol %s failed", symbol);
14571457
goto check_symbol_fail;
14581458
}
@@ -1468,7 +1468,7 @@ do_text_relocation(AOTModule *module,
14681468
bh_memcpy_s(real_buf, sizeof(real_buf),
14691469
symbol + strlen(REAL_PLT_PREFIX), 16);
14701470
if (!str2uint64(real_buf, (uint64*)symbol_addr)) {
1471-
set_error_buf_v(error_buf, error_buf,
1471+
set_error_buf_v(error_buf, error_buf_size,
14721472
"resolve symbol %s failed", symbol);
14731473
goto check_symbol_fail;
14741474
}
@@ -1484,7 +1484,7 @@ do_text_relocation(AOTModule *module,
14841484
bh_memcpy_s(float_buf, sizeof(float_buf),
14851485
symbol + strlen(REAL_PLT_PREFIX), 8);
14861486
if (!str2uint32(float_buf, (uint32*)symbol_addr)) {
1487-
set_error_buf_v(error_buf, error_buf,
1487+
set_error_buf_v(error_buf, error_buf_size,
14881488
"resolve symbol %s failed", symbol);
14891489
goto check_symbol_fail;
14901490
}
@@ -2306,7 +2306,8 @@ aot_load_from_comp_data(AOTCompData *comp_data, AOTCompContext *comp_ctx,
23062306
goto fail1;
23072307
}
23082308

2309-
bh_memcpy_s(module->memories, size, comp_data->memories, size);
2309+
bh_memcpy_s(module->memories, (uint32)size,
2310+
comp_data->memories, (uint32)size);
23102311
}
23112312

23122313
module->mem_init_data_list = comp_data->mem_init_data_list;

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
777777
void
778778
wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst)
779779
{
780-
return wasm_runtime_deinstantiate_internal(module_inst, false);
780+
wasm_runtime_deinstantiate_internal(module_inst, false);
781781
}
782782

783783
WASMExecEnv *
@@ -1962,7 +1962,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
19621962

19631963
fail:
19641964
if (envp)
1965-
wasm_runtime_free(envp);
1965+
wasm_runtime_free((void*)envp);
19661966

19671967
if (init_options.preopens)
19681968
wasm_runtime_free(init_options.preopens);

core/iwasm/compilation/simd/simd_int_arith.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ aot_compile_simd_i8x16_arith(AOTCompContext *comp_ctx,
8383

8484
return simd_v128_integer_arith(comp_ctx, func_ctx, arith_op, lhs, rhs);
8585
fail:
86-
return NULL;
86+
return false;
8787
}
8888

8989
bool
@@ -105,7 +105,7 @@ aot_compile_simd_i16x8_arith(AOTCompContext *comp_ctx,
105105

106106
return simd_v128_integer_arith(comp_ctx, func_ctx, arith_op, lhs, rhs);
107107
fail:
108-
return NULL;
108+
return false;
109109
}
110110

111111
bool
@@ -127,7 +127,7 @@ aot_compile_simd_i32x4_arith(AOTCompContext *comp_ctx,
127127

128128
return simd_v128_integer_arith(comp_ctx, func_ctx, arith_op, lhs, rhs);
129129
fail:
130-
return NULL;
130+
return false;
131131
}
132132

133133
bool

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,8 +1909,8 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
19091909
return false;
19101910

19111911
memory_data = memory->memory_data;
1912-
heap_size = memory->heap_data_end - memory->heap_data;
1913-
total_size_old = memory->memory_data_end - memory_data;
1912+
heap_size = (uint32)(memory->heap_data_end - memory->heap_data);
1913+
total_size_old = (uint32)(memory->memory_data_end - memory_data);
19141914
total_page_count = inc_page_count + memory->cur_page_count;
19151915
total_size = memory->num_bytes_per_page * (uint64)total_page_count;
19161916
heap_data_old = memory->heap_data;

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static uint32
647647
strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
648648
{
649649
wasm_module_inst_t module_inst = get_module_inst(exec_env);
650-
uint32 len = strlen(src) + 1;
650+
uint32 len = (uint32)strlen(src) + 1;
651651

652652
/* src has been checked by runtime */
653653
if (!validate_native_addr(dst, len))
@@ -712,7 +712,7 @@ free_wrapper(wasm_exec_env_t exec_env, void *ptr)
712712
if (!validate_native_addr(ptr, sizeof(uint32)))
713713
return;
714714

715-
return module_free(addr_native_to_app(ptr));
715+
module_free(addr_native_to_app(ptr));
716716
}
717717

718718
static int32

core/shared/utils/bh_vector.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#include "bh_vector.h"
77

88
static uint8*
9-
alloc_vector_data(uint32 length, uint32 size_elem)
9+
alloc_vector_data(size_t length, size_t size_elem)
1010
{
1111
uint64 total_size = ((uint64)size_elem) * length;
1212
uint8 *data;
1313

14-
if (total_size > UINT32_MAX) {
14+
if (length > UINT32_MAX
15+
|| size_elem > UINT32_MAX
16+
|| total_size > UINT32_MAX) {
1517
return NULL;
1618
}
1719

@@ -23,7 +25,7 @@ alloc_vector_data(uint32 length, uint32 size_elem)
2325
}
2426

2527
static bool
26-
extend_vector(Vector *vector, uint32 length)
28+
extend_vector(Vector *vector, size_t length)
2729
{
2830
uint8 *data;
2931

@@ -45,7 +47,7 @@ extend_vector(Vector *vector, uint32 length)
4547
}
4648

4749
bool
48-
bh_vector_init(Vector *vector, uint32 init_length, uint32 size_elem)
50+
bh_vector_init(Vector *vector, size_t init_length, size_t size_elem)
4951
{
5052
if (!vector) {
5153
LOG_ERROR("Init vector failed: vector is NULL.\n");
@@ -104,7 +106,7 @@ bool bh_vector_get(const Vector *vector, uint32 index, void *elem_buf)
104106

105107
bool bh_vector_insert(Vector *vector, uint32 index, const void *elem_buf)
106108
{
107-
uint32 i;
109+
size_t i;
108110
uint8 *p;
109111

110112
if (!vector || !elem_buf) {
@@ -182,7 +184,7 @@ bh_vector_remove(Vector *vector, uint32 index, void *old_elem_buf)
182184
return true;
183185
}
184186

185-
uint32
187+
size_t
186188
bh_vector_size(const Vector *vector)
187189
{
188190
return vector ? vector->num_elems : 0;

core/shared/utils/bh_vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef struct Vector {
3535
* @return true if success, false otherwise
3636
*/
3737
bool
38-
bh_vector_init(Vector *vector, uint32 init_length, uint32 size_elem);
38+
bh_vector_init(Vector *vector, size_t init_length, size_t size_elem);
3939

4040
/**
4141
* Set element of vector
@@ -104,7 +104,7 @@ bh_vector_remove(Vector *vector, uint32 index, void *old_elem_buf);
104104
*
105105
* @return return the size of the vector
106106
*/
107-
uint32
107+
size_t
108108
bh_vector_size(const Vector *vector);
109109

110110
/**

core/shared/utils/uncommon/bh_getopt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef __GNUC__
77

88
#include "bh_getopt.h"
9+
#include <stdio.h>
910
#include <string.h>
1011

1112
char* optarg = NULL;
@@ -14,7 +15,6 @@ int optind = 1;
1415
int getopt(int argc, char *const argv[], const char *optstring)
1516
{
1617
static int sp = 1;
17-
int c;
1818
int opt;
1919
char *p;
2020

product-mini/platforms/windows/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ endif ()
5858

5959
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
6060
# Enable fast interpreter
61-
set (WAMR_BUILD_FAST_INTERP 1)
61+
set (WAMR_BUILD_FAST_INTERP 0)
6262
endif ()
6363

6464
if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
#
5+
6+
#!/usr/bin/env python3
7+
import os
8+
import sys
9+
from pathlib import Path
10+
11+
def clone_llvm():
12+
llvm_dir = Path("llvm")
13+
if(llvm_dir.exists() == False):
14+
print("Clone llvm to core/deps/ ..")
15+
for line in os.popen("git clone --branch release/11.x https://github.com/llvm/llvm-project.git llvm"):
16+
print(line)
17+
else:
18+
print("llvm source codes already existed")
19+
return llvm_dir
20+
21+
def main():
22+
current_os = sys.platform
23+
print("current OS is ", current_os)
24+
25+
current_dir = Path.cwd()
26+
deps_dir = current_dir.joinpath( "../../../core/deps")
27+
28+
os.chdir(deps_dir)
29+
llvm_dir = clone_llvm()
30+
os.chdir(llvm_dir)
31+
32+
build_dir_name = "win32build"
33+
llvm_file = "LLVM.sln"
34+
35+
Path(build_dir_name).mkdir(exist_ok = True)
36+
build_dir = Path(build_dir_name)
37+
os.chdir(build_dir)
38+
39+
if ( not Path(llvm_file).exists()):
40+
core_number = os.cpu_count()
41+
print("Build llvm with", core_number, " cores")
42+
cmd = 'cmake ../llvm \
43+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
44+
-DCMAKE_BUILD_TYPE:STRING="Release" \
45+
-DLLVM_TARGETS_TO_BUILD:STRING="X86;ARM;AArch64;Mips" \
46+
-DLLVM_INCLUDE_GO_TESTS=OFF \
47+
-DLLVM_INCLUDE_TOOLS=OFF \
48+
-DLLVM_INCLUDE_UTILS=OFF \
49+
-DLLVM_ENABLE_TERMINFO=OFF \
50+
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
51+
-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON \
52+
-DLLVM_ENABLE_ZLIB:BOOL=OFF \
53+
-DLLVM_INCLUDE_DOCS:BOOL=OFF \
54+
-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \
55+
-DLLVM_INCLUDE_TESTS:BOOL=OFF \
56+
-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
57+
-DLLVM_APPEND_VC_REV:BOOL=OFF'
58+
print(cmd)
59+
for line in os.popen(cmd):
60+
print(line)
61+
else:
62+
print("llvm has already been Cmaked")
63+
64+
print("Please open LLVM.sln in {} to build *Release* version".format(build_dir.absolute()))
65+
66+
os.chdir(current_dir)
67+
68+
if __name__ == "__main__":
69+
main()

product-mini/platforms/windows/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ app_instance_repl(wasm_module_inst_t module_inst)
118118
size_t n;
119119

120120
while ((printf("webassembly> "),
121-
cmd = fgets(buffer, sizeof(buffer), stdin)) != -1) {
121+
cmd = fgets(buffer, sizeof(buffer), stdin)) != NULL) {
122122
bh_assert(cmd);
123123
n = strlen(cmd);
124124
if (cmd[n - 1] == '\n') {

samples/workload/bwa/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ ExternalProject_Add(bwa
117117
UPDATE_COMMAND git clean -fd && git checkout -- *
118118
&& ${CMAKE_COMMAND} -E echo "Copying pre-installed CMakeLists.txt"
119119
&& ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.bwa_wasm.txt CMakeLists.txt
120+
&& git apply ../bwa.patch
120121
CONFIGURE_COMMAND ${CMAKE_COMMAND}
121122
-DWASI_SDK_PREFIX=${WASI_SDK_HOME}/wasi-sdk
122123
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_HOME}/wasi-sdk/share/cmake/wasi-sdk.cmake

samples/workload/bwa/bwa.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/utils.c b/utils.c
2+
index 9ceb1be..323299f 100644
3+
--- a/utils.c
4+
+++ b/utils.c
5+
@@ -301,6 +301,7 @@ long peakrss(void)
6+
#ifdef __linux__
7+
return r.ru_maxrss * 1024;
8+
#else
9+
- return r.ru_maxrss;
10+
+ /*return r.ru_maxrss;*/
11+
+ return 0;
12+
#endif
13+
}

0 commit comments

Comments
 (0)