From 2c66acf4ee967e8397dd3d935ff14164fd4b2431 Mon Sep 17 00:00:00 2001 From: Chen Huitao Date: Mon, 18 May 2020 19:57:44 +0800 Subject: [PATCH] fix #1246 (#1254) * fix finding python path which only has python3. * fix #1246, arm host issue. * skip assembler tests on non-x86 host. * update macro of dummy value. * fix MSVC macro. * update dummy array value macro. * restore to original qemu code. --- qemu/tcg/i386/tcg-target.c | 6 ++++++ qemu/tcg/optimize.c | 3 --- qemu/tcg/tcg.c | 4 +++- tests/unit/Makefile | 9 +++++++-- tests/unit/test_mem_high.c | 3 +++ tests/unit/test_pc_change.c | 3 +++ tests/unit/unicorn_test.h | 7 +++++++ 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/qemu/tcg/i386/tcg-target.c b/qemu/tcg/i386/tcg-target.c index 7ffad8e9..fefe85a9 100644 --- a/qemu/tcg/i386/tcg-target.c +++ b/qemu/tcg/i386/tcg-target.c @@ -77,6 +77,11 @@ static const int tcg_target_call_iarg_regs[] = { TCG_REG_R8, TCG_REG_R9, #else +#ifdef _MSC_VER +#ifdef _UC_MSVC_ARRAY_DUMMY +#error "DUP DEF _UC_MSVC_ARRAY_DUMMY" +#endif +#define _UC_MSVC_ARRAY_DUMMY /* 32 bit mode uses stack based calling convention (GCC default). We add a dummy value here for MSVC compatibility for the error: "error C2466: cannot allocate an array of constant size 0" @@ -85,6 +90,7 @@ static const int tcg_target_call_iarg_regs[] = { */ 0, #endif +#endif }; static const int tcg_target_call_oarg_regs[] = { diff --git a/qemu/tcg/optimize.c b/qemu/tcg/optimize.c index 6793761a..8693ebff 100644 --- a/qemu/tcg/optimize.c +++ b/qemu/tcg/optimize.c @@ -574,9 +574,6 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, /* Do copy propagation */ for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { - if (args[i] >= TCG_MAX_TEMPS) { - return NULL; - } if (temps[args[i]].state == TCG_TEMP_COPY) { args[i] = find_better_copy(s, args[i]); } diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index 20f08821..679836ae 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -2378,8 +2378,10 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def, flags = args[nb_oargs + nb_iargs + 1]; nb_regs = ARRAY_SIZE(tcg_target_call_iarg_regs); -#if TCG_TARGET_REG_BITS == 32 +#ifdef _UC_MSVC_ARRAY_DUMMY // do this because msvc cannot have arrays with 0 entries. + /* ref: tcg/i386/tcg-target.c: tcg_target_call_iarg_regs, + it is added a dummy value, set back to 0. */ nb_regs = 0; #endif if (nb_regs > nb_params) { diff --git a/tests/unit/Makefile b/tests/unit/Makefile index a856356d..c0704d34 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile @@ -7,6 +7,7 @@ ASFLAGS += --32 OBJCOPY = objcopy UNAME_S := $(shell uname -s) +UNAME_M := $(shell uname -m) LDLIBS += -pthread ifeq ($(UNAME_S), Linux) LDLIBS += -lrt @@ -32,12 +33,16 @@ TEST_PROGS = $(TEST_ASSEMBLY:%.s=%.o) TEST_BINS = $(TEST_PROGS:%.o=%.bin) ALL_TESTS = $(ALL_TESTS_SOURCES:%.c=%) +ifneq (,$(findstring x86,$(UNAME_M))) +ALL_TESTS += $(TEST_BINS) +endif + .PHONY: all -all: ${TEST_BINS} ${ALL_TESTS} +all: ${ALL_TESTS} .PHONY: clean clean: - rm -rf ${TEST_BINS} ${ALL_TESTS} + rm -rf ${ALL_TESTS} %.bin: %.o ${OBJCOPY} -O binary $^ $@ diff --git a/tests/unit/test_mem_high.c b/tests/unit/test_mem_high.c index 7e410497..ab277bf4 100644 --- a/tests/unit/test_mem_high.c +++ b/tests/unit/test_mem_high.c @@ -92,6 +92,9 @@ static void test_high_address_read_values(void **state) uc_engine *uc = *state; struct stat info; char * code = read_file("high_address.bin", &info); + if (code == NULL) { + return; + } uint64_t addr = 0x0010000000000001; //addr = 0x000ffffffffffff8; // uncomment to fix wrong behaviour diff --git a/tests/unit/test_pc_change.c b/tests/unit/test_pc_change.c index 6c844aa4..c513e6b7 100644 --- a/tests/unit/test_pc_change.c +++ b/tests/unit/test_pc_change.c @@ -57,6 +57,9 @@ static void test_pc_change(void **state) int32_t r_ecx = 3, r_edx = 15; struct stat info; char *code = read_file("pc_change.bin", &info); + if (code == NULL) { + return; + } #define BASEADDR 0x1000000 diff --git a/tests/unit/unicorn_test.h b/tests/unit/unicorn_test.h index 8899bc9f..fa695d9a 100644 --- a/tests/unit/unicorn_test.h +++ b/tests/unit/unicorn_test.h @@ -42,7 +42,14 @@ do { \ char * read_file(const char *filename, struct stat *info) { stat(filename, info); char *code = malloc(info->st_size); + if (code == NULL) { + return NULL; + } FILE *fp = fopen(filename, "r"); + if (fp == NULL) { + free(code); + return NULL; + } fread(code, info->st_size, 1, fp); return code; }