[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:04:02 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit e6d1fe78ea341942c891607026d6ed8689a61fea
Author: Török Edvin <edwin at clamav.net>
Date:   Wed Sep 2 18:53:29 2009 +0300

    Apicall0 suppport for JIT.

diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index afb5401..9171c62 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -188,13 +188,26 @@ private:
     unsigned numLocals;
     unsigned numArgs;
 
+    Value *getOperand(const struct cli_bc_func *func, const Type *Ty, operand_t operand)
+    {
+	unsigned map[] = {0, 1, 2, 3, 3, 4, 4, 4, 4};
+	if (operand < func->numValues)
+	    return Values[operand];
+	unsigned w = (Ty->getPrimitiveSizeInBits()+7)/8;
+	return convertOperand(func, map[w], operand);
+    }
+
     Value *convertOperand(const struct cli_bc_func *func, const Type *Ty, operand_t operand)
     {
 	unsigned map[] = {0, 1, 2, 3, 3, 4, 4, 4, 4};
 	if (operand < func->numArgs)
 	    return Values[operand];
-	if (operand < func->numValues)
-	    return Builder.CreateLoad(Values[operand]);
+	if (operand < func->numValues) {
+	    Value *V = Values[operand];
+	    if (V->getType() == Ty)
+		return V;
+	    return Builder.CreateLoad(V);
+	}
 	unsigned w = (Ty->getPrimitiveSizeInBits()+7)/8;
 	return convertOperand(func, map[w], operand);
     }
@@ -303,6 +316,7 @@ public:
 					   BytecodeID+"f"+Twine(j), M);
 	    Functions[j]->setDoesNotThrow();
 	}
+	const Type *I32Ty = Type::getInt32Ty(Context);
 	for (unsigned j=0;j<bc->num_func;j++) {
 	    PrettyStackTraceString CrashInfo("Generate LLVM IR");
 	    const struct cli_bc_func *func = &bc->funcs[j];
@@ -350,6 +364,10 @@ public:
 			case OP_ZEXT:
 			case OP_SEXT:
 			case OP_TRUNC:
+			case OP_GEP1:
+			case OP_GEP2:
+			case OP_GEPN:
+			case OP_STORE:
 			    // these instructions represents operands differently
 			    break;
 			default:
@@ -526,6 +544,43 @@ public:
 			    Store(inst->dest, Builder.CreateCall(DestF, args.begin(), args.end()));
 			    break;
 			}
+			case OP_GEP1:
+			{
+			    Value *V = Values[inst->u.binop[0]];
+			    Value *Op = convertOperand(func, I32Ty, inst->u.binop[1]);
+			    Store(inst->dest, Builder.CreateGEP(V, Op));
+			    break;
+			}
+			case OP_GEP2:
+			{
+			    std::vector<Value*> Idxs;
+			    Value *V = Values[inst->u.three[0]];
+			    Idxs.push_back(convertOperand(func, I32Ty, inst->u.three[1]));
+			    Idxs.push_back(convertOperand(func, I32Ty, inst->u.three[2]));
+			    Store(inst->dest, Builder.CreateGEP(V, Idxs.begin(), Idxs.end()));
+			    break;
+			}
+			case OP_GEPN:
+			{
+			    std::vector<Value*> Idxs;
+			    assert(inst->u.ops.numOps > 1);
+			    Value *V = Values[inst->u.ops.ops[0]];
+			    for (unsigned a=1;a<inst->u.ops.numOps;a++)
+				Idxs.push_back(convertOperand(func, I32Ty, inst->u.ops.ops[a]));
+			    Store(inst->dest, Builder.CreateGEP(V, Idxs.begin(), Idxs.end()));
+			    break;
+			}
+			case OP_STORE:
+			{
+			    Value *Dest = convertOperand(func, inst, inst->u.binop[1]);
+			    const Type *ETy = cast<PointerType>(Dest->getType())->getElementType();
+			    Builder.CreateStore(getOperand(func, ETy, inst->u.binop[0]),
+						Dest);
+			    break;
+			}
+			case OP_LOAD:
+			    Store(inst->dest, Op0);
+			    break;
 			default:
 			    errs() << "JIT doesn't implement opcode " <<
 				inst->opcode << " yet!\n";
@@ -634,6 +689,8 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
 	OurFPM.add(new TargetData(*EE->getTargetData()));
 	// Promote allocas to registers.
 	OurFPM.add(createPromoteMemoryToRegisterPass());
+	// Delete dead instructions
+	OurFPM.add(createDeadCodeEliminationPass());
 	OurFPM.doInitialization();
 
 	LLVMTypeMapper apiMap(bcs->engine->Context, cli_apicall_types, cli_apicall_maxtypes);
diff --git a/unit_tests/check_bytecode.c b/unit_tests/check_bytecode.c
index 686cc4b..0016d5f 100644
--- a/unit_tests/check_bytecode.c
+++ b/unit_tests/check_bytecode.c
@@ -112,6 +112,14 @@ START_TEST (test_apicalls)
 }
 END_TEST
 
+START_TEST (test_apicalls2)
+{
+    cl_init(CL_INIT_DEFAULT);
+    runtest("input/apicalls2.cbc", 0xf00d, CL_SUCCESS, 0);
+//    runtest("input/apicalls2.cbc", 0xf00d, CL_SUCCESS, 1);
+}
+END_TEST
+
 START_TEST (test_div0)
 {
     cl_init(CL_INIT_DEFAULT);
@@ -130,6 +138,7 @@ Suite *test_bytecode_suite(void)
     tcase_add_test(tc_cli_arith, test_retmagic);
     tcase_add_test(tc_cli_arith, test_arith);
     tcase_add_test(tc_cli_arith, test_apicalls);
+    tcase_add_test(tc_cli_arith, test_apicalls2);
     tcase_add_test(tc_cli_arith, test_div0);
     return s;
 }
diff --git a/unit_tests/input/apicalls.cbc b/unit_tests/input/apicalls2.cbc
similarity index 51%
copy from unit_tests/input/apicalls.cbc
copy to unit_tests/input/apicalls2.cbc
index 551e0bc..ee97d74 100644
--- a/unit_tests/input/apicalls.cbc
+++ b/unit_tests/input/apicalls2.cbc
@@ -1,8 +1,10 @@
-ClamBCaa`|`````|`afafp`clamcoincidencejb
-Tedacb`bb`bb`b
-Eabaaabbed|b`acflfifoebfcfaf`gifoedgefcgdgac``
-A`b`bLacb`baab`bFadaa
-Bb`b``bbabHonnkm``odHm``oonnkdaaaadab`b`Hhgfedcbadb`babnaaaDm``odDmjnmdTcab`babE
+ClamBCaa`|`````|`ajafp`clamcoincidencejb
+Tedcabidebidacb`bb`bb`bacb`bbidb`bebed
+Eabababbgd|b`acflfifoebfcfaf`gifoedgefcgdgac``aabhd|b`acflfifoebfcfaf`gifoedgefcgdg`c``
+A`b`bLahbedbfd`b`baab`baab`bFajac
+Bbfdaacb`@d at d``eb`aab`bac`bbabHonnkm``odHm``oonnkdaaaddab`bacHhgfedcbadTaaadaaab
+Bb`bae`bbaa`Honnkmjnmdaaafdab`baeHhgfedcbadb`bagnaafDm``odDmjnmdTcab`bag
+BTcab`bDmjnmdE
 Aab`bLabahaab`bFacaa
 Baaaadaah`Bgaab`babnaaaDm``odDmjnmdTcab`babE
 Aab`bLabb`aaab`bFacaa

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list