Package: clamav / 0.101.2+dfsg-1

Add-support-for-LLVM-3.8.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
From 4c68f84da6bf0b1b686c7d7575520a307fc71c34 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++/configure.ac        |  4 +-
 libclamav/c++/detect.cpp          |  2 +
 5 files changed, 119 insertions(+), 14 deletions(-)

diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp
index 033604e..8b065e7 100644
--- a/libclamav/c++/ClamBCRTChecks.cpp
+++ b/libclamav/c++/ClamBCRTChecks.cpp
@@ -53,7 +53,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
@@ -206,7 +208,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>();
@@ -331,7 +337,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()));
@@ -366,7 +376,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>();
@@ -397,9 +411,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;
@@ -426,7 +448,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;
@@ -440,7 +466,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());
@@ -574,7 +604,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;
@@ -597,7 +631,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());
@@ -654,7 +692,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))
@@ -688,7 +730,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
@@ -971,7 +1017,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 5567894..147ad48 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 80b6fc3..8bc1937 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++/configure.ac b/libclamav/c++/configure.ac
index a8511a0..291b8a0 100644
--- a/libclamav/c++/configure.ac
+++ b/libclamav/c++/configure.ac
@@ -89,14 +89,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 acquire the required flags to properly link in external LLVM
diff --git a/libclamav/c++/detect.cpp b/libclamav/c++/detect.cpp
index dea61b5..db3d3bd 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"