Fix the build warnings on Mac (#388)

Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com>
This commit is contained in:
Xiaokang Qin 2020-09-18 18:22:26 +08:00 committed by GitHub
parent 2d06567cd1
commit 7c8ccc7c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 63 deletions

View File

@ -2657,13 +2657,6 @@ fail:
* Implementation of wasm_runtime_invoke_native() * Implementation of wasm_runtime_invoke_native()
*/ */
static inline void
word_copy(uint32 *dest, uint32 *src, unsigned num)
{
for (; num > 0; num--)
*dest++ = *src++;
}
#define PUT_I64_TO_ADDR(addr, value) do { \ #define PUT_I64_TO_ADDR(addr, value) do { \
union { int64 val; uint32 parts[2]; } u; \ union { int64 val; uint32 parts[2]; } u; \
u.val = (value); \ u.val = (value); \
@ -2936,6 +2929,13 @@ static Float64FuncPtr invokeNative_Float64 = (Float64FuncPtr)invokeNative;
static Float32FuncPtr invokeNative_Float32 = (Float32FuncPtr)invokeNative; static Float32FuncPtr invokeNative_Float32 = (Float32FuncPtr)invokeNative;
static VoidFuncPtr invokeNative_Void = (VoidFuncPtr)invokeNative; static VoidFuncPtr invokeNative_Void = (VoidFuncPtr)invokeNative;
static inline void
word_copy(uint32 *dest, uint32 *src, unsigned num)
{
for (; num > 0; num--)
*dest++ = *src++;
}
bool bool
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr, wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature, const WASMType *func_type, const char *signature,

View File

@ -661,7 +661,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
uint32 param_cell_num; uint32 param_cell_num;
uint64 total_size; uint64 total_size;
uint8 *wasm_ret_types = NULL; uint8 *wasm_ret_types = NULL;
bool ret; bool ret = false;
/* Check function type index */ /* Check function type index */
if (type_idx >= comp_ctx->comp_data->func_type_count) { if (type_idx >= comp_ctx->comp_data->func_type_count) {

View File

@ -241,10 +241,10 @@ call_llvm_intrinsic_v(AOTCompContext *comp_ctx,
/* Call llvm constrained floating-point intrinsic */ /* Call llvm constrained floating-point intrinsic */
static LLVMValueRef static LLVMValueRef
call_llvm_float_expermental_constrained_intrinsic(AOTCompContext *comp_ctx, call_llvm_float_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
const char *intrinsic, bool is_f32,
bool is_f32, const char *intrinsic,
...) ...)
{ {
va_list param_value_list; va_list param_value_list;
LLVMValueRef ret; LLVMValueRef ret;
@ -253,7 +253,7 @@ call_llvm_float_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
param_types[0] = param_types[1] = ret_type; param_types[0] = param_types[1] = ret_type;
param_types[2] = param_types[3] = MD_TYPE; param_types[2] = param_types[3] = MD_TYPE;
va_start(param_value_list, is_f32); va_start(param_value_list, intrinsic);
ret = call_llvm_intrinsic_v(comp_ctx, ret = call_llvm_intrinsic_v(comp_ctx,
intrinsic, intrinsic,
@ -269,10 +269,10 @@ call_llvm_float_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
/* Call llvm constrained libm-equivalent intrinsic */ /* Call llvm constrained libm-equivalent intrinsic */
static LLVMValueRef static LLVMValueRef
call_llvm_libm_expermental_constrained_intrinsic(AOTCompContext *comp_ctx, call_llvm_libm_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
const char *intrinsic, bool is_f32,
bool is_f32, const char *intrinsic,
...) ...)
{ {
va_list param_value_list; va_list param_value_list;
LLVMValueRef ret; LLVMValueRef ret;
@ -281,7 +281,7 @@ call_llvm_libm_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
param_types[0] = ret_type; param_types[0] = ret_type;
param_types[1] = param_types[2] = MD_TYPE; param_types[1] = param_types[2] = MD_TYPE;
va_start(param_value_list, is_f32); va_start(param_value_list, intrinsic);
ret = call_llvm_intrinsic_v(comp_ctx, ret = call_llvm_intrinsic_v(comp_ctx,
intrinsic, intrinsic,
@ -929,12 +929,12 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
DEF_FP_BINARY_OP(LLVMBuildFAdd(comp_ctx->builder, left, right, "fadd"), DEF_FP_BINARY_OP(LLVMBuildFAdd(comp_ctx->builder, left, right, "fadd"),
"llvm build fadd fail."); "llvm build fadd fail.");
else else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic( DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx, comp_ctx,
is_f32,
(is_f32 (is_f32
? "llvm.experimental.constrained.fadd.f32" ? "llvm.experimental.constrained.fadd.f32"
: "llvm.experimental.constrained.fadd.f64"), : "llvm.experimental.constrained.fadd.f64"),
is_f32,
left, left,
right, right,
comp_ctx->fp_rounding_mode, comp_ctx->fp_rounding_mode,
@ -946,12 +946,12 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
DEF_FP_BINARY_OP(LLVMBuildFSub(comp_ctx->builder, left, right, "fsub"), DEF_FP_BINARY_OP(LLVMBuildFSub(comp_ctx->builder, left, right, "fsub"),
"llvm build fsub fail."); "llvm build fsub fail.");
else else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic( DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx, comp_ctx,
is_f32,
(is_f32 (is_f32
? "llvm.experimental.constrained.fsub.f32" ? "llvm.experimental.constrained.fsub.f32"
: "llvm.experimental.constrained.fsub.f64"), : "llvm.experimental.constrained.fsub.f64"),
is_f32,
left, left,
right, right,
comp_ctx->fp_rounding_mode, comp_ctx->fp_rounding_mode,
@ -963,12 +963,12 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
DEF_FP_BINARY_OP(LLVMBuildFMul(comp_ctx->builder, left, right, "fmul"), DEF_FP_BINARY_OP(LLVMBuildFMul(comp_ctx->builder, left, right, "fmul"),
"llvm build fmul fail."); "llvm build fmul fail.");
else else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic( DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx, comp_ctx,
is_f32,
(is_f32 (is_f32
? "llvm.experimental.constrained.fmul.f32" ? "llvm.experimental.constrained.fmul.f32"
: "llvm.experimental.constrained.fmul.f64"), : "llvm.experimental.constrained.fmul.f64"),
is_f32,
left, left,
right, right,
comp_ctx->fp_rounding_mode, comp_ctx->fp_rounding_mode,
@ -980,12 +980,12 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
DEF_FP_BINARY_OP(LLVMBuildFDiv(comp_ctx->builder, left, right, "fdiv"), DEF_FP_BINARY_OP(LLVMBuildFDiv(comp_ctx->builder, left, right, "fdiv"),
"llvm build fdiv fail."); "llvm build fdiv fail.");
else else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic( DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx, comp_ctx,
is_f32,
(is_f32 (is_f32
? "llvm.experimental.constrained.fdiv.f32" ? "llvm.experimental.constrained.fdiv.f32"
: "llvm.experimental.constrained.fdiv.f64"), : "llvm.experimental.constrained.fdiv.f64"),
is_f32,
left, left,
right, right,
comp_ctx->fp_rounding_mode, comp_ctx->fp_rounding_mode,
@ -1020,9 +1020,9 @@ fail:
static LLVMValueRef static LLVMValueRef
call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx, call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx,
const char *intrinsic, bool is_f32,
bool is_f32, const char *intrinsic,
...) ...)
{ {
va_list param_value_list; va_list param_value_list;
LLVMValueRef ret; LLVMValueRef ret;
@ -1030,7 +1030,7 @@ call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx,
param_type = ret_type; param_type = ret_type;
va_start(param_value_list, is_f32); va_start(param_value_list, intrinsic);
ret = call_llvm_intrinsic_v(comp_ctx, ret = call_llvm_intrinsic_v(comp_ctx,
intrinsic, intrinsic,
@ -1051,9 +1051,9 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
switch (math_op) { switch (math_op) {
case FLOAT_ABS: case FLOAT_ABS:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.fabs.f32" : is_f32 ? "llvm.fabs.f32" :
"llvm.fabs.f64", "llvm.fabs.f64",
is_f32,
operand), operand),
NULL); NULL);
return true; return true;
@ -1064,51 +1064,51 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
case FLOAT_CEIL: case FLOAT_CEIL:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.ceil.f32" : is_f32 ? "llvm.ceil.f32" :
"llvm.ceil.f64", "llvm.ceil.f64",
is_f32,
operand), operand),
NULL); NULL);
return true; return true;
case FLOAT_FLOOR: case FLOAT_FLOOR:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32 ? "llvm.floor.f32" :
"llvm.floor.f64",
is_f32, is_f32,
is_f32 ? "llvm.floor.f32":
"llvm.floor.f64",
operand), operand),
NULL); NULL);
return true; return true;
case FLOAT_TRUNC: case FLOAT_TRUNC:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.trunc.f32" : is_f32 ? "llvm.trunc.f32" :
"llvm.trunc.f64", "llvm.trunc.f64",
is_f32,
operand), operand),
NULL); NULL);
return true; return true;
case FLOAT_NEAREST: case FLOAT_NEAREST:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.rint.f32" : is_f32 ? "llvm.rint.f32" :
"llvm.rint.f64", "llvm.rint.f64",
is_f32,
operand), operand),
NULL); NULL);
return true; return true;
case FLOAT_SQRT: case FLOAT_SQRT:
if (is_targeting_soft_float(comp_ctx, is_f32)) if (is_targeting_soft_float(comp_ctx, is_f32))
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx, DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.sqrt.f32" : is_f32 ? "llvm.sqrt.f32" :
"llvm.sqrt.f64", "llvm.sqrt.f64",
is_f32,
operand), operand),
NULL); NULL);
else else
DEF_FP_UNARY_OP(call_llvm_libm_expermental_constrained_intrinsic( DEF_FP_UNARY_OP(call_llvm_libm_experimental_constrained_intrinsic(
comp_ctx, comp_ctx,
is_f32,
(is_f32 (is_f32
? "llvm.experimental.constrained.sqrt.f32" ? "llvm.experimental.constrained.sqrt.f32"
: "llvm.experimental.constrained.sqrt.f64"), : "llvm.experimental.constrained.sqrt.f64"),
is_f32,
operand, operand,
comp_ctx->fp_rounding_mode, comp_ctx->fp_rounding_mode,
comp_ctx->fp_exception_behavior), comp_ctx->fp_exception_behavior),

View File

@ -195,7 +195,7 @@ typedef struct WASMImport {
} u; } u;
} WASMImport; } WASMImport;
typedef struct WASMFunction { struct WASMFunction {
/* the type of function */ /* the type of function */
WASMType *func_type; WASMType *func_type;
uint32 local_count; uint32 local_count;
@ -226,13 +226,13 @@ typedef struct WASMFunction {
uint8 *consts; uint8 *consts;
uint32 const_cell_num; uint32 const_cell_num;
#endif #endif
} WASMFunction; };
typedef struct WASMGlobal { struct WASMGlobal {
uint8 type; uint8 type;
bool is_mutable; bool is_mutable;
InitializerExpression init_expr; InitializerExpression init_expr;
} WASMGlobal; };
typedef struct WASMExport { typedef struct WASMExport {
char *name; char *name;
@ -281,7 +281,7 @@ typedef struct StringNode {
char *str; char *str;
} StringNode, *StringList; } StringNode, *StringList;
typedef struct WASMModule { struct WASMModule {
/* Module type, for module loaded from WASM bytecode binary, /* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode; this field is Wasm_Module_Bytecode;
for module loaded from AOT file, this field is for module loaded from AOT file, this field is
@ -365,7 +365,7 @@ typedef struct WASMModule {
bh_list import_module_list_head; bh_list import_module_list_head;
bh_list *import_module_list; bh_list *import_module_list;
#endif #endif
} WASMModule; };
typedef struct BlockType { typedef struct BlockType {
/* Block type may be expressed in one of two forms: /* Block type may be expressed in one of two forms:

View File

@ -21,7 +21,7 @@ typedef struct WASMMemoryInstance WASMMemoryInstance;
typedef struct WASMTableInstance WASMTableInstance; typedef struct WASMTableInstance WASMTableInstance;
typedef struct WASMGlobalInstance WASMGlobalInstance; typedef struct WASMGlobalInstance WASMGlobalInstance;
typedef struct WASMMemoryInstance { struct WASMMemoryInstance {
/* Module type */ /* Module type */
uint32 module_type; uint32 module_type;
/* Shared memory flag */ /* Shared memory flag */
@ -57,9 +57,9 @@ typedef struct WASMMemoryInstance {
Note: when memory is re-allocated, the heap data and memory data Note: when memory is re-allocated, the heap data and memory data
must be copied to new memory also. */ must be copied to new memory also. */
uint8 memory_data[1]; uint8 memory_data[1];
} WASMMemoryInstance; };
typedef struct WASMTableInstance { struct WASMTableInstance {
/* The element type, TABLE_ELEM_TYPE_ANY_FUNC currently */ /* The element type, TABLE_ELEM_TYPE_ANY_FUNC currently */
uint8 elem_type; uint8 elem_type;
/* Current size */ /* Current size */
@ -72,9 +72,9 @@ typedef struct WASMTableInstance {
#endif #endif
/* Base address */ /* Base address */
uint8 base_addr[1]; uint8 base_addr[1];
} WASMTableInstance; };
typedef struct WASMGlobalInstance { struct WASMGlobalInstance {
/* value type, VALUE_TYPE_I32/I64/F32/F64 */ /* value type, VALUE_TYPE_I32/I64/F32/F64 */
uint8 type; uint8 type;
/* mutable or constant */ /* mutable or constant */
@ -88,9 +88,9 @@ typedef struct WASMGlobalInstance {
WASMModuleInstance *import_module_inst; WASMModuleInstance *import_module_inst;
WASMGlobalInstance *import_global_inst; WASMGlobalInstance *import_global_inst;
#endif #endif
} WASMGlobalInstance; };
typedef struct WASMFunctionInstance { struct WASMFunctionInstance {
/* whether it is import function or WASM function */ /* whether it is import function or WASM function */
bool is_import_func; bool is_import_func;
/* parameter count */ /* parameter count */
@ -120,7 +120,7 @@ typedef struct WASMFunctionInstance {
WASMModuleInstance *import_module_inst; WASMModuleInstance *import_module_inst;
WASMFunctionInstance *import_func_inst; WASMFunctionInstance *import_func_inst;
#endif #endif
} WASMFunctionInstance; };
typedef struct WASMExportFuncInstance { typedef struct WASMExportFuncInstance {
char *name; char *name;
@ -144,7 +144,7 @@ typedef struct WASMExportMemInstance {
} WASMExportMemInstance; } WASMExportMemInstance;
#endif #endif
typedef struct WASMModuleInstance { struct WASMModuleInstance {
/* Module instance type, for module instance loaded from /* Module instance type, for module instance loaded from
WASM bytecode binary, this field is Wasm_Module_Bytecode; WASM bytecode binary, this field is Wasm_Module_Bytecode;
for module instance loaded from AOT file, this field is for module instance loaded from AOT file, this field is
@ -213,7 +213,7 @@ typedef struct WASMModuleInstance {
#if WASM_ENABLE_MEMORY_PROFILING != 0 #if WASM_ENABLE_MEMORY_PROFILING != 0
uint32 max_aux_stack_used; uint32 max_aux_stack_used;
#endif #endif
} WASMModuleInstance; };
struct WASMInterpFrame; struct WASMInterpFrame;
typedef struct WASMInterpFrame WASMRuntimeFrame; typedef struct WASMInterpFrame WASMRuntimeFrame;

View File

@ -238,9 +238,12 @@ void os_thread_exit(void *retval)
uint8 *os_thread_get_stack_boundary() uint8 *os_thread_get_stack_boundary()
{ {
pthread_t self = pthread_self(); pthread_t self = pthread_self();
#ifdef __linux__
pthread_attr_t attr; pthread_attr_t attr;
size_t guard_size;
#endif
uint8 *addr = NULL; uint8 *addr = NULL;
size_t stack_size, guard_size; size_t stack_size;
int page_size = getpagesize(); int page_size = getpagesize();
size_t max_stack_size = (size_t) size_t max_stack_size = (size_t)
(APP_THREAD_STACK_SIZE_MAX + page_size - 1) (APP_THREAD_STACK_SIZE_MAX + page_size - 1)

View File

@ -110,8 +110,11 @@ if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*
endif() endif()
if (NOT MSVC) if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections \ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \
-Wall -Wno-unused-parameter -Wno-pedantic") -ffunction-sections -fdata-sections \
-Wno-unused-parameter -Wno-pedantic")
# Remove the extra spaces for better make log
string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif() endif()
set (SHARED_DIR ../core/shared) set (SHARED_DIR ../core/shared)
@ -134,10 +137,6 @@ include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
include (${IWASM_DIR}/aot/iwasm_aot.cmake) include (${IWASM_DIR}/aot/iwasm_aot.cmake)
include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
endif()
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang" OR MSVC)) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang" OR MSVC))
@ -147,6 +146,8 @@ endif ()
if (NOT MSVC) if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
endif()
if (NOT (MSVC OR CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
endif() endif()
@ -154,7 +155,11 @@ endif()
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch=thunk -mfunction-return=thunk") # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch=thunk -mfunction-return=thunk")
if (NOT MSVC) if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -ftrapv -D_FORTIFY_SOURCE=2") if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -ftrapv -D_FORTIFY_SOURCE=2")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -ftrapv -D_FORTIFY_SOURCE=2")
endif()
endif() endif()
# message ("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") # message ("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")