Various bytecode JIT fixes, teach clamconf about JIT, and make sure make check runs the JIT!

0.96
Török Edvin 17 years ago
parent c466339d01
commit 2487a4a342
  1. 5
      clamconf/clamconf.c
  2. 1
      libclamav/bytecode.h
  3. 22
      libclamav/bytecode2llvm.cpp
  4. 2
      libclamav/bytecode_nojit.c
  5. 1
      libclamav/libclamav.map
  6. 31
      unit_tests/check_bytecode.c

@ -34,6 +34,7 @@
#include "libclamav/str.h"
#include "libclamav/clamav.h"
#include "libclamav/others.h"
#include "libclamav/bytecode.h"
static struct _cfgfile {
const char *name;
@ -288,7 +289,9 @@ int main(int argc, char **argv)
printf("BZIP2 ");
#endif
if(have_rar)
printf("RAR");
printf("RAR ");
if (have_clamjit)
printf("JIT");
printf("\n");
if(!strlen(dbdir)) {

@ -67,6 +67,7 @@ int cli_bytecode_context_clear(struct cli_bc_ctx *ctx);
uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx);
void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx);
extern int have_clamjit;
int cli_bytecode_init(struct cli_all_bc *allbc);
int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio);
int cli_bytecode_prepare(struct cli_all_bc *allbc);

@ -444,7 +444,9 @@ public:
break;
}
default:
assert(0 && "Not implemented yet");
errs() << "JIT doesn't implement opcode " <<
inst->opcode << " yet!\n";
return false;
}
}
}
@ -505,6 +507,8 @@ int cli_vm_execute_jit(const struct cli_all_bc *bcs, struct cli_bc_ctx *ctx,
int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
{
if (!bcs->engine)
return CL_EBYTECODE;
jmp_buf env;
// setup exception handler to longjmp back here
ExceptionReturn.set(&env);
@ -536,7 +540,9 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
}
EE->RegisterJITEventListener(createOProfileJITEventListener());
EE->DisableLazyCompilation();
// Due to LLVM PR4816 only X86 supports non-lazy compilation, disable
// for now.
// EE->DisableLazyCompilation();
EE->DisableSymbolSearching();
FunctionPassManager OurFPM(MP);
@ -600,10 +606,12 @@ int cli_bytecode_init_jit(struct cli_all_bc *bcs)
int cli_bytecode_done_jit(struct cli_all_bc *bcs)
{
if (bcs->engine->EE)
delete bcs->engine->EE;
delete bcs->engine;
bcs->engine = 0;
if (bcs->engine) {
if (bcs->engine->EE)
delete bcs->engine->EE;
delete bcs->engine;
bcs->engine = 0;
}
return 0;
}
@ -611,3 +619,5 @@ void cli_bytecode_debug(int argc, char **argv)
{
cl::ParseCommandLineOptions(argc, argv);
}
int have_clamjit=1;

@ -57,3 +57,5 @@ int bytecode_init(void)
{
return 0;
}
int have_clamjit=0;

@ -144,6 +144,7 @@ CLAMAV_PRIVATE {
messageDestroy;
base64Flush;
have_rar;
have_clamjit;
cli_bytecode_load;
cli_bytecode_prepare;
cli_bytecode_run;

@ -34,7 +34,7 @@
#include "../libclamav/bytecode.h"
#include "checks.h"
static void runtest(const char *file, uint64_t expected, int fail)
static void runtest(const char *file, uint64_t expected, int fail, int nojit)
{
int rc;
int fd = open_testfile(file);
@ -50,8 +50,12 @@ static void runtest(const char *file, uint64_t expected, int fail)
cl_debug();
rc = cli_bytecode_init(&bcs);
fail_unless(rc == CL_SUCCESS, "cli_bytecode_init failed");
if (!nojit) {
rc = cli_bytecode_init(&bcs);
fail_unless(rc == CL_SUCCESS, "cli_bytecode_init failed");
} else {
bcs.engine = NULL;
}
bcs.all_bcs = &bc;
bcs.count = 1;
@ -63,6 +67,10 @@ static void runtest(const char *file, uint64_t expected, int fail)
rc = cli_bytecode_prepare(&bcs);
fail_unless(rc == CL_SUCCESS, "cli_bytecode_prepare failed");
if (have_clamjit && !nojit && nojit != -1) {
fail_unless(bc.state == bc_jit, "preparing for JIT failed");
}
ctx = cli_bytecode_context_alloc();
fail_unless(!!ctx, "cli_bytecode_context_alloc failed");
@ -82,26 +90,35 @@ static void runtest(const char *file, uint64_t expected, int fail)
START_TEST (test_retmagic)
{
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS);
cl_init(CL_INIT_DEFAULT);
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS, 0);
runtest("input/retmagic.cbc", 0x1234f00d, CL_SUCCESS, 1);
}
END_TEST
START_TEST (test_arith)
{
runtest("input/arith.cbc", 0xd5555555, CL_SUCCESS);
cl_init(CL_INIT_DEFAULT);
runtest("input/arith.cbc", 0xd5555555, CL_SUCCESS, 0);
runtest("input/arith.cbc", 0xd5555555, CL_SUCCESS, 1);
}
END_TEST
START_TEST (test_apicalls)
{
runtest("input/apicalls.cbc", 0xf00d, CL_SUCCESS);
cl_init(CL_INIT_DEFAULT);
/* Not yet implemented for JIT, expect to return error */
runtest("input/apicalls.cbc", 0xf00d, CL_SUCCESS, -1);
runtest("input/apicalls.cbc", 0xf00d, CL_SUCCESS, 1);
}
END_TEST
START_TEST (test_div0)
{
cl_init(CL_INIT_DEFAULT);
/* must not crash on div#0 but catch it */
runtest("input/div0.cbc", 0, CL_EBYTECODE);
runtest("input/div0.cbc", 0, CL_EBYTECODE, 0);
runtest("input/div0.cbc", 0, CL_EBYTECODE, 1);
}
END_TEST

Loading…
Cancel
Save