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()
*/
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 { \
union { int64 val; uint32 parts[2]; } u; \
u.val = (value); \
@ -2936,6 +2929,13 @@ static Float64FuncPtr invokeNative_Float64 = (Float64FuncPtr)invokeNative;
static Float32FuncPtr invokeNative_Float32 = (Float32FuncPtr)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
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
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;
uint64 total_size;
uint8 *wasm_ret_types = NULL;
bool ret;
bool ret = false;
/* Check function type index */
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 */
static LLVMValueRef
call_llvm_float_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
const char *intrinsic,
bool is_f32,
...)
call_llvm_float_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
bool is_f32,
const char *intrinsic,
...)
{
va_list param_value_list;
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[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,
intrinsic,
@ -269,10 +269,10 @@ call_llvm_float_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
/* Call llvm constrained libm-equivalent intrinsic */
static LLVMValueRef
call_llvm_libm_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
const char *intrinsic,
bool is_f32,
...)
call_llvm_libm_experimental_constrained_intrinsic(AOTCompContext *comp_ctx,
bool is_f32,
const char *intrinsic,
...)
{
va_list param_value_list;
LLVMValueRef ret;
@ -281,7 +281,7 @@ call_llvm_libm_expermental_constrained_intrinsic(AOTCompContext *comp_ctx,
param_types[0] = ret_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,
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"),
"llvm build fadd fail.");
else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx,
is_f32,
(is_f32
? "llvm.experimental.constrained.fadd.f32"
: "llvm.experimental.constrained.fadd.f64"),
is_f32,
left,
right,
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"),
"llvm build fsub fail.");
else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx,
is_f32,
(is_f32
? "llvm.experimental.constrained.fsub.f32"
: "llvm.experimental.constrained.fsub.f64"),
is_f32,
left,
right,
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"),
"llvm build fmul fail.");
else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx,
is_f32,
(is_f32
? "llvm.experimental.constrained.fmul.f32"
: "llvm.experimental.constrained.fmul.f64"),
is_f32,
left,
right,
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"),
"llvm build fdiv fail.");
else
DEF_FP_BINARY_OP(call_llvm_float_expermental_constrained_intrinsic(
DEF_FP_BINARY_OP(call_llvm_float_experimental_constrained_intrinsic(
comp_ctx,
is_f32,
(is_f32
? "llvm.experimental.constrained.fdiv.f32"
: "llvm.experimental.constrained.fdiv.f64"),
is_f32,
left,
right,
comp_ctx->fp_rounding_mode,
@ -1020,9 +1020,9 @@ fail:
static LLVMValueRef
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;
LLVMValueRef ret;
@ -1030,7 +1030,7 @@ call_llvm_float_math_intrinsic(AOTCompContext *comp_ctx,
param_type = ret_type;
va_start(param_value_list, is_f32);
va_start(param_value_list, intrinsic);
ret = call_llvm_intrinsic_v(comp_ctx,
intrinsic,
@ -1051,9 +1051,9 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
switch (math_op) {
case FLOAT_ABS:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.fabs.f32" :
"llvm.fabs.f64",
is_f32,
operand),
NULL);
return true;
@ -1064,51 +1064,51 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
case FLOAT_CEIL:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.ceil.f32" :
"llvm.ceil.f64",
is_f32,
operand),
NULL);
return true;
case FLOAT_FLOOR:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32 ? "llvm.floor.f32" :
"llvm.floor.f64",
is_f32,
is_f32 ? "llvm.floor.f32":
"llvm.floor.f64",
operand),
NULL);
return true;
case FLOAT_TRUNC:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.trunc.f32" :
"llvm.trunc.f64",
is_f32,
operand),
NULL);
return true;
case FLOAT_NEAREST:
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.rint.f32" :
"llvm.rint.f64",
is_f32,
operand),
NULL);
return true;
case FLOAT_SQRT:
if (is_targeting_soft_float(comp_ctx, is_f32))
DEF_FP_UNARY_OP(call_llvm_float_math_intrinsic(comp_ctx,
is_f32,
is_f32 ? "llvm.sqrt.f32" :
"llvm.sqrt.f64",
is_f32,
operand),
NULL);
else
DEF_FP_UNARY_OP(call_llvm_libm_expermental_constrained_intrinsic(
DEF_FP_UNARY_OP(call_llvm_libm_experimental_constrained_intrinsic(
comp_ctx,
is_f32,
(is_f32
? "llvm.experimental.constrained.sqrt.f32"
: "llvm.experimental.constrained.sqrt.f64"),
is_f32,
operand,
comp_ctx->fp_rounding_mode,
comp_ctx->fp_exception_behavior),

View File

@ -195,7 +195,7 @@ typedef struct WASMImport {
} u;
} WASMImport;
typedef struct WASMFunction {
struct WASMFunction {
/* the type of function */
WASMType *func_type;
uint32 local_count;
@ -226,13 +226,13 @@ typedef struct WASMFunction {
uint8 *consts;
uint32 const_cell_num;
#endif
} WASMFunction;
};
typedef struct WASMGlobal {
struct WASMGlobal {
uint8 type;
bool is_mutable;
InitializerExpression init_expr;
} WASMGlobal;
};
typedef struct WASMExport {
char *name;
@ -281,7 +281,7 @@ typedef struct StringNode {
char *str;
} StringNode, *StringList;
typedef struct WASMModule {
struct WASMModule {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode;
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;
#endif
} WASMModule;
};
typedef struct BlockType {
/* 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 WASMGlobalInstance WASMGlobalInstance;
typedef struct WASMMemoryInstance {
struct WASMMemoryInstance {
/* Module type */
uint32 module_type;
/* Shared memory flag */
@ -57,9 +57,9 @@ typedef struct WASMMemoryInstance {
Note: when memory is re-allocated, the heap data and memory data
must be copied to new memory also. */
uint8 memory_data[1];
} WASMMemoryInstance;
};
typedef struct WASMTableInstance {
struct WASMTableInstance {
/* The element type, TABLE_ELEM_TYPE_ANY_FUNC currently */
uint8 elem_type;
/* Current size */
@ -72,9 +72,9 @@ typedef struct WASMTableInstance {
#endif
/* Base address */
uint8 base_addr[1];
} WASMTableInstance;
};
typedef struct WASMGlobalInstance {
struct WASMGlobalInstance {
/* value type, VALUE_TYPE_I32/I64/F32/F64 */
uint8 type;
/* mutable or constant */
@ -88,9 +88,9 @@ typedef struct WASMGlobalInstance {
WASMModuleInstance *import_module_inst;
WASMGlobalInstance *import_global_inst;
#endif
} WASMGlobalInstance;
};
typedef struct WASMFunctionInstance {
struct WASMFunctionInstance {
/* whether it is import function or WASM function */
bool is_import_func;
/* parameter count */
@ -120,7 +120,7 @@ typedef struct WASMFunctionInstance {
WASMModuleInstance *import_module_inst;
WASMFunctionInstance *import_func_inst;
#endif
} WASMFunctionInstance;
};
typedef struct WASMExportFuncInstance {
char *name;
@ -144,7 +144,7 @@ typedef struct WASMExportMemInstance {
} WASMExportMemInstance;
#endif
typedef struct WASMModuleInstance {
struct WASMModuleInstance {
/* Module instance type, for module instance loaded from
WASM bytecode binary, this field is Wasm_Module_Bytecode;
for module instance loaded from AOT file, this field is
@ -213,7 +213,7 @@ typedef struct WASMModuleInstance {
#if WASM_ENABLE_MEMORY_PROFILING != 0
uint32 max_aux_stack_used;
#endif
} WASMModuleInstance;
};
struct WASMInterpFrame;
typedef struct WASMInterpFrame WASMRuntimeFrame;

View File

@ -238,9 +238,12 @@ void os_thread_exit(void *retval)
uint8 *os_thread_get_stack_boundary()
{
pthread_t self = pthread_self();
#ifdef __linux__
pthread_attr_t attr;
size_t guard_size;
#endif
uint8 *addr = NULL;
size_t stack_size, guard_size;
size_t stack_size;
int page_size = getpagesize();
size_t max_stack_size = (size_t)
(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()
if (NOT MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections \
-Wall -Wno-unused-parameter -Wno-pedantic")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \
-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()
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}/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")
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))
@ -147,6 +146,8 @@ endif ()
if (NOT MSVC)
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")
endif()
@ -154,7 +155,11 @@ endif()
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch=thunk -mfunction-return=thunk")
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()
# message ("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")