[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Török Edvin
edwin at clamav.net
Sun Apr 4 01:02:34 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 2487a4a34207de444741a68a883983f01e4f0a3e
Author: Török Edvin <edwin at clamav.net>
Date: Fri Aug 28 20:07:25 2009 +0300
Various bytecode JIT fixes, teach clamconf about JIT, and make sure make check runs the JIT!
diff --git a/clamconf/clamconf.c b/clamconf/clamconf.c
index a1ade4d..222fa5b 100644
--- a/clamconf/clamconf.c
+++ b/clamconf/clamconf.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)) {
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index 8d63c65..5f4b231 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -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);
diff --git a/libclamav/bytecode2llvm.cpp b/libclamav/bytecode2llvm.cpp
index 34102be..4b3dc39 100644
--- a/libclamav/bytecode2llvm.cpp
+++ b/libclamav/bytecode2llvm.cpp
@@ -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;
diff --git a/libclamav/bytecode_nojit.c b/libclamav/bytecode_nojit.c
index d638795..b7662c8 100644
--- a/libclamav/bytecode_nojit.c
+++ b/libclamav/bytecode_nojit.c
@@ -57,3 +57,5 @@ int bytecode_init(void)
{
return 0;
}
+
+int have_clamjit=0;
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index 5bc6daf..ecf15ab 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -144,6 +144,7 @@ CLAMAV_PRIVATE {
messageDestroy;
base64Flush;
have_rar;
+ have_clamjit;
cli_bytecode_load;
cli_bytecode_prepare;
cli_bytecode_run;
diff --git a/unit_tests/check_bytecode.c b/unit_tests/check_bytecode.c
index 0d6f358..8d539a7 100644
--- a/unit_tests/check_bytecode.c
+++ b/unit_tests/check_bytecode.c
@@ -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
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list