summaryrefslogtreecommitdiff
path: root/libre/clamav
diff options
context:
space:
mode:
authorAndré Fabian Silva Delgado <emulatorman@parabola.nu>2017-02-12 00:34:27 -0300
committerAndré Fabian Silva Delgado <emulatorman@parabola.nu>2017-02-12 00:34:27 -0300
commit11f487197951270623cfcb9cd3022d1ad544291c (patch)
tree82f9fdf32c7d9fbdb149eb1afebb5052d3da404d /libre/clamav
parente82f7af6cbb12e9c630e4c408ae1898a4134367b (diff)
clamav-0.99.2-3.parabola1: build against current LLVM
Diffstat (limited to 'libre/clamav')
-rw-r--r--libre/clamav/Add-support-for-LLVM-3.7.patch740
-rw-r--r--libre/clamav/Add-support-for-LLVM-3.8.patch457
-rw-r--r--libre/clamav/Add-support-for-LLVM-3.9.patch76
-rw-r--r--libre/clamav/PKGBUILD41
4 files changed, 1298 insertions, 16 deletions
diff --git a/libre/clamav/Add-support-for-LLVM-3.7.patch b/libre/clamav/Add-support-for-LLVM-3.7.patch
new file mode 100644
index 000000000..8bcd1d7ea
--- /dev/null
+++ b/libre/clamav/Add-support-for-LLVM-3.7.patch
@@ -0,0 +1,740 @@
+From 3b1b2e757d0d1f13a3f234abf05d6e5015f52744 Mon Sep 17 00:00:00 2001
+From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
+Date: Fri, 14 Oct 2016 20:24:39 +0200
+Subject: Add support for LLVM 3.7
+
+Main changes:
+The DataLayoutPass is no longer necessary.
+The LoopInfo pass is now a WrapperPass.
+Before creating TargetLibraryInfo one needs to create a
+TargetLibraryInfoImpl.
+PassManager is now in the legacy:: namespace.
+GetElementPtrInst::getIndexedType changed behavior causing segfaults in
+the testsuite; emulating the old behavior now.
+CreateCallX functions for fixed number X of elements got removed.
+JITEmitDebugInfo Option was removed.
+DIDescriptor was removed.
+
+Patch-Name: Add-support-for-LLVM-3.7.patch
+---
+ libclamav/c++/ClamBCRTChecks.cpp | 34 ++++++-
+ libclamav/c++/PointerTracking.cpp | 44 ++++++++-
+ libclamav/c++/bytecode2llvm.cpp | 181 +++++++++++++++++++++++++++++++++++---
+ libclamav/c++/m4/llvm-flags.m4 | 4 +-
+ 4 files changed, 244 insertions(+), 19 deletions(-)
+
+diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp
+index 97099b2..35f7272 100644
+--- a/libclamav/c++/ClamBCRTChecks.cpp
++++ b/libclamav/c++/ClamBCRTChecks.cpp
+@@ -201,9 +201,11 @@ namespace llvm {
+ TD = &getAnalysis<TargetData>();
+ #elif LLVM_VERSION < 35
+ TD = &getAnalysis<DataLayout>();
+-#else
++#elif LLVM_VERSION < 37
+ DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
+ TD = DLP ? &DLP->getDataLayout() : 0;
++#else
++ TD = &F.getEntryBlock().getModule()->getDataLayout();
+ #endif
+ SE = &getAnalysis<ScalarEvolution>();
+ PT = &getAnalysis<PointerTracking>();
+@@ -212,7 +214,11 @@ namespace llvm {
+ #else
+ DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ #endif
++#if LLVM_VERSION < 37
+ expander = new SCEVExpander(*SE OPT("SCEVexpander"));
++#else
++ expander = new SCEVExpander(*SE, *TD OPT("SCEVexpander"));
++#endif
+
+ std::vector<Instruction*> insns;
+
+@@ -351,8 +357,10 @@ namespace llvm {
+ AU.addRequired<TargetData>();
+ #elif LLVM_VERSION < 35
+ AU.addRequired<DataLayout>();
+-#else
++#elif LLVM_VERSION < 37
+ AU.addRequired<DataLayoutPass>();
++#else
++ // No DataLayout pass needed anymore.
+ #endif
+ #if LLVM_VERSION < 35
+ AU.addRequired<DominatorTree>();
+@@ -406,7 +414,11 @@ namespace llvm {
+ if (BaseMap.count(P)) {
+ return BaseMap[Ptr] = BaseMap[P];
+ }
++#if LLVM_VERSION < 37
+ Value *P2 = GetUnderlyingObject(P, TD);
++#else
++ Value *P2 = GetUnderlyingObject(P, *TD);
++#endif
+ if (P2 != P) {
+ Value *V = getPointerBase(P2);
+ return BaseMap[Ptr] = V;
+@@ -524,7 +536,11 @@ namespace llvm {
+ }
+ }
+ if (LoadInst *LI = dyn_cast<LoadInst>(Base)) {
++#if LLVM_VERSION < 37
+ Value *V = GetUnderlyingObject(LI->getPointerOperand()->stripPointerCasts(), TD);
++#else
++ Value *V = GetUnderlyingObject(LI->getPointerOperand()->stripPointerCasts(), *TD);
++#endif
+ if (Argument *A = dyn_cast<Argument>(V)) {
+ if (A->getArgNo() == 0) {
+ // pointers from hidden ctx are trusted to be at least the
+@@ -651,7 +667,11 @@ namespace llvm {
+ }
+ BasicBlock *BB = I->getParent();
+ BasicBlock::iterator It = I;
++#if LLVM_VERSION < 37
+ BasicBlock *newBB = SplitBlock(BB, &*It, this);
++#else
++ BasicBlock *newBB = SplitBlock(BB, &*It);
++#endif
+ PHINode *PN;
+ unsigned MDDbgKind = I->getContext().getMDKindID("dbg");
+ //verifyFunction(*BB->getParent());
+@@ -696,9 +716,15 @@ namespace llvm {
+ unsigned locationid = 0;
+ bool Approximate;
+ if (MDNode *Dbg = getLocation(I, Approximate, MDDbgKind)) {
++#if LLVM_VERSION < 37
+ DILocation Loc(Dbg);
+ locationid = Loc.getLineNumber() << 8;
+ unsigned col = Loc.getColumnNumber();
++#else
++ DebugLoc Loc(Dbg);
++ locationid = Loc.getLine() << 8;
++ unsigned col = Loc.getCol();
++#endif
+ if (col > 254)
+ col = 254;
+ if (Approximate)
+@@ -912,7 +938,11 @@ INITIALIZE_PASS_DEPENDENCY(TargetData)
+ #elif LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DataLayout)
+ #else
++#if LLVM_VERSION < 37
+ INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
++#else
++// No DataLayout pass needed anymore.
++#endif
+ #endif
+ #if LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+diff --git a/libclamav/c++/PointerTracking.cpp b/libclamav/c++/PointerTracking.cpp
+index 8e17a4a..67340e8 100644
+--- a/libclamav/c++/PointerTracking.cpp
++++ b/libclamav/c++/PointerTracking.cpp
+@@ -30,7 +30,11 @@
+ #include "llvm/IR/InstIterator.h"
+ #endif
+ #include "llvm/Support/raw_ostream.h"
++#if LLVM_VERSION < 37
+ #include "llvm/Target/TargetLibraryInfo.h"
++#else
++#include <llvm/Analysis/TargetLibraryInfo.h>
++#endif
+
+ #if LLVM_VERSION < 32
+ #include "llvm/Target/TargetData.h"
+@@ -70,7 +74,11 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+ #else
+ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+ #endif
++#if LLVM_VERSION < 37
+ INITIALIZE_PASS_DEPENDENCY(LoopInfo)
++#else
++INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
++#endif
+ INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
+ #if LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+@@ -96,12 +104,18 @@ bool PointerTracking::runOnFunction(Function &F) {
+ TD = getAnalysisIfAvailable<TargetData>();
+ #elif LLVM_VERSION < 35
+ TD = getAnalysisIfAvailable<DataLayout>();
+-#else
++#elif LLVM_VERSION < 37
+ DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
+ TD = DLP ? &DLP->getDataLayout() : 0;
++#else
++ TD = &F.getEntryBlock().getModule()->getDataLayout();
+ #endif
+ SE = &getAnalysis<ScalarEvolution>();
++#if LLVM_VERSION < 37
+ LI = &getAnalysis<LoopInfo>();
++#else
++ LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
++#endif
+ #if LLVM_VERSION < 35
+ DT = &getAnalysis<DominatorTree>();
+ #else
+@@ -116,7 +130,11 @@ void PointerTracking::getAnalysisUsage(AnalysisUsage &AU) const {
+ #else
+ AU.addRequiredTransitive<DominatorTreeWrapperPass>();
+ #endif
++#if LLVM_VERSION < 37
+ AU.addRequiredTransitive<LoopInfo>();
++#else
++ AU.addRequiredTransitive<LoopInfoWrapperPass>();
++#endif
+ AU.addRequiredTransitive<ScalarEvolution>();
+ AU.setPreservesAll();
+ }
+@@ -178,12 +196,19 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P,
+ if (CallInst *CI = extractMallocCall(V)) {
+ Value *arraySize = getMallocArraySize(CI, TD);
+ constType* AllocTy = getMallocAllocatedType(CI);
+-#else
++#elif LLVM_VERSION < 37
+ TargetLibraryInfo* TLI = new TargetLibraryInfo();
+
+ if (CallInst *CI = extractMallocCall(V, TLI)) {
+ Value *arraySize = getMallocArraySize(CI, TD, TLI);
+ constType* AllocTy = getMallocAllocatedType(CI, TLI);
++#else
++ TargetLibraryInfoImpl* TLII = new TargetLibraryInfoImpl();
++ TargetLibraryInfo* TLI = new TargetLibraryInfo(*TLII);
++
++ if (CallInst *CI = extractMallocCall(V, TLI)) {
++ Value *arraySize = getMallocArraySize(CI, *TD, TLI);
++ constType* AllocTy = getMallocAllocatedType(CI, TLI);
+ #endif
+ if (!AllocTy || !arraySize) return SE->getCouldNotCompute();
+ Ty = AllocTy;
+@@ -240,7 +265,7 @@ Value *PointerTracking::computeAllocationCountValue(Value *P, constType *&Ty) co
+ if (!Ty)
+ return 0;
+ Value *arraySize = getMallocArraySize(CI, TD);
+-#else
++#elif LLVM_VERSION < 37
+ TargetLibraryInfo* TLI = new TargetLibraryInfo();
+
+ if (CallInst *CI = extractMallocCall(V, TLI)) {
+@@ -248,6 +273,15 @@ Value *PointerTracking::computeAllocationCountValue(Value *P, constType *&Ty) co
+ if (!Ty)
+ return 0;
+ Value *arraySize = getMallocArraySize(CI, TD, TLI);
++#else
++ TargetLibraryInfoImpl* TLII = new TargetLibraryInfoImpl();
++ TargetLibraryInfo* TLI = new TargetLibraryInfo(*TLII);
++
++ if (CallInst *CI = extractMallocCall(V, TLI)) {
++ Ty = getMallocAllocatedType(CI, TLI);
++ if (!Ty)
++ return 0;
++ Value *arraySize = getMallocArraySize(CI, *TD, TLI);
+ #endif
+ if (!arraySize) {
+ Ty = Type::getInt8Ty(P->getContext());
+@@ -351,7 +385,11 @@ void PointerTracking::getPointerOffset(Value *Pointer, Value *&Base,
+ const SCEV *&Offset) const
+ {
+ Pointer = Pointer->stripPointerCasts();
++#if LLVM_VERSION < 37
+ Base = GetUnderlyingObject(Pointer, TD);
++#else
++ Base = GetUnderlyingObject(Pointer, *TD);
++#endif
+ Limit = getAllocationSizeInBytes(Base);
+ if (isa<SCEVCouldNotCompute>(Limit)) {
+ Base = 0;
+diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
+index e5aea03..2171993 100644
+--- a/libclamav/c++/bytecode2llvm.cpp
++++ b/libclamav/c++/bytecode2llvm.cpp
+@@ -63,7 +63,11 @@
+ #include "llvm/Object/ObjectFile.h"
+ #endif
+ #include "llvm/ExecutionEngine/JITEventListener.h"
++#if LLVM_VERSION < 37
+ #include "llvm/PassManager.h"
++#else
++#include "llvm/IR/LegacyPassManager.h"
++#endif
+ #include "llvm/Support/Compiler.h"
+ #include "llvm/Support/Debug.h"
+ #include "llvm/Support/CommandLine.h"
+@@ -231,7 +235,9 @@ namespace {
+ #define llvm_report_error(x) report_fatal_error(x)
+ #define llvm_install_error_handler(x) install_fatal_error_handler(x)
+ #define DwarfExceptionHandling JITExceptionHandling
++#if LLVM_VERSION < 37
+ #define SetCurrentDebugLocation(x) SetCurrentDebugLocation(DebugLoc::getFromDILocation(x))
++#endif
+ #define DEFINEPASS(passname) passname() : FunctionPass(ID)
+ #else
+ #define DEFINEPASS(passname) passname() : FunctionPass(&ID)
+@@ -718,7 +724,11 @@ class RuntimeLimits : public FunctionPass {
+ BBMap[BB] = apicalls;
+ }
+ if (!BackedgeTargets.empty()) {
++#if LLVM_VERSION < 37
+ LoopInfo &LI = getAnalysis<LoopInfo>();
++#else
++ LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
++#endif
+ ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
+
+ // Now check whether any of these backedge targets are part of a loop
+@@ -802,7 +812,11 @@ class RuntimeLimits : public FunctionPass {
+ #endif
+ // Load Flag that tells us we timed out (first byte in bc_ctx)
+ Value *Cond = Builder.CreateLoad(Flag, true);
++#if LLVM_VERSION < 37
+ BasicBlock *newBB = SplitBlock(BB, BB->getTerminator(), this);
++#else
++ BasicBlock *newBB = SplitBlock(BB, BB->getTerminator());
++#endif
+ TerminatorInst *TI = BB->getTerminator();
+ BranchInst::Create(AbrtBB, newBB, Cond, TI);
+ TI->eraseFromParent();
+@@ -823,7 +837,11 @@ class RuntimeLimits : public FunctionPass {
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
++#if LLVM_VERSION < 37
+ AU.addRequired<LoopInfo>();
++#else
++ AU.addRequired<LoopInfoWrapperPass>();
++#endif
+ AU.addRequired<ScalarEvolution>();
+ #if LLVM_VERSION < 35
+ AU.addRequired<DominatorTree>();
+@@ -916,7 +934,11 @@ class LLVMCodegen {
+ Module *M;
+ LLVMContext &Context;
+ ExecutionEngine *EE;
++#if LLVM_VERSION < 37
+ FunctionPassManager &PM, &PMUnsigned;
++#else
++ legacy::FunctionPassManager &PM, &PMUnsigned;
++#endif
+ LLVMTypeMapper *TypeMap;
+
+ Function **apiFuncs;
+@@ -1089,7 +1111,11 @@ class LLVMCodegen {
+ Constant *C = ConstantExpr::getPointerCast(GV, IP8Ty);
+ //TODO: check constant bounds here
+ return ConstantExpr::getPointerCast(
++#if LLVM_VERSION < 37
+ ConstantExpr::getInBoundsGetElementPtr(C, ARRAYREF(Value*, idxs, 1)),
++#else
++ ConstantExpr::getInBoundsGetElementPtr(Ty, C, ARRAYREF(Value*, idxs, 1)),
++#endif
+ PTy);
+ }
+ if (isa<IntegerType>(Ty)) {
+@@ -1118,15 +1144,21 @@ class LLVMCodegen {
+
+ public:
+ LLVMCodegen(const struct cli_bc *bc, Module *M, struct CommonFunctions *CF, FunctionMapTy &cFuncs,
++#if LLVM_VERSION < 37
+ ExecutionEngine *EE, FunctionPassManager &PM, FunctionPassManager &PMUnsigned,
++#else
++ ExecutionEngine *EE, legacy::FunctionPassManager &PM, legacy::FunctionPassManager &PMUnsigned,
++#endif
+ Function **apiFuncs, LLVMTypeMapper &apiMap)
+ : bc(bc), M(M), Context(M->getContext()), EE(EE),
+ PM(PM),PMUnsigned(PMUnsigned), TypeMap(), apiFuncs(apiFuncs),apiMap(apiMap),
+ compiledFunctions(cFuncs), BytecodeID("bc"+Twine(bc->id)),
+ #if LLVM_VERSION < 32
+ Folder(EE->getTargetData()), Builder(Context, Folder), Values(), CF(CF) {
+-#else
++#elif LLVM_VERSION < 37
+ Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
++#else
++ Folder(*EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
+ #endif
+
+ for (unsigned i=0;i<cli_apicall_maxglobal - _FIRST_GLOBAL;i++) {
+@@ -1141,7 +1173,17 @@ class LLVMCodegen {
+ template <typename InputIterator>
+ #endif
+ Value* createGEP(Value *Base, constType *ETy, ARRAYREFPARAM(Value*,InputIterator Start,InputIterator End,ARef)) {
++#if LLVM_VERSION < 37
+ constType *Ty = GetElementPtrInst::getIndexedType(Base->getType(),ARRAYREFP(Start,End,ARef));
++#else
++ Type *Ty = NULL;
++ // This used to be done internally in LLVM's getIndexedTypeInternal.
++ PointerType *PTy = dyn_cast<PointerType>(Base->getType()->getScalarType());
++ if (PTy) {
++ Type *Agg = PTy->getElementType();
++ Ty = GetElementPtrInst::getIndexedType(Agg,ARRAYREFP(Start,End,ARef));
++ }
++#endif
+ if (!Ty || (ETy && (Ty != ETy && (!isa<IntegerType>(Ty) || !isa<IntegerType>(ETy))))) {
+ if (cli_debug_flag) {
+ std::string str;
+@@ -1457,7 +1499,11 @@ class LLVMCodegen {
+ if (func->dbgnodes[c] != ~0u) {
+ unsigned j = func->dbgnodes[c];
+ assert(j < mdnodes.size());
++#if LLVM_VERSION < 37
+ Builder.SetCurrentDebugLocation(mdnodes[j]);
++#else
++ Builder.SetCurrentDebugLocation(DebugLoc(mdnodes[j]));
++#endif
+ } else
+ Builder.SetCurrentDebugLocation(0);
+ }
+@@ -1767,11 +1813,16 @@ class LLVMCodegen {
+ #if LLVM_VERSION < 29
+ CallInst *c = Builder.CreateCall4(CF->FMemset, Dst, Val, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1));
+-#else
++#elif LLVM_VERSION < 37
+ CallInst *c = Builder.CreateCall5(CF->FMemset, Dst, Val, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1),
+ ConstantInt::get(Type::getInt1Ty(Context), 0)
+ );
++#else
++ Value *args[] = { Dst, Val, Len,
++ ConstantInt::get(Type::getInt32Ty(Context), 1),
++ ConstantInt::get(Type::getInt1Ty(Context), 0)};
++ CallInst *c = Builder.CreateCall(CF->FMemset, ARRAYREF(Value*, args, args + 5));
+ #endif
+ c->setTailCall(true);
+ c->setDoesNotThrow();
+@@ -1788,11 +1839,16 @@ class LLVMCodegen {
+ #if LLVM_VERSION < 29
+ CallInst *c = Builder.CreateCall4(CF->FMemcpy, Dst, Src, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1));
+-#else
++#elif LLVM_VERSION < 37
+ CallInst *c = Builder.CreateCall5(CF->FMemcpy, Dst, Src, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1),
+ ConstantInt::get(Type::getInt1Ty(Context), 0)
+ );
++#else
++ Value *args[] = { Dst, Src, Len,
++ ConstantInt::get(Type::getInt32Ty(Context), 1),
++ ConstantInt::get(Type::getInt1Ty(Context), 0)};
++ CallInst *c = Builder.CreateCall(CF->FMemcpy, ARRAYREF(Value*, args, args + 5));
+ #endif
+ c->setTailCall(true);
+ c->setDoesNotThrow();
+@@ -1809,10 +1865,15 @@ class LLVMCodegen {
+ #if LLVM_VERSION < 29
+ CallInst *c = Builder.CreateCall4(CF->FMemmove, Dst, Src, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1));
+-#else
++#elif LLVM_VERSION < 37
+ CallInst *c = Builder.CreateCall5(CF->FMemmove, Dst, Src, Len,
+ ConstantInt::get(Type::getInt32Ty(Context), 1),
+ ConstantInt::get(Type::getInt1Ty(Context), 0));
++#else
++ Value *args[] = {Dst, Src, Len,
++ ConstantInt::get(Type::getInt32Ty(Context), 1),
++ ConstantInt::get(Type::getInt1Ty(Context), 0)};
++ CallInst *c = Builder.CreateCall(CF->FMemmove, args);
+ #endif
+ c->setTailCall(true);
+ c->setDoesNotThrow();
+@@ -1830,7 +1891,12 @@ class LLVMCodegen {
+ #else
+ Value *Len = convertOperand(func, EE->getDataLayout()->getIntPtrType(Context), inst->u.three[2]);
+ #endif
++#if LLVM_VERSION < 37
+ CallInst *c = Builder.CreateCall3(CF->FRealmemcmp, Dst, Src, Len);
++#else
++ Value *args[] = {Dst, Src, Len};
++ CallInst *c = Builder.CreateCall(CF->FRealmemcmp, ARRAYREF(Value*, args, args + 3));
++#endif
+ c->setTailCall(true);
+ c->setDoesNotThrow();
+ Store(inst->dest, c);
+@@ -2211,7 +2277,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
+ }
+ #if LLVM_VERSION >= 29
+ INITIALIZE_PASS_BEGIN(RuntimeLimits, "rl", "Runtime Limits", false, false)
++#if LLVM_VERSION < 37
+ INITIALIZE_PASS_DEPENDENCY(LoopInfo)
++#else
++INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
++#endif
+ INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
+ #if LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+@@ -2437,8 +2507,10 @@ static void addFPasses(FunctionPassManager &FPM, bool trusted, const TargetData
+ static void addFPasses(FunctionPassManager &FPM, bool trusted, const DataLayout *TD)
+ #elif LLVM_VERSION < 36
+ static void addFPasses(FunctionPassManager &FPM, bool trusted, const Module *M)
+-#else
++#elif LLVM_VERSION < 37
+ static void addFPasses(FunctionPassManager &FPM, bool trusted, Module *M)
++#else
++static void addFPasses(legacy::FunctionPassManager &FPM, bool trusted, Module *M)
+ #endif
+ {
+ // Set up the optimizer pipeline. Start with registering info about how
+@@ -2449,10 +2521,12 @@ static void addFPasses(FunctionPassManager &FPM, bool trusted, Module *M)
+ FPM.add(new DataLayout(*TD));
+ #elif LLVM_VERSION < 36
+ FPM.add(new DataLayoutPass(M));
+-#else
++#elif LLVM_VERSION < 37
+ DataLayoutPass *DLP = new DataLayoutPass();
+ DLP->doInitialization(*M);
+ FPM.add(DLP);
++#else
++ // No DataLayout pass needed anymore.
+ #endif
+ // Promote allocas to registers.
+ FPM.add(createPromoteMemoryToRegisterPass());
+@@ -2482,6 +2556,8 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+
+ #if LLVM_VERSION >= 31
+ TargetOptions Options;
++#if LLVM_VERSION < 37
++ // This option was removed.
+ #ifdef CL_DEBUG
+ //disable this for now, it leaks
+ Options.JITEmitDebugInfo = false;
+@@ -2489,6 +2565,7 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+ #else
+ Options.JITEmitDebugInfo = false;
+ #endif
++#endif
+ #if LLVM_VERSION < 34
+ Options.DwarfExceptionHandling = false;
+ #else
+@@ -2525,7 +2602,11 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+ struct CommonFunctions CF;
+ addFunctionProtos(&CF, EE, M);
+
++#if LLVM_VERSION < 37
+ FunctionPassManager OurFPM(M), OurFPMUnsigned(M);
++#else
++ legacy::FunctionPassManager OurFPM(M), OurFPMUnsigned(M);
++#endif
+ #if LLVM_VERSION < 32
+ M->setDataLayout(EE->getTargetData()->getStringRepresentation());
+ #else
+@@ -2665,17 +2746,23 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+ break;
+ }
+ }
++#if LLVM_VERSION < 37
+ PassManager PM;
++#else
++ legacy::PassManager PM;
++#endif
+ #if LLVM_VERSION < 32
+ PM.add(new TargetData(*EE->getTargetData()));
+ #elif LLVM_VERSION < 35
+ PM.add(new DataLayout(*EE->getDataLayout()));
+ #elif LLVM_VERSION < 36
+ PM.add(new DataLayoutPass(M));
+-#else
++#elif LLVM_VERSION < 37
+ DataLayoutPass *DLP = new DataLayoutPass();
+ DLP->doInitialization(*M);
+ PM.add(DLP);
++#else
++ // No DataLayout pass needed anymore.
+ #endif
+ // TODO: only run this on the untrusted bytecodes, not all of them...
+ if (has_untrusted)
+@@ -2987,11 +3074,19 @@ static Metadata *findDbgGlobalDeclare(GlobalVariable *V) {
+ return 0;
+
+ for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
++#if LLVM_VERSION < 37
+ DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i)));
+ if (!DIG.isGlobalVariable())
+ continue;
+ if (DIGlobalVariable(DIG).getGlobal() == V)
+ return DIG;
++#else
++ MDNode *DIG = NMD->getOperand(i);
++ if (!DIGlobalVariable::classof(DIG))
++ continue;
++ if ((cast<DIGlobalVariable>(DIG))->getVariable() == V)
++ return DIG;
++#endif
+ }
+ return 0;
+ }
+@@ -3008,11 +3103,19 @@ static Metadata *findDbgSubprogramDeclare(Function *V) {
+ return 0;
+
+ for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
++#if LLVM_VERSION < 37
+ DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i)));
+ if (!DIG.isSubprogram())
+ continue;
+ if (DISubprogram(DIG).getFunction() == V)
+ return DIG;
++#else
++ MDNode *DIG = NMD->getOperand(i);
++ if (!DISubprogram::classof(DIG))
++ continue;
++ if ((cast<DISubprogram>(DIG))->getFunction() == V)
++ return DIG;
++#endif
+ }
+ return 0;
+ }
+@@ -3061,22 +3164,39 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
+ Metadata *DIGV = findDbgGlobalDeclare(GV);
+ #endif
+ if (!DIGV) return false;
++#if LLVM_VERSION < 37
+ DIGlobalVariable Var(cast<MDNode>(DIGV));
++#else
++ DIGlobalVariable *Var = cast<DIGlobalVariable>(DIGV);
++#endif
+
++#if LLVM_VERSION < 37
+ StringRef D = Var.getDisplayName();
++#else
++ StringRef D = Var->getDisplayName();
++#endif
+ if (!D.empty())
+ DisplayName = D;
++#if LLVM_VERSION < 37
+ LineNo = Var.getLineNumber();
++#else
++ LineNo = Var->getLine();
++#endif
+ #if LLVM_VERSION < 33
+ Unit = Var.getCompileUnit();
+-#else
++#elif LLVM_VERSION < 37
+ G = Var.getFilename();
+ H = Var.getDirectory();
++#else
++ G = Var->getFilename();
++ H = Var->getDirectory();
+ #endif
+ #if LLVM_VERSION < 35
+ TypeD = Var.getType();
+-#else
++#elif LLVM_VERSION < 37
+ T = Var.getType().getName();
++#else
++ T = (cast<DIType>(*Var->getType())).getName();
+ #endif
+ } else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){
+ #if LLVM_VERSION < 36
+@@ -3085,32 +3205,61 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
+ Metadata *DIF = findDbgSubprogramDeclare(F);
+ #endif
+ if (!DIF) return false;
++#if LLVM_VERSION < 37
+ DISubprogram Var(cast<MDNode>(DIF));
++#else
++ DISubprogram *Var = cast<DISubprogram>(DIF);
++#endif
+
++#if LLVM_VERSION < 37
+ StringRef D = Var.getDisplayName();
++#else
++ StringRef D = Var->getDisplayName();
++#endif
+ if (!D.empty())
+ DisplayName = D;
++#if LLVM_VERSION < 37
+ LineNo = Var.getLineNumber();
++#else
++ LineNo = Var->getLine();
++#endif
+ #if LLVM_VERSION < 33
+ Unit = Var.getCompileUnit();
+-#else
++#elif LLVM_VERSION < 37
+ G = Var.getFilename();
+ H = Var.getDirectory();
++#else
++ G = Var->getFilename();
++ H = Var->getDirectory();
+ #endif
+ #if LLVM_VERSION < 35
+ TypeD = Var.getType();
+-#else
++#elif LLVM_VERSION < 37
+ T = Var.getType().getName();
++#else
++ T = Var->getType()->getName();
+ #endif
+ } else {
+ const DbgDeclareInst *DDI = findDbgDeclare(V);
+ if (!DDI) return false;
++#if LLVM_VERSION < 37
+ DIVariable Var(cast<MDNode>(DDI->getVariable()));
++#else
++ DIVariable* Var = DDI->getVariable();
++#endif
+
++#if LLVM_VERSION < 37
+ StringRef D = Var.getName();
++#else
++ StringRef D = Var->getName();
++#endif
+ if (!D.empty())
+ DisplayName = D;
++#if LLVM_VERSION < 37
+ LineNo = Var.getLineNumber();
++#else
++ LineNo = Var->getLine();
++#endif
+ #if LLVM_VERSION < 33
+ Unit = Var.getCompileUnit();
+ #else
+@@ -3120,8 +3269,10 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
+ #endif
+ #if LLVM_VERSION < 35
+ TypeD = Var.getType();
+-#else
++#elif LLVM_VERSION < 37
+ T = Var.getType().getName();
++#else
++ T = (cast<DIType>(*Var->getType())).getName();
+ #endif
+ }
+
+@@ -3157,9 +3308,15 @@ void printValue(llvm::Value *V, bool a, bool b) {
+
+ void printLocation(llvm::Instruction *I, bool a, bool b) {
+ if (MDNode *N = I->getMetadata("dbg")) {
++#if LLVM_VERSION < 37
+ DILocation Loc(N);
+ errs() << Loc.getFilename() << ":" << Loc.getLineNumber();
+ if (unsigned Col = Loc.getColumnNumber()) {
++#else
++ DebugLoc Loc(N);
++ errs() << Loc.get()->getFilename() << ":" << Loc.getLine();
++ if (unsigned Col = Loc.getCol()) {
++#endif
+ errs() << ":" << Col;
+ }
+ errs() << ": ";
+diff --git a/libclamav/c++/m4/llvm-flags.m4 b/libclamav/c++/m4/llvm-flags.m4
+index dce4e10..04d6833 100644
+--- a/libclamav/c++/m4/llvm-flags.m4
++++ b/libclamav/c++/m4/llvm-flags.m4
+@@ -98,14 +98,14 @@ elif test $llvmver_test -lt 290; then
+ elif test $llvmver_test -lt 360; then
+ llvmcomp="jit nativecodegen scalaropts ipo"
+ AC_MSG_RESULT([ok ($llvmver)])
+-elif test $llvmver_test -lt 370; then
++elif test $llvmver_test -lt 380; then
+ dnl LLVM 3.6.0 removed jit, so we have to use mcjit
+ dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers
+ llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser"
+ AC_MSG_RESULT([ok ($llvmver)])
+ else
+ AC_MSG_RESULT([no ($llvmver)])
+- AC_MSG_ERROR([LLVM < 3.7 required, but "$llvmver"($llvmver_test) found])
++ AC_MSG_ERROR([LLVM < 3.8 required, but "$llvmver"($llvmver_test) found])
+ fi
+
+ dnl aquire the required flags to properly link in external LLVM
diff --git a/libre/clamav/Add-support-for-LLVM-3.8.patch b/libre/clamav/Add-support-for-LLVM-3.8.patch
new file mode 100644
index 000000000..1d421b3a0
--- /dev/null
+++ b/libre/clamav/Add-support-for-LLVM-3.8.patch
@@ -0,0 +1,457 @@
+From 3111db3d1a3f2b20a007673f69a53ad69afec2f8 Mon Sep 17 00:00:00 2001
+From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
+Date: Fri, 14 Oct 2016 20:24:48 +0200
+Subject: Add support for LLVM 3.8
+
+Main changes:
+llvm/Config/config.h was removed.
+The ScalarEvolution pass is now a WrapperPass.
+Iterators are no longer automatically converted to and from pointers.
+The GVNPass causes the test_bswap_jit test to fail; replaced with
+ConstantPropagationPass.
+LLVMIsMultithreaded is from the C API, while llvm_is_multithreaded is
+the corresponding C++ API.
+
+Patch-Name: Add-support-for-LLVM-3.8.patch
+---
+ libclamav/c++/ClamBCRTChecks.cpp | 50 ++++++++++++++++++++++++++++++
+ libclamav/c++/PointerTracking.cpp | 12 ++++++++
+ libclamav/c++/bytecode2llvm.cpp | 65 +++++++++++++++++++++++++++++++--------
+ libclamav/c++/detect.cpp | 2 ++
+ libclamav/c++/m4/llvm-flags.m4 | 4 +--
+ 5 files changed, 119 insertions(+), 14 deletions(-)
+
+diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp
+index 35f7272..a254c40 100644
+--- a/libclamav/c++/ClamBCRTChecks.cpp
++++ b/libclamav/c++/ClamBCRTChecks.cpp
+@@ -54,7 +54,9 @@
+ #include "llvm/Analysis/ScalarEvolution.h"
+ #include "llvm/Analysis/ScalarEvolutionExpressions.h"
+ #include "llvm/Analysis/ScalarEvolutionExpander.h"
++#if LLVM_VERSION < 38
+ #include "llvm/Config/config.h"
++#endif
+ #include "llvm/Pass.h"
+ #include "llvm/Support/CommandLine.h"
+ #if LLVM_VERSION < 35
+@@ -207,7 +209,11 @@ namespace llvm {
+ #else
+ TD = &F.getEntryBlock().getModule()->getDataLayout();
+ #endif
++#if LLVM_VERSION < 38
+ SE = &getAnalysis<ScalarEvolution>();
++#else
++ SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
++#endif
+ PT = &getAnalysis<PointerTracking>();
+ #if LLVM_VERSION < 35
+ DT = &getAnalysis<DominatorTree>();
+@@ -332,7 +338,11 @@ namespace llvm {
+ AbrtC->setDoesNotThrow();
+ #endif
+ // remove all instructions from entry
++#if LLVM_VERSION < 38
+ BasicBlock::iterator BBI = I, BBE=BB->end();
++#else
++ BasicBlock::iterator BBI = I->getIterator(), BBE=BB->end();
++#endif
+ while (BBI != BBE) {
+ if (!BBI->use_empty())
+ BBI->replaceAllUsesWith(UndefValue::get(BBI->getType()));
+@@ -367,7 +377,11 @@ namespace llvm {
+ #else
+ AU.addRequired<DominatorTreeWrapperPass>();
+ #endif
++#if LLVM_VERSION < 38
+ AU.addRequired<ScalarEvolution>();
++#else
++ AU.addRequired<ScalarEvolutionWrapperPass>();
++#endif
+ AU.addRequired<PointerTracking>();
+ #if LLVM_VERSION < 35
+ AU.addRequired<CallGraph>();
+@@ -398,9 +412,17 @@ namespace llvm {
+
+ Instruction *getInsertPoint(Value *V)
+ {
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = EP;
++#else
++ BasicBlock::iterator It = EP->getIterator();
++#endif
+ if (Instruction *I = dyn_cast<Instruction>(V)) {
++#if LLVM_VERSION < 38
+ It = I;
++#else
++ It = I->getIterator();
++#endif
+ ++It;
+ }
+ return &*It;
+@@ -427,7 +449,11 @@ namespace llvm {
+ constType *P8Ty =
+ PointerType::getUnqual(Type::getInt8Ty(Ptr->getContext()));
+ if (PHINode *PN = dyn_cast<PHINode>(Ptr)) {
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = PN;
++#else
++ BasicBlock::iterator It = PN->getIterator();
++#endif
+ ++It;
+ PHINode *newPN = PHINode::Create(P8Ty, HINT(PN->getNumIncomingValues()) ".verif.base", &*It);
+ Changed = true;
+@@ -441,7 +467,11 @@ namespace llvm {
+ return newPN;
+ }
+ if (SelectInst *SI = dyn_cast<SelectInst>(Ptr)) {
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = SI;
++#else
++ BasicBlock::iterator It = SI->getIterator();
++#endif
+ ++It;
+ Value *TrueB = getPointerBase(SI->getTrueValue());
+ Value *FalseB = getPointerBase(SI->getFalseValue());
+@@ -552,7 +582,11 @@ namespace llvm {
+ }
+ #endif
+ if (PHINode *PN = dyn_cast<PHINode>(Base)) {
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = PN;
++#else
++ BasicBlock::iterator It = PN->getIterator();
++#endif
+ ++It;
+ PHINode *newPN = PHINode::Create(I64Ty, HINT(PN->getNumIncomingValues()) ".verif.bounds", &*It);
+ Changed = true;
+@@ -575,7 +609,11 @@ namespace llvm {
+ return BoundsMap[Base] = newPN;
+ }
+ if (SelectInst *SI = dyn_cast<SelectInst>(Base)) {
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = SI;
++#else
++ BasicBlock::iterator It = SI->getIterator();
++#endif
+ ++It;
+ Value *TrueB = getPointerBounds(SI->getTrueValue());
+ Value *FalseB = getPointerBounds(SI->getFalseValue());
+@@ -632,7 +670,11 @@ namespace llvm {
+ if (!MDDbgKind)
+ return 0;
+ Approximate = true;
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = I;
++#else
++ BasicBlock::iterator It = I->getIterator();
++#endif
+ while (It != I->getParent()->begin()) {
+ --It;
+ if (MDNode *Dbg = It->getMetadata(MDDbgKind))
+@@ -666,7 +708,11 @@ namespace llvm {
+ return false;
+ }
+ BasicBlock *BB = I->getParent();
++#if LLVM_VERSION < 38
+ BasicBlock::iterator It = I;
++#else
++ BasicBlock::iterator It = I->getIterator();
++#endif
+ #if LLVM_VERSION < 37
+ BasicBlock *newBB = SplitBlock(BB, &*It, this);
+ #else
+@@ -949,7 +995,11 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+ #else
+ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+ #endif
++#if LLVM_VERSION < 38
+ INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
++#else
++INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
++#endif
+ #if LLVM_VERSION < 34
+ INITIALIZE_AG_DEPENDENCY(CallGraph)
+ #elif LLVM_VERSION < 35
+diff --git a/libclamav/c++/PointerTracking.cpp b/libclamav/c++/PointerTracking.cpp
+index 67340e8..ad5b93f 100644
+--- a/libclamav/c++/PointerTracking.cpp
++++ b/libclamav/c++/PointerTracking.cpp
+@@ -79,7 +79,11 @@ INITIALIZE_PASS_DEPENDENCY(LoopInfo)
+ #else
+ INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
+ #endif
++#if LLVM_VERSION < 38
+ INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
++#else
++INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
++#endif
+ #if LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+ #else
+@@ -110,7 +114,11 @@ bool PointerTracking::runOnFunction(Function &F) {
+ #else
+ TD = &F.getEntryBlock().getModule()->getDataLayout();
+ #endif
++#if LLVM_VERSION < 38
+ SE = &getAnalysis<ScalarEvolution>();
++#else
++ SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
++#endif
+ #if LLVM_VERSION < 37
+ LI = &getAnalysis<LoopInfo>();
+ #else
+@@ -135,7 +143,11 @@ void PointerTracking::getAnalysisUsage(AnalysisUsage &AU) const {
+ #else
+ AU.addRequiredTransitive<LoopInfoWrapperPass>();
+ #endif
++#if LLVM_VERSION < 38
+ AU.addRequiredTransitive<ScalarEvolution>();
++#else
++ AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
++#endif
+ AU.setPreservesAll();
+ }
+
+diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
+index 2171993..213847c 100644
+--- a/libclamav/c++/bytecode2llvm.cpp
++++ b/libclamav/c++/bytecode2llvm.cpp
+@@ -170,7 +170,9 @@ void LLVMInitializePowerPCAsmPrinter();
+ //#define TIMING
+ #undef TIMING
+
++#if LLVM_VERSION < 38
+ #include "llvm/Config/config.h"
++#endif
+ #ifdef ENABLE_THREADS
+ #if !ENABLE_THREADS
+ #error "Thread support was explicitly disabled. Cannot continue"
+@@ -729,7 +731,11 @@ class RuntimeLimits : public FunctionPass {
+ #else
+ LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+ #endif
++#if LLVM_VERSION < 38
+ ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
++#else
++ ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
++#endif
+
+ // Now check whether any of these backedge targets are part of a loop
+ // with a small constant trip count
+@@ -783,7 +789,11 @@ class RuntimeLimits : public FunctionPass {
+ new UnreachableInst(F.getContext(), AbrtBB);
+ IRBuilder<false> Builder(F.getContext());
+
++#if LLVM_VERSION < 38
+ Value *Flag = F.arg_begin();
++#else
++ Value *Flag = &*F.arg_begin();
++#endif
+ #if LLVM_VERSION < 30
+ Function *LSBarrier = Intrinsic::getDeclaration(F.getParent(),
+ Intrinsic::memory_barrier);
+@@ -797,13 +807,21 @@ class RuntimeLimits : public FunctionPass {
+ #endif
+ verifyFunction(F);
+ BasicBlock *BB = &F.getEntryBlock();
++#if LLVM_VERSION < 38
+ Builder.SetInsertPoint(BB, BB->getTerminator());
++#else
++ Builder.SetInsertPoint(BB, BB->getTerminator()->getIterator());
++#endif
+ Flag = Builder.CreatePointerCast(Flag, PointerType::getUnqual(
+ Type::getInt1Ty(F.getContext())));
+ for (BBSetTy::iterator I=needsTimeoutCheck.begin(),
+ E=needsTimeoutCheck.end(); I != E; ++I) {
+ BasicBlock *BB = *I;
++#if LLVM_VERSION < 38
+ Builder.SetInsertPoint(BB, BB->getTerminator());
++#else
++ Builder.SetInsertPoint(BB, BB->getTerminator()->getIterator());
++#endif
+ #if LLVM_VERSION < 30
+ // store-load barrier: will be a no-op on x86 but not other arches
+ Builder.CreateCall(LSBarrier, ARRAYREF(Value*, MBArgs, MBArgs+5));
+@@ -842,7 +860,11 @@ class RuntimeLimits : public FunctionPass {
+ #else
+ AU.addRequired<LoopInfoWrapperPass>();
+ #endif
++#if LLVM_VERSION < 38
+ AU.addRequired<ScalarEvolution>();
++#else
++ AU.addRequired<ScalarEvolutionWrapperPass>();
++#endif
+ #if LLVM_VERSION < 35
+ AU.addRequired<DominatorTree>();
+ #else
+@@ -1157,8 +1179,10 @@ class LLVMCodegen {
+ Folder(EE->getTargetData()), Builder(Context, Folder), Values(), CF(CF) {
+ #elif LLVM_VERSION < 37
+ Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
+-#else
++#elif LLVM_VERSION < 38
+ Folder(*EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
++#else
++ Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
+ #endif
+
+ for (unsigned i=0;i<cli_apicall_maxglobal - _FIRST_GLOBAL;i++) {
+@@ -1319,8 +1343,10 @@ class LLVMCodegen {
+ }
+ #if LLVM_VERSION < 32
+ if (EE->getTargetData()->getPointerSize() == 8) {
+-#else
++#elif LLVM_VERSION < 38
+ if (EE->getDataLayout()->getPointerSize() == 8) {
++#else
++ if (EE->getDataLayout().getPointerSize() == 8) {
+ #endif
+ // eliminate useless trunc, GEP can take i64 too
+ if (TruncInst *I = dyn_cast<TruncInst>(V)) {
+@@ -1440,7 +1466,11 @@ class LLVMCodegen {
+ numArgs = func->numArgs;
+
+ if (FakeGVs.any()) {
++#if LLVM_VERSION < 38
+ Argument *Ctx = F->arg_begin();
++#else
++ Argument *Ctx = &*F->arg_begin();
++#endif
+ for (unsigned i=0;i<bc->num_globals;i++) {
+ if (!FakeGVs[i])
+ continue;
+@@ -1888,8 +1918,10 @@ class LLVMCodegen {
+ Src = Builder.CreatePointerCast(Src, PointerType::getUnqual(Type::getInt8Ty(Context)));
+ #if LLVM_VERSION < 32
+ Value *Len = convertOperand(func, EE->getTargetData()->getIntPtrType(Context), inst->u.three[2]);
+-#else
++#elif LLVM_VERSION < 38
+ Value *Len = convertOperand(func, EE->getDataLayout()->getIntPtrType(Context), inst->u.three[2]);
++#else
++ Value *Len = convertOperand(func, EE->getDataLayout().getIntPtrType(Context), inst->u.three[2]);
+ #endif
+ #if LLVM_VERSION < 37
+ CallInst *c = Builder.CreateCall3(CF->FRealmemcmp, Dst, Src, Len);
+@@ -2028,6 +2060,7 @@ class LLVMCodegen {
+ PMUnsigned.run(*F);
+ PMUnsigned.doFinalization();
+ }
++
+ apiMap.pmTimer.stopTimer();
+ apiMap.irgenTimer.startTimer();
+ }
+@@ -2260,8 +2293,10 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
+ args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
+ #if LLVM_VERSION < 32
+ args.push_back(EE->getTargetData()->getIntPtrType(Context));
+-#else
++#elif LLVM_VERSION < 38
+ args.push_back(EE->getDataLayout()->getIntPtrType(Context));
++#else
++ args.push_back(EE->getDataLayout().getIntPtrType(Context));
+ #endif
+ FuncTy_5 = FunctionType::get(Type::getInt32Ty(Context),
+ args, false);
+@@ -2282,7 +2317,11 @@ INITIALIZE_PASS_DEPENDENCY(LoopInfo)
+ #else
+ INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
+ #endif
++#if LLVM_VERSION < 38
+ INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
++#else
++INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
++#endif
+ #if LLVM_VERSION < 35
+ INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+ #else
+@@ -2609,8 +2648,10 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+ #endif
+ #if LLVM_VERSION < 32
+ M->setDataLayout(EE->getTargetData()->getStringRepresentation());
+-#else
++#elif LLVM_VERSION < 38
+ M->setDataLayout(EE->getDataLayout()->getStringRepresentation());
++#else
++ M->setDataLayout(EE->getDataLayout().getStringRepresentation());
+ #endif
+ #if LLVM_VERSION < 31
+ M->setTargetTriple(sys::getHostTriple());
+@@ -2767,7 +2808,11 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
+ // TODO: only run this on the untrusted bytecodes, not all of them...
+ if (has_untrusted)
+ PM.add(createClamBCRTChecks());
+-#if LLVM_VERSION >= 36
++#if LLVM_VERSION >= 38
++ // With LLVM 3.8 the test_bswap_jit test fails with the GVNPass enabled.
++ // To prevent the segfaults mentioned below, replace it with the ConstantPropagationPass.
++ PM.add(createConstantPropagationPass());
++#elif LLVM_VERSION >= 36
+ // With LLVM 3.6 (MCJIT) this Pass is required to work around
+ // a crash in LLVM caused by the SCCP Pass:
+ // Pass 'Sparse Conditional Constant Propagation' is not initialized.
+@@ -2841,7 +2886,7 @@ int bytecode_init(void)
+ return CL_EARG;
+ }
+ #else
+- if (!LLVMIsMultithreaded()) {
++ if (!llvm_is_multithreaded()) {
+ cli_warnmsg("bytecode_init: LLVM is compiled without multithreading support\n");
+ }
+ #endif
+@@ -2890,11 +2935,7 @@ int bytecode_init(void)
+ InitializeAllTargets();
+ #endif
+
+-#if LLVM_VERSION < 35
+ if (!llvm_is_multithreaded()) {
+-#else
+- if (!LLVMIsMultithreaded()) {
+-#endif
+ //TODO:cli_dbgmsg
+ DEBUG(errs() << "WARNING: ClamAV JIT built w/o atomic builtins\n"
+ << "On x86 for best performance ClamAV should be built for i686, not i386!\n");
+@@ -3113,7 +3154,7 @@ static Metadata *findDbgSubprogramDeclare(Function *V) {
+ MDNode *DIG = NMD->getOperand(i);
+ if (!DISubprogram::classof(DIG))
+ continue;
+- if ((cast<DISubprogram>(DIG))->getFunction() == V)
++ if ((cast<DISubprogram>(DIG))->describes(V))
+ return DIG;
+ #endif
+ }
+diff --git a/libclamav/c++/detect.cpp b/libclamav/c++/detect.cpp
+index 17348af..95ba2f7 100644
+--- a/libclamav/c++/detect.cpp
++++ b/libclamav/c++/detect.cpp
+@@ -22,7 +22,9 @@
+ */
+
+ #include "llvm/ADT/Triple.h"
++#if LLVM_VERSION < 38
+ #include "llvm/Config/config.h"
++#endif
+ #include "llvm/Support/raw_ostream.h"
+ #if LLVM_VERSION < 29
+ #include "llvm/System/DataTypes.h"
+diff --git a/libclamav/c++/m4/llvm-flags.m4 b/libclamav/c++/m4/llvm-flags.m4
+index 04d6833..345c7ae 100644
+--- a/libclamav/c++/m4/llvm-flags.m4
++++ b/libclamav/c++/m4/llvm-flags.m4
+@@ -98,14 +98,14 @@ elif test $llvmver_test -lt 290; then
+ elif test $llvmver_test -lt 360; then
+ llvmcomp="jit nativecodegen scalaropts ipo"
+ AC_MSG_RESULT([ok ($llvmver)])
+-elif test $llvmver_test -lt 380; then
++elif test $llvmver_test -lt 390; then
+ dnl LLVM 3.6.0 removed jit, so we have to use mcjit
+ dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers
+ llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser"
+ AC_MSG_RESULT([ok ($llvmver)])
+ else
+ AC_MSG_RESULT([no ($llvmver)])
+- AC_MSG_ERROR([LLVM < 3.8 required, but "$llvmver"($llvmver_test) found])
++ AC_MSG_ERROR([LLVM < 3.9 required, but "$llvmver"($llvmver_test) found])
+ fi
+
+ dnl aquire the required flags to properly link in external LLVM
diff --git a/libre/clamav/Add-support-for-LLVM-3.9.patch b/libre/clamav/Add-support-for-LLVM-3.9.patch
new file mode 100644
index 000000000..084d41c1a
--- /dev/null
+++ b/libre/clamav/Add-support-for-LLVM-3.9.patch
@@ -0,0 +1,76 @@
+From fef1bbc259bca9cfaac65a85de877f9b7ed27773 Mon Sep 17 00:00:00 2001
+From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
+Date: Fri, 14 Oct 2016 20:24:56 +0200
+Subject: Add support for LLVM 3.9
+
+Changes:
+IRBuilder no longer has a preserveNames template argument.
+AtomicOrdering is now a strongly typed enum.
+
+Patch-Name: Add-support-for-LLVM-3.9.patch
+---
+ libclamav/c++/bytecode2llvm.cpp | 12 +++++++++++-
+ libclamav/c++/m4/llvm-flags.m4 | 4 ++--
+ 2 files changed, 13 insertions(+), 3 deletions(-)
+
+diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
+index 213847c..252f8f6 100644
+--- a/libclamav/c++/bytecode2llvm.cpp
++++ b/libclamav/c++/bytecode2llvm.cpp
+@@ -787,7 +787,11 @@ class RuntimeLimits : public FunctionPass {
+ AbrtC->setDoesNotThrow();
+ #endif
+ new UnreachableInst(F.getContext(), AbrtBB);
++#if LLVM_VERSION < 39
+ IRBuilder<false> Builder(F.getContext());
++#else
++ IRBuilder<> Builder(F.getContext());
++#endif
+
+ #if LLVM_VERSION < 38
+ Value *Flag = F.arg_begin();
+@@ -825,8 +829,10 @@ class RuntimeLimits : public FunctionPass {
+ #if LLVM_VERSION < 30
+ // store-load barrier: will be a no-op on x86 but not other arches
+ Builder.CreateCall(LSBarrier, ARRAYREF(Value*, MBArgs, MBArgs+5));
+-#else
++#elif LLVM_VERSION < 39
+ Builder.CreateFence(Release);
++#else
++ Builder.CreateFence(AtomicOrdering::Release);
+ #endif
+ // Load Flag that tells us we timed out (first byte in bc_ctx)
+ Value *Cond = Builder.CreateLoad(Flag, true);
+@@ -969,7 +975,11 @@ class LLVMCodegen {
+ Twine BytecodeID;
+
+ TargetFolder Folder;
++#if LLVM_VERSION < 39
+ IRBuilder<false, TargetFolder> Builder;
++#else
++ IRBuilder<TargetFolder> Builder;
++#endif
+
+ std::vector<Value*> globals;
+ DenseMap<unsigned, unsigned> GVoffsetMap;
+diff --git a/libclamav/c++/m4/llvm-flags.m4 b/libclamav/c++/m4/llvm-flags.m4
+index 345c7ae..9631d5d 100644
+--- a/libclamav/c++/m4/llvm-flags.m4
++++ b/libclamav/c++/m4/llvm-flags.m4
+@@ -98,14 +98,14 @@ elif test $llvmver_test -lt 290; then
+ elif test $llvmver_test -lt 360; then
+ llvmcomp="jit nativecodegen scalaropts ipo"
+ AC_MSG_RESULT([ok ($llvmver)])
+-elif test $llvmver_test -lt 390; then
++elif test $llvmver_test -lt 400; then
+ dnl LLVM 3.6.0 removed jit, so we have to use mcjit
+ dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers
+ llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser"
+ AC_MSG_RESULT([ok ($llvmver)])
+ else
+ AC_MSG_RESULT([no ($llvmver)])
+- AC_MSG_ERROR([LLVM < 3.9 required, but "$llvmver"($llvmver_test) found])
++ AC_MSG_ERROR([LLVM < 4.0 required, but "$llvmver"($llvmver_test) found])
+ fi
+
+ dnl aquire the required flags to properly link in external LLVM
diff --git a/libre/clamav/PKGBUILD b/libre/clamav/PKGBUILD
index a30f36d62..ef0cb9f28 100644
--- a/libre/clamav/PKGBUILD
+++ b/libre/clamav/PKGBUILD
@@ -1,4 +1,4 @@
-# $Id: PKGBUILD 272647 2016-07-28 19:05:20Z heftig $
+# $Id: PKGBUILD 288711 2017-02-11 22:07:31Z foutrelis $
# Contributor (Arch): Dale Blount <dale@archlinux.org>
# Contributor (Arch): Gregor Ibic <gregor.ibic@intelicom.si>
# Maintainer (Arch): Gaetan Bisson <bisson@archlinux.org>
@@ -9,18 +9,13 @@
_pkgname=clamav-libre
pkgname=clamav
pkgver=0.99.2
-pkgrel=2.parabola1
+pkgrel=3.parabola1
pkgdesc='Anti-virus toolkit for Unix, without nonfree decompression engine for RAR archives'
url='http://www.clamav.net/'
license=('GPL')
arch=('i686' 'x86_64' 'armv7h')
-makedepends=('libmilter')
-makedepends_i686=('llvm35')
-makedepends_x86_64=("${makedepends_i686[@]}")
-depends=('bzip2' 'libltdl' 'libxml2' 'curl')
-depends_i686=('llvm35-libs')
-depends_x86_64=("${depends_i686[@]}")
-depends_armv7h=('gcc-libs')
+makedepends=('libmilter' 'llvm')
+depends=('bzip2' 'libltdl' 'llvm-libs' 'libxml2' 'curl')
validpgpkeys=('B964E6D7BC7D7C82CCB8D45840B8EA2364221D53'
'F79FB2D08751574C5D3FDFFBB3D5342C260429A0')
mksource=("http://www.clamav.net/downloads/production/${pkgname}-${pkgver}.tar.gz"{,.sig})
@@ -30,7 +25,10 @@ source=("https://repo.parabola.nu/other/${_pkgname}/${_pkgname}-${pkgver}.tar.gz
'clamd.conf'
'freshclam.conf'
'clamd.service'
- 'freshclamd.service')
+ 'freshclamd.service'
+ 'Add-support-for-LLVM-3.7.patch'
+ 'Add-support-for-LLVM-3.8.patch'
+ 'Add-support-for-LLVM-3.9.patch')
mksha1sums=('c1a47411834d8527f7b40727aebee63f01d488af'
'SKIP')
sha1sums=('f6460a9ce0edb7d76397e4f9b1ebd3cc2c7d544c'
@@ -39,7 +37,10 @@ sha1sums=('f6460a9ce0edb7d76397e4f9b1ebd3cc2c7d544c'
'887f624eb305f2446f55d8339e2972ad0cfe2b79'
'b767837d0279ad30b92c314cb762b73e5ad0415e'
'77899cce83f04cbe134b30da376f879d2841f769'
- 'cda9a087e5593992150cb456e34c5f6f589aca82')
+ 'cda9a087e5593992150cb456e34c5f6f589aca82'
+ '89765c80080c84f0a48c295ac11e1a4ce7f4cc14'
+ '5a513779e59253b22aefe36451f941866178cc64'
+ '16be511156965197f956a0f2147ce1be2a546008')
backup=('etc/clamav/clamd.conf'
'etc/clamav/freshclam.conf'
@@ -54,21 +55,29 @@ mksource() {
rm -v COPYING.unrar
}
+prepare() {
+ cd "${srcdir}/${pkgname}-${pkgver}"
+ patch -Np1 -i ../Add-support-for-LLVM-3.7.patch
+ patch -Np1 -i ../Add-support-for-LLVM-3.8.patch
+ patch -Np1 -i ../Add-support-for-LLVM-3.9.patch
+ autoreconf -vi libclamav/c++
+}
+
build() {
cd "${srcdir}/${pkgname}-${pkgver}"
- if [ "$CARCH" != "armv7h" ]; then
- local extra_options="--with-system-llvm \
- --with-llvm-linking=dynamic"
- fi
+ # --disable-zlib-vcheck because the configure script thinks that
+ # zlib 1.2.11 is older than 1.2.2
./configure \
--prefix=/usr \
--sbindir=/usr/bin \
--sysconfdir=/etc/clamav \
--with-dbdir=/var/lib/clamav \
--disable-clamav \
+ --disable-zlib-vcheck \
--enable-milter \
--disable-unrar \
- $extra_options
+ --with-system-llvm \
+ --with-llvm-linking=dynamic
make
}