mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-03-12 08:55:28 +00:00
Sync with internal feature (#204)
This commit is contained in:
parent
6523868a9a
commit
c6042c45a3
|
@ -109,6 +109,11 @@ enum {
|
||||||
#define WASM_ENABLE_ABS_LABEL_ADDR 0
|
#define WASM_ENABLE_ABS_LABEL_ADDR 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Enable opcode counter or not */
|
||||||
|
#ifndef WASM_ENABLE_OPCODE_COUNTER
|
||||||
|
#define WASM_ENABLE_OPCODE_COUNTER 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Heap and stack profiling */
|
/* Heap and stack profiling */
|
||||||
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
|
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
|
||||||
|
|
||||||
|
|
|
@ -149,19 +149,22 @@ apply_relocation(AOTModule *module,
|
||||||
}
|
}
|
||||||
case R_X86_64_PLT32:
|
case R_X86_64_PLT32:
|
||||||
{
|
{
|
||||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
uint8 *plt;
|
||||||
+ get_plt_item_size() * symbol_index;
|
intptr_t target_addr = 0;
|
||||||
intptr_t target_addr = (intptr_t) /* L + A - P */
|
|
||||||
(plt + reloc_addend
|
|
||||||
- (target_section_addr + reloc_offset));
|
|
||||||
|
|
||||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||||
|
|
||||||
if (symbol_index < 0) {
|
if (symbol_index >= 0) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||||
"AOT module load failed: "
|
+ get_plt_item_size() * symbol_index;
|
||||||
"invalid symbol index for relocation");
|
target_addr = (intptr_t) /* L + A - P */
|
||||||
return false;
|
(plt + reloc_addend
|
||||||
|
- (target_section_addr + reloc_offset));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target_addr = (intptr_t) /* L + A - P */
|
||||||
|
((uint8*)symbol_addr + reloc_addend
|
||||||
|
- (target_section_addr + reloc_offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int32)target_addr != target_addr) {
|
if ((int32)target_addr != target_addr) {
|
||||||
|
|
|
@ -818,7 +818,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
|
|
||||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||||
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
||||||
DEFINE_GOTO_TABLE (handle_table);
|
DEFINE_GOTO_TABLE (const void *, handle_table);
|
||||||
#undef HANDLE_OPCODE
|
#undef HANDLE_OPCODE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -697,10 +697,42 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||||
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
||||||
|
typedef struct OpcodeInfo {
|
||||||
|
char *name;
|
||||||
|
uint64 count;
|
||||||
|
} OpcodeInfo;
|
||||||
|
|
||||||
|
#define HANDLE_OPCODE(op) { #op, 0 }
|
||||||
|
DEFINE_GOTO_TABLE (OpcodeInfo, opcode_table);
|
||||||
|
#undef HANDLE_OPCODE
|
||||||
|
|
||||||
|
static void
|
||||||
|
wasm_interp_dump_op_count()
|
||||||
|
{
|
||||||
|
uint32 i;
|
||||||
|
uint64 total_count = 0;
|
||||||
|
for (i = 0; i < WASM_OP_IMPDEP; i++)
|
||||||
|
total_count += opcode_table[i].count;
|
||||||
|
|
||||||
|
printf("total opcode count: %ld\n", total_count);
|
||||||
|
for (i = 0; i < WASM_OP_IMPDEP; i++)
|
||||||
|
if (opcode_table[i].count > 0)
|
||||||
|
printf("\t\t%s count:\t\t%ld,\t\t%.2f%%\n",
|
||||||
|
opcode_table[i].name, opcode_table[i].count,
|
||||||
|
opcode_table[i].count * 100.0f / total_count);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||||
|
|
||||||
//#define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode
|
//#define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode
|
||||||
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
||||||
|
#define HANDLE_OP(opcode) HANDLE_##opcode:opcode_table[opcode].count++;h_##opcode
|
||||||
|
#else
|
||||||
#define HANDLE_OP(opcode) HANDLE_##opcode
|
#define HANDLE_OP(opcode) HANDLE_##opcode
|
||||||
|
#endif
|
||||||
#if WASM_ENABLE_FAST_INTERP == 0
|
#if WASM_ENABLE_FAST_INTERP == 0
|
||||||
#define FETCH_OPCODE_AND_DISPATCH() goto *handle_table[*frame_ip++]
|
#define FETCH_OPCODE_AND_DISPATCH() goto *handle_table[*frame_ip++]
|
||||||
#else
|
#else
|
||||||
|
@ -765,7 +797,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
|
|
||||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||||
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
||||||
DEFINE_GOTO_TABLE (handle_table);
|
DEFINE_GOTO_TABLE (const void*, handle_table);
|
||||||
#undef HANDLE_OPCODE
|
#undef HANDLE_OPCODE
|
||||||
#if WASM_ENABLE_FAST_INTERP != 0
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
if (exec_env == NULL) {
|
if (exec_env == NULL) {
|
||||||
|
@ -2287,4 +2319,7 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
||||||
FREE_FRAME(exec_env, frame);
|
FREE_FRAME(exec_env, frame);
|
||||||
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
||||||
|
wasm_interp_dump_op_count();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,8 +262,8 @@ typedef enum WASMOpcode {
|
||||||
*/
|
*/
|
||||||
#define WASM_INSTRUCTION_NUM 256
|
#define WASM_INSTRUCTION_NUM 256
|
||||||
|
|
||||||
#define DEFINE_GOTO_TABLE(_name) \
|
#define DEFINE_GOTO_TABLE(type, _name) \
|
||||||
static const void *_name[WASM_INSTRUCTION_NUM] = { \
|
static type _name[WASM_INSTRUCTION_NUM] = { \
|
||||||
HANDLE_OPCODE (WASM_OP_UNREACHABLE), /* 0x00 */ \
|
HANDLE_OPCODE (WASM_OP_UNREACHABLE), /* 0x00 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_NOP), /* 0x01 */ \
|
HANDLE_OPCODE (WASM_OP_NOP), /* 0x01 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_BLOCK), /* 0x02 */ \
|
HANDLE_OPCODE (WASM_OP_BLOCK), /* 0x02 */ \
|
||||||
|
|
|
@ -92,7 +92,7 @@ void* os_mmap(void *hint, unsigned int size, int prot, int flags)
|
||||||
|
|
||||||
ret = sgx_alloc_rsrv_mem(alignedSize);
|
ret = sgx_alloc_rsrv_mem(alignedSize);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
os_printf_sgx("os_mmap(size=%d, alignedSize=%d, prot=0x%x) failed.",size, alignedSize, prot);
|
os_printf("os_mmap(size=%d, alignedSize=%d, prot=0x%x) failed.",size, alignedSize, prot);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (prot & MMAP_PROT_READ)
|
if (prot & MMAP_PROT_READ)
|
||||||
|
@ -103,7 +103,7 @@ void* os_mmap(void *hint, unsigned int size, int prot, int flags)
|
||||||
mprot |= SGX_PROT_EXEC;
|
mprot |= SGX_PROT_EXEC;
|
||||||
st = sgx_tprotect_rsrv_mem(ret, alignedSize, mprot);
|
st = sgx_tprotect_rsrv_mem(ret, alignedSize, mprot);
|
||||||
if (st != SGX_SUCCESS){
|
if (st != SGX_SUCCESS){
|
||||||
os_printf_sgx("os_mmap(size=%d,prot=0x%x) failed to set protect.",size, prot);
|
os_printf("os_mmap(size=%d,prot=0x%x) failed to set protect.",size, prot);
|
||||||
sgx_free_rsrv_mem(ret, alignedSize);
|
sgx_free_rsrv_mem(ret, alignedSize);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,8 @@ int os_mprotect(void *addr, uint32 size, int prot)
|
||||||
if (prot & MMAP_PROT_EXEC)
|
if (prot & MMAP_PROT_EXEC)
|
||||||
mprot |= SGX_PROT_EXEC;
|
mprot |= SGX_PROT_EXEC;
|
||||||
st = sgx_tprotect_rsrv_mem(addr, size, mprot);
|
st = sgx_tprotect_rsrv_mem(addr, size, mprot);
|
||||||
if (st != SGX_SUCCESS) os_printf_sgx("os_mprotect(addr=0x%lx,size=%d,prot=0x%x) failed.", addr, size, prot);
|
if (st != SGX_SUCCESS)
|
||||||
|
os_printf("os_mprotect(addr=0x%lx,size=%d,prot=0x%x) failed.", addr, size, prot);
|
||||||
|
|
||||||
return (st == SGX_SUCCESS? 0:-1);
|
return (st == SGX_SUCCESS? 0:-1);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -8,7 +8,7 @@ DEPS_DIR=${PWD}/../../../core/deps
|
||||||
cd ${DEPS_DIR}
|
cd ${DEPS_DIR}
|
||||||
if [ ! -d "llvm" ]; then
|
if [ ! -d "llvm" ]; then
|
||||||
echo "Clone llvm to core/deps/ .."
|
echo "Clone llvm to core/deps/ .."
|
||||||
git clone --depth 1 https://github.com/llvm-mirror/llvm.git
|
git clone --depth 1 https://github.com/llvm/llvm-project.git llvm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd llvm
|
cd llvm
|
||||||
|
@ -24,7 +24,7 @@ if [ ! -f bin/llvm-lto ]; then
|
||||||
|
|
||||||
echo "Build llvm with" ${CORE_NUM} "cores"
|
echo "Build llvm with" ${CORE_NUM} "cores"
|
||||||
|
|
||||||
cmake .. \
|
cmake ../llvm \
|
||||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||||
-DCMAKE_BUILD_TYPE:STRING="Release" \
|
-DCMAKE_BUILD_TYPE:STRING="Release" \
|
||||||
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
|
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
|
||||||
|
|
|
@ -8,7 +8,7 @@ DEPS_DIR=${PWD}/../core/deps
|
||||||
cd ${DEPS_DIR}
|
cd ${DEPS_DIR}
|
||||||
if [ ! -d "llvm" ]; then
|
if [ ! -d "llvm" ]; then
|
||||||
echo "Clone llvm to core/deps/ .."
|
echo "Clone llvm to core/deps/ .."
|
||||||
git clone --depth 1 https://github.com/llvm-mirror/llvm.git
|
git clone --depth 1 https://github.com/llvm/llvm-project.git llvm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd llvm
|
cd llvm
|
||||||
|
@ -24,7 +24,7 @@ if [ ! -f bin/llvm-lto ]; then
|
||||||
|
|
||||||
echo "Build llvm with" ${CORE_NUM} "cores"
|
echo "Build llvm with" ${CORE_NUM} "cores"
|
||||||
|
|
||||||
cmake .. \
|
cmake ../llvm \
|
||||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||||
-DCMAKE_BUILD_TYPE:STRING="Release" \
|
-DCMAKE_BUILD_TYPE:STRING="Release" \
|
||||||
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
|
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user