[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:13:20 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit b3571ea9ae1db34044fdf1c6b5a1c6827d932037
Author: Török Edvin <edwin at clamav.net>
Date:   Wed Dec 30 12:13:40 2009 +0200

    Fix __*di3 libcalls on x86-32.
    
    On 32-bit targets LLVM emits libcalls for 64-bit operations.
    Make sure these libcalls actually map to our own functions, and not to 0.
    Also reject any other libcall we don't know about instead of mapping to 0 and crashing.

diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index 3a0e945..a320b31 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/CallingConv.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
@@ -121,6 +122,75 @@ void llvm_error_handler(void *user_data, const std::string &reason)
     jit_exception_handler();
 }
 
+// Since libgcc is not available on all compilers (for example on win32),
+// just define what these functions should do, the compiler will forward to
+// the appropriate libcall if needed.
+static int64_t rtlib_sdiv_i64(int64_t a, int64_t b)
+{
+    return a/b;
+}
+
+static uint64_t rtlib_udiv_i64(uint64_t a, uint64_t b)
+{
+    return a/b;
+}
+
+static int64_t rtlib_srem_i64(int64_t a, int64_t b)
+{
+    return a%b;
+}
+
+static uint64_t rtlib_urem_i64(uint64_t a, uint64_t b)
+{
+    return a%b;
+}
+
+static int64_t rtlib_mul_i64(uint64_t a, uint64_t b)
+{
+    return a*b;
+}
+
+static int64_t rtlib_shl_i64(int64_t a, int32_t b)
+{
+    return a << b;
+}
+
+static int64_t rtlib_srl_i64(int64_t a, int32_t b)
+{
+    return (uint64_t)a >> b;
+}
+/* Implementation independent sign-extended signed right shift */
+#ifdef HAVE_SAR
+#define CLI_SRS(n,s) ((n)>>(s))
+#else
+#define CLI_SRS(n,s) ((((n)>>(s)) ^ (1<<(sizeof(n)*8-1-s))) - (1<<(sizeof(n)*8-1-s)))
+#endif
+static int64_t rtlib_sra_i64(int64_t a, int32_t b)
+{
+    return CLI_SRS(a, b);//CLI_./..
+}
+
+// Resolve integer libcalls, but nothing else.
+static void* noUnknownFunctions(const std::string& name) {
+    void *addr =
+	StringSwitch<void*>(name)
+	.Case("__divdi3", (void*)(intptr_t)rtlib_sdiv_i64)
+	.Case("__udivdi3", (void*)(intptr_t)rtlib_udiv_i64)
+	.Case("__moddi3", (void*)(intptr_t)rtlib_srem_i64)
+	.Case("__umoddi3", (void*)(intptr_t)rtlib_urem_i64)
+	.Case("__muldi3", (void*)(intptr_t)rtlib_mul_i64)
+	.Case("__ashrdi3", (void*)(intptr_t)rtlib_sra_i64)
+	.Case("__ashldi3", (void*)(intptr_t)rtlib_shl_i64)
+	.Case("__lshrdi3", (void*)(intptr_t)rtlib_srl_i64)
+	.Default(0);
+    if (addr)
+	return addr;
+
+    std::string reason((Twine("Attempt to call external function ")+name).str());
+    llvm_error_handler(0, reason);
+    return 0;
+}
+
 class LLVMTypeMapper {
 private:
     std::vector<PATypeHolder> TypeMap;
@@ -517,7 +587,7 @@ public:
 	FHandler->setDoesNotThrow();
 	FHandler->addFnAttr(Attribute::NoInline);
 	EE->addGlobalMapping(FHandler, (void*)(intptr_t)jit_exception_handler);
-
+        EE->InstallLazyFunctionCreator(noUnknownFunctions);
 
 	std::vector<const Type*> args;
 	args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list