From: Brendan Hansen Date: Thu, 7 Jul 2022 03:20:47 +0000 (-0500) Subject: bugfixes; most test cases pass X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5122a2f098277a4f67a667301a3a9a899d785221;p=onyx-embedder.git bugfixes; most test cases pass --- diff --git a/build.sh b/build.sh index 160e456..e4095d8 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ CC="gcc" WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op' -FLAGS="-g3" +FLAGS="-O3" LIBS="-pthread" INCLUDES="-I include" TARGET="libonyx_embedder.so" diff --git a/include/bh.h b/include/bh.h index 55c9408..9ce04ef 100644 --- a/include/bh.h +++ b/include/bh.h @@ -4,7 +4,11 @@ #ifdef BH_STATIC #define BH_DEF static #else - #define BH_DEF + #ifdef BH_INTERNAL + #define BH_DEF __attribute__((visibility("hidden"))) + #else + #define BH_DEF + #endif #endif // NOTE: For lseek64 @@ -1396,15 +1400,16 @@ BH_DEF i64 leb128_to_int(u8* bytes, i32 *byte_count) { u64 size = 64; u8 byte; - while (1) { + do { byte = bytes[(*byte_count)++]; res |= (byte & 0x7f) << shift; - if ((byte & 0x80) == 0) break; shift += 7; - } + } while ((byte & 0x80) != 0); if ((shift < size) && (byte & 0x40) != 0) { - return res | ((~(u64) 0x0) << shift); + i64 zero_shifted = ~ 0x0; + zero_shifted = zero_shifted << shift; + return res | zero_shifted; } return res; diff --git a/src/vm/code_builder.c b/src/vm/code_builder.c index 4f60d2c..41dd1af 100644 --- a/src/vm/code_builder.c +++ b/src/vm/code_builder.c @@ -14,7 +14,7 @@ static inline int NEXT_VALUE(ovm_code_builder_t *b) { #if defined(BUILDER_DEBUG) b->highest_value_number += 1; - return b->highest_value_number; + return b->highest_value_number - 1; #else if (bh_arr_length(b->execution_stack) == 0) { diff --git a/src/vm/vm.c b/src/vm/vm.c index 30fde47..6ce7cef 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -917,6 +917,7 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t case OVMI_MOV: VAL(instr.r) = VAL(instr.a); + // printf("$%d = %lx\n", instr.r, VAL(instr.r).u64); break; #define OVM_LOAD(type_, stype) \ @@ -1022,6 +1023,7 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t i32 fidx = func_idx; \ ovm_func_t *func = &program->funcs[fidx]; \ i32 extra_params = bh_arr_length(state->params) - func->param_count; \ + assert(extra_params >= 0); \ if (func->kind == OVM_FUNC_INTERNAL) { \ ovm__func_setup_stack_frame(engine, state, program, fidx, instr.r); \ \ diff --git a/src/wasm.c b/src/wasm.c index 5a06b09..83fed31 100644 --- a/src/wasm.c +++ b/src/wasm.c @@ -1,5 +1,6 @@ #define BH_DEFINE #define BH_NO_TABLE +#define BH_INTERNAL #define STB_DS_IMPLEMENTATION #include "bh.h" #include "stb_ds.h" diff --git a/src/wasm/module_parsing.c.incl b/src/wasm/module_parsing.c.incl index 2b09548..7ee0fce 100644 --- a/src/wasm/module_parsing.c.incl +++ b/src/wasm/module_parsing.c.incl @@ -697,7 +697,7 @@ static void parse_instruction(build_context *ctx) { } case 0x42: { - unsigned long long value = uleb128_to_uint(ctx->binary.data, &ctx->offset); + long long value = leb128_to_int(ctx->binary.data, &ctx->offset); ovm_code_builder_add_imm(&ctx->builder, OVM_TYPE_I64, &value); break; }