1
From afdd6526fe20e5dd8ca3946abcbfc07e564eec08 Mon Sep 17 00:00:00 2001
2
From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
3
Date: Fri, 2 May 2014 16:04:52 +0200
4
Subject: Fix FTBFS with LLVM 3.1-3.4
6
Fixed detection of LLVM versions like 3.4.2 as 34.
8
libclamav/c++/ClamBCRTChecks.cpp | 80 ++++++++++++--
9
libclamav/c++/Makefile.am | 3 +-
10
libclamav/c++/PointerTracking.cpp | 45 +++++++-
11
libclamav/c++/PointerTracking.h | 15 ++-
12
libclamav/c++/bytecode2llvm.cpp | 227 ++++++++++++++++++++++++++++++++++----
13
libclamav/c++/configure.ac | 21 +++-
14
libclamav/c++/detect.cpp | 13 +++
15
7 files changed, 365 insertions(+), 39 deletions(-)
17
diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp
18
index 634700d..380c015 100644
19
--- a/libclamav/c++/ClamBCRTChecks.cpp
20
+++ b/libclamav/c++/ClamBCRTChecks.cpp
22
#include "llvm/ADT/SCCIterator.h"
23
#include "llvm/Analysis/CallGraph.h"
24
#include "llvm/Analysis/Verifier.h"
25
-#include "llvm/Analysis/DebugInfo.h"
26
#include "llvm/Analysis/Dominators.h"
27
#include "llvm/Analysis/ConstantFolding.h"
28
//#include "llvm/Analysis/LiveValues.h"
30
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
31
#include "llvm/Analysis/ScalarEvolutionExpander.h"
32
#include "llvm/Config/config.h"
33
-#include "llvm/DerivedTypes.h"
34
-#include "llvm/Instructions.h"
35
-#include "llvm/IntrinsicInst.h"
36
-#include "llvm/Intrinsics.h"
37
-#include "llvm/LLVMContext.h"
38
-#include "llvm/Module.h"
39
#include "llvm/Pass.h"
40
#include "llvm/Support/CommandLine.h"
41
#include "llvm/Support/DataFlow.h"
42
#include "llvm/Support/InstIterator.h"
43
-#include "llvm/Support/InstVisitor.h"
44
#include "llvm/Support/GetElementPtrTypeIterator.h"
45
#include "llvm/ADT/DepthFirstIterator.h"
46
-#include "llvm/Target/TargetData.h"
47
#include "llvm/Transforms/Scalar.h"
48
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
49
#include "llvm/Support/Debug.h"
50
#include "llvm30_compat.h"
52
+#if LLVM_VERSION < 32
53
+#include "llvm/Analysis/DebugInfo.h"
55
+#include "llvm/DebugInfo.h"
58
+#if LLVM_VERSION < 32
59
+#include "llvm/Target/TargetData.h"
60
+#elif LLVM_VERSION < 33
61
+#include "llvm/DataLayout.h"
63
+#include "llvm/IR/DataLayout.h"
66
+#if LLVM_VERSION < 33
67
+#include "llvm/DerivedTypes.h"
68
+#include "llvm/Instructions.h"
69
+#include "llvm/IntrinsicInst.h"
70
+#include "llvm/Intrinsics.h"
71
+#include "llvm/LLVMContext.h"
72
+#include "llvm/Module.h"
73
+#include "llvm/Support/InstVisitor.h"
75
+#include "llvm/IR/DerivedTypes.h"
76
+#include "llvm/IR/Instructions.h"
77
+#include "llvm/IR/IntrinsicInst.h"
78
+#include "llvm/IR/Intrinsics.h"
79
+#include "llvm/IR/LLVMContext.h"
80
+#include "llvm/IR/Module.h"
81
+#include "llvm/InstVisitor.h"
91
+#if LLVM_VERSION < 32
92
static Value *GetUnderlyingObject(Value *P, TargetData *TD)
94
+static Value *GetUnderlyingObject(Value *P, DataLayout *TD)
97
return P->getUnderlyingObject();
99
@@ -137,8 +164,11 @@ namespace llvm {
100
BasicBlock::iterator It = F.getEntryBlock().begin();
101
while (isa<AllocaInst>(It) || isa<PHINode>(It)) ++It;
104
+#if LLVM_VERSION < 32
105
TD = &getAnalysis<TargetData>();
107
+ TD = &getAnalysis<DataLayout>();
109
SE = &getAnalysis<ScalarEvolution>();
110
PT = &getAnalysis<PointerTracking>();
111
DT = &getAnalysis<DominatorTree>();
112
@@ -247,8 +277,13 @@ namespace llvm {
113
CallInst *AbrtC = CallInst::Create(func_abort, "", UI);
114
AbrtC->setCallingConv(CallingConv::C);
115
AbrtC->setTailCall(true);
116
+#if LLVM_VERSION < 32
117
AbrtC->setDoesNotReturn(true);
118
AbrtC->setDoesNotThrow(true);
120
+ AbrtC->setDoesNotReturn();
121
+ AbrtC->setDoesNotThrow();
123
// remove all instructions from entry
124
BasicBlock::iterator BBI = I, BBE=BB->end();
126
@@ -265,7 +300,11 @@ namespace llvm {
129
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
130
+#if LLVM_VERSION < 32
131
AU.addRequired<TargetData>();
133
+ AU.addRequired<DataLayout>();
135
AU.addRequired<DominatorTree>();
136
AU.addRequired<ScalarEvolution>();
137
AU.addRequired<PointerTracking>();
138
@@ -275,7 +314,11 @@ namespace llvm {
139
bool isValid() const { return valid; }
142
+#if LLVM_VERSION < 32
149
DenseMap<Value*, Value*> BaseMap;
150
@@ -511,13 +554,22 @@ namespace llvm {
151
CallInst *RtErrCall = CallInst::Create(func_rterr, PN, "", AbrtBB);
152
RtErrCall->setCallingConv(CallingConv::C);
153
RtErrCall->setTailCall(true);
154
+#if LLVM_VERSION < 32
155
RtErrCall->setDoesNotThrow(true);
157
+ RtErrCall->setDoesNotThrow();
160
CallInst* AbrtC = CallInst::Create(func_abort, "", AbrtBB);
161
AbrtC->setCallingConv(CallingConv::C);
162
AbrtC->setTailCall(true);
163
+#if LLVM_VERSION < 32
164
AbrtC->setDoesNotReturn(true);
165
AbrtC->setDoesNotThrow(true);
167
+ AbrtC->setDoesNotReturn();
168
+ AbrtC->setDoesNotThrow();
170
new UnreachableInst(BB->getContext(), AbrtBB);
171
DT->addNewBlock(AbrtBB, BB);
172
//verifyFunction(*BB->getParent());
173
@@ -732,10 +784,18 @@ namespace llvm {
176
INITIALIZE_PASS_BEGIN(PtrVerifier, "", "", false, false)
177
+#if LLVM_VERSION < 32
178
INITIALIZE_PASS_DEPENDENCY(TargetData)
180
+INITIALIZE_PASS_DEPENDENCY(DataLayout)
182
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
183
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
184
+#if LLVM_VERSION < 34
185
INITIALIZE_AG_DEPENDENCY(CallGraph)
187
+INITIALIZE_PASS_DEPENDENCY(CallGraph)
189
INITIALIZE_PASS_DEPENDENCY(PointerTracking)
190
INITIALIZE_PASS_END(PtrVerifier, "clambcrtchecks", "ClamBC RTchecks", false, false)
192
diff --git a/libclamav/c++/Makefile.am b/libclamav/c++/Makefile.am
193
index 599321d..d8c8244 100644
194
--- a/libclamav/c++/Makefile.am
195
+++ b/libclamav/c++/Makefile.am
196
@@ -38,6 +38,7 @@ libclamavcxx_la_CXXFLAGS = $(AM_CPPFLAGS) @LLVMCONFIG_CXXFLAGS@ -fexceptions -DL
198
libclamavcxx_la_CXXFLAGS += -DLLVM30
200
+libclamavcxx_la_CXXFLAGS += -DLLVM_VERSION=${LLVM_VERSION}
201
libclamavcxx_la_LDFLAGS = @LLVMCONFIG_LDFLAGS@ @LLVMCONFIG_LIBS@
202
libclamavcxx_la_DEPENDENCIES = @LLVMCONFIG_LIBFILES@
203
noinst_LTLIBRARIES = libclamavcxx.la
204
@@ -51,7 +52,7 @@ noinst_LTLIBRARIES = libclamavcxx.la libllvmsystem.la\
205
libclamavcxx_la_LIBADD=libllvmjit.la
206
libclamavcxx_la_DEPENDENCIES=libllvmjit.la libllvmcodegen.la libllvmsystem.la
207
libclamavcxx_la_LDFLAGS=-no-undefined
208
-libclamavcxx_la_CXXFLAGS = $(LLVM_CXXFLAGS)
209
+libclamavcxx_la_CXXFLAGS = $(LLVM_CXXFLAGS) -DLLVM_VERSION=${LLVM_VERSION}
213
diff --git a/libclamav/c++/PointerTracking.cpp b/libclamav/c++/PointerTracking.cpp
214
index da559cf..e853bd3 100644
215
--- a/libclamav/c++/PointerTracking.cpp
216
+++ b/libclamav/c++/PointerTracking.cpp
218
#include "PointerTracking.h"
219
#include "llvm/Analysis/ScalarEvolution.h"
220
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
221
-#include "llvm/Constants.h"
222
-#include "llvm/Module.h"
223
-#include "llvm/Value.h"
224
#include "llvm/Support/CallSite.h"
225
#include "llvm/Support/InstIterator.h"
226
#include "llvm/Support/raw_ostream.h"
227
+#include "llvm/Target/TargetLibraryInfo.h"
229
+#if LLVM_VERSION < 32
230
#include "llvm/Target/TargetData.h"
231
+#elif LLVM_VERSION < 33
232
+#include "llvm/DataLayout.h"
234
+#include "llvm/IR/DataLayout.h"
237
+#if LLVM_VERSION < 33
238
+#include "llvm/Constants.h"
239
+#include "llvm/Module.h"
240
+#include "llvm/Value.h"
242
+#include "llvm/IR/Constants.h"
243
+#include "llvm/IR/Module.h"
244
+#include "llvm/IR/Value.h"
247
using namespace llvm;
249
void initializePointerTrackingPass(llvm::PassRegistry&);
251
INITIALIZE_PASS_BEGIN(PointerTracking, "pointertracking",
252
"Track pointer bounds", false, true)
254
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
255
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
256
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
257
@@ -52,7 +69,11 @@ bool PointerTracking::runOnFunction(Function &F) {
259
assert(analyzing.empty());
261
+#if LLVM_VERSION < 32
262
TD = getAnalysisIfAvailable<TargetData>();
264
+ TD = getAnalysisIfAvailable<DataLayout>();
266
SE = &getAnalysis<ScalarEvolution>();
267
LI = &getAnalysis<LoopInfo>();
268
DT = &getAnalysis<DominatorTree>();
269
@@ -119,9 +140,17 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P,
270
return SE->getSCEV(arraySize);
273
+#if LLVM_VERSION < 32
274
if (CallInst *CI = extractMallocCall(V)) {
275
Value *arraySize = getMallocArraySize(CI, TD);
276
constType* AllocTy = getMallocAllocatedType(CI);
278
+ TargetLibraryInfo* TLI = new TargetLibraryInfo();
280
+ if (CallInst *CI = extractMallocCall(V, TLI)) {
281
+ Value *arraySize = getMallocArraySize(CI, TD, TLI);
282
+ constType* AllocTy = getMallocAllocatedType(CI, TLI);
284
if (!AllocTy || !arraySize) return SE->getCouldNotCompute();
286
// arraySize elements of type Ty.
287
@@ -171,11 +200,21 @@ Value *PointerTracking::computeAllocationCountValue(Value *P, constType *&Ty) co
288
return AI->getArraySize();
291
+#if LLVM_VERSION < 32
292
if (CallInst *CI = extractMallocCall(V)) {
293
Ty = getMallocAllocatedType(CI);
296
Value *arraySize = getMallocArraySize(CI, TD);
298
+ TargetLibraryInfo* TLI = new TargetLibraryInfo();
300
+ if (CallInst *CI = extractMallocCall(V, TLI)) {
301
+ Ty = getMallocAllocatedType(CI, TLI);
304
+ Value *arraySize = getMallocArraySize(CI, TD, TLI);
307
Ty = Type::getInt8Ty(P->getContext());
308
return CI->getArgOperand(0);
309
diff --git a/libclamav/c++/PointerTracking.h b/libclamav/c++/PointerTracking.h
310
index 20eee22..3429991 100644
311
--- a/libclamav/c++/PointerTracking.h
312
+++ b/libclamav/c++/PointerTracking.h
315
#include "llvm/ADT/SmallPtrSet.h"
316
#include "llvm/Analysis/Dominators.h"
317
-#include "llvm/Instructions.h"
318
#include "llvm/Pass.h"
319
#include "llvm/Support/PredIteratorCache.h"
320
#include "llvm30_compat.h"
322
+#if LLVM_VERSION < 33
323
+#include "llvm/Instructions.h"
325
+#include "llvm/IR/Instructions.h"
330
class ScalarEvolution;
334
+#if LLVM_VERSION < 32
340
// Result from solver, assuming pointer is not NULL,
341
// and it is not a use-after-free situation.
342
@@ -106,7 +115,11 @@ namespace llvm {
343
Value *computeAllocationCountValue(Value *P, constType *&Ty) const;
346
+#if LLVM_VERSION < 32
354
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
355
index 41b3112..b0176b2 100644
356
--- a/libclamav/c++/bytecode2llvm.cpp
357
+++ b/libclamav/c++/bytecode2llvm.cpp
360
#include "ClamBCModule.h"
361
#include "ClamBCDiagnostics.h"
362
-#include "llvm/Analysis/DebugInfo.h"
363
#include "llvm/ADT/DenseMap.h"
364
#include "llvm/ADT/BitVector.h"
365
#include "llvm/ADT/PostOrderIterator.h"
367
#include "llvm/Analysis/ScalarEvolution.h"
368
#include "llvm/Analysis/Verifier.h"
369
#include "llvm/AutoUpgrade.h"
370
-#include "llvm/CallingConv.h"
371
-#include "llvm/DerivedTypes.h"
372
-#include "llvm/Function.h"
373
#include "llvm/ExecutionEngine/ExecutionEngine.h"
374
#include "llvm/ExecutionEngine/JIT.h"
375
#include "llvm/ExecutionEngine/JITEventListener.h"
376
-#include "llvm/LLVMContext.h"
377
-#include "llvm/Intrinsics.h"
378
-#include "llvm/Module.h"
379
#include "llvm/PassManager.h"
380
#include "llvm/Support/Compiler.h"
381
#include "llvm/Support/Debug.h"
383
#include "llvm/Support/MemoryBuffer.h"
384
#include "llvm/Support/raw_ostream.h"
385
#include "llvm/Support/SourceMgr.h"
386
-#include "llvm/Support/IRBuilder.h"
387
#include "llvm/Support/PrettyStackTrace.h"
391
#include "llvm/Support/Signals.h"
392
#include "llvm/Support/Threading.h"
393
#include "llvm/Support/ThreadLocal.h"
394
-#include "llvm/IntrinsicInst.h"
395
#include "llvm/PassRegistry.h"
396
+#if LLVM_VERSION < 33
397
+#include "llvm/IntrinsicInst.h"
399
+#include "llvm/IR/IntrinsicInst.h"
402
#include "llvm/System/DataTypes.h"
403
#include "llvm/System/Host.h"
404
@@ -94,7 +90,6 @@ void LLVMInitializePowerPCAsmPrinter();
406
#include "llvm/Target/TargetSelect.h"
408
-#include "llvm/Target/TargetData.h"
409
#include "llvm/Target/TargetOptions.h"
410
#include "llvm/Support/TargetFolder.h"
411
#include "llvm/Transforms/Scalar.h"
412
@@ -106,13 +101,58 @@ void LLVMInitializePowerPCAsmPrinter();
416
+#if LLVM_VERSION < 32
417
+#include "llvm/Analysis/DebugInfo.h"
419
+#include "llvm/DebugInfo.h"
422
+#if LLVM_VERSION < 32
423
+#include "llvm/Support/IRBuilder.h"
424
+#include "llvm/Target/TargetData.h"
425
+#elif LLVM_VERSION < 33
426
+#include "llvm/IRBuilder.h"
427
+#include "llvm/DataLayout.h"
429
+#include "llvm/IR/IRBuilder.h"
430
+#include "llvm/IR/DataLayout.h"
433
+#if LLVM_VERSION < 33
434
+#include "llvm/CallingConv.h"
435
+#include "llvm/DerivedTypes.h"
436
+#include "llvm/Function.h"
437
+#include "llvm/LLVMContext.h"
438
+#include "llvm/Intrinsics.h"
439
+#include "llvm/Module.h"
441
+#include "llvm/IR/CallingConv.h"
442
+#include "llvm/IR/DerivedTypes.h"
443
+#include "llvm/IR/Function.h"
444
+#include "llvm/IR/LLVMContext.h"
445
+#include "llvm/IR/Intrinsics.h"
446
+#include "llvm/IR/Module.h"
449
+#if LLVM_VERSION >= 34
450
+#include "llvm/Analysis/CFG.h"
456
#include "llvm/Config/config.h"
457
+#ifdef ENABLE_THREADS
459
#error "Thread support was explicitly disabled. Cannot continue"
463
+#ifdef LLVM_ENABLE_THREADS
464
+#if !LLVM_ENABLE_THREADS
465
+#error "Thread support was explicitly disabled. Cannot continue"
469
#ifdef _GLIBCXX_PARALLEL
470
#error "libstdc++ parallel mode is not supported for ClamAV. Please remove -D_GLIBCXX_PARALLEL from CXXFLAGS!"
471
@@ -274,7 +314,11 @@ static void NORETURN jit_ssp_handler(void)
472
jit_exception_handler();
475
+#if LLVM_VERSION < 33
476
void llvm_error_handler(void *user_data, const std::string &reason)
478
+void llvm_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag = true)
481
// Output it to stderr, it might exceed the 1k/4k limit of cli_errmsg
482
cli_errmsg("[Bytecode JIT]: [LLVM error] %s\n", reason.c_str());
483
@@ -383,7 +427,11 @@ class NotifyListener : public JITEventListener {
486
cli_dbgmsg_internal("[Bytecode JIT]: emitted function %s of %ld bytes at %p\n",
487
+#if LLVM_VERSION < 31
488
F.getNameStr().c_str(), (long)Size, Code);
490
+ F.getName().str().c_str(), (long)Size, Code);
495
@@ -676,8 +724,13 @@ class RuntimeLimits : public FunctionPass {
496
CallInst* AbrtC = CallInst::Create(func_abort, "", AbrtBB);
497
AbrtC->setCallingConv(CallingConv::C);
498
AbrtC->setTailCall(true);
499
+#if LLVM_VERSION < 32
500
AbrtC->setDoesNotReturn(true);
501
AbrtC->setDoesNotThrow(true);
503
+ AbrtC->setDoesNotReturn();
504
+ AbrtC->setDoesNotThrow();
506
new UnreachableInst(F.getContext(), AbrtBB);
507
IRBuilder<false> Builder(F.getContext());
509
@@ -1027,7 +1080,11 @@ class LLVMCodegen {
510
: bc(bc), M(M), Context(M->getContext()), EE(EE),
511
PM(PM),PMUnsigned(PMUnsigned), TypeMap(), apiFuncs(apiFuncs),apiMap(apiMap),
512
compiledFunctions(cFuncs), BytecodeID("bc"+Twine(bc->id)),
513
+#if LLVM_VERSION < 32
514
Folder(EE->getTargetData()), Builder(Context, Folder), Values(), CF(CF) {
516
+ Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) {
519
for (unsigned i=0;i<cli_apicall_maxglobal - _FIRST_GLOBAL;i++) {
520
unsigned id = cli_globals[i].globalid;
521
@@ -1158,7 +1215,11 @@ class LLVMCodegen {
523
V = SI->getOperand(0);
525
+#if LLVM_VERSION < 32
526
if (EE->getTargetData()->getPointerSize() == 8) {
528
+ if (EE->getDataLayout()->getPointerSize() == 8) {
530
// eliminate useless trunc, GEP can take i64 too
531
if (TruncInst *I = dyn_cast<TruncInst>(V)) {
532
Value *Src = I->getOperand(0);
533
@@ -1233,7 +1294,12 @@ class LLVMCodegen {
534
Functions[j]->setLinkage(GlobalValue::InternalLinkage);
536
/* bb #2270, this should really be fixed either by LLVM or GCC.*/
537
+#if LLVM_VERSION < 32
538
Functions[j]->addFnAttr(Attribute::constructStackAlignmentFromInt(16));
540
+ // TODO: How does this translate?
541
+// Functions[j]->addFnAttr(Attribute::StackAlignment);
545
constType *I32Ty = Type::getInt32Ty(Context);
546
@@ -1534,7 +1600,11 @@ class LLVMCodegen {
548
CallInst *CI = Builder.CreateCall(DestF, ARRAYREF(Value*, args.begin(), args.end()));
549
CI->setCallingConv(CallingConv::Fast);
550
+#if LLVM_VERSION < 32
551
CI->setDoesNotThrow(true);
553
+ CI->setDoesNotThrow();
555
if (CI->getType()->getTypeID() != Type::VoidTyID)
556
Store(inst->dest, CI);
558
@@ -1555,7 +1625,11 @@ class LLVMCodegen {
559
args.push_back(convertOperand(func, DestF->getFunctionType()->getParamType(a+1), op));
561
CallInst *CI = Builder.CreateCall(DestF, ARRAYREFVECTOR(Value*, args));
562
+#if LLVM_VERSION < 32
563
CI->setDoesNotThrow(true);
565
+ CI->setDoesNotThrow();
567
Store(inst->dest, CI);
570
@@ -1688,7 +1762,11 @@ class LLVMCodegen {
571
Dst = Builder.CreatePointerCast(Dst, PointerType::getUnqual(Type::getInt8Ty(Context)));
572
Value *Src = convertOperand(func, inst, inst->u.three[1]);
573
Src = Builder.CreatePointerCast(Src, PointerType::getUnqual(Type::getInt8Ty(Context)));
574
+#if LLVM_VERSION < 32
575
Value *Len = convertOperand(func, EE->getTargetData()->getIntPtrType(Context), inst->u.three[2]);
577
+ Value *Len = convertOperand(func, EE->getDataLayout()->getIntPtrType(Context), inst->u.three[2]);
579
CallInst *c = Builder.CreateCall3(CF->FRealmemcmp, Dst, Src, Len);
580
c->setTailCall(true);
581
c->setDoesNotThrow();
582
@@ -1713,7 +1791,11 @@ class LLVMCodegen {
584
CallInst *C = Builder.CreateCall(CF->FBSwap16, convertOperand(func, inst, inst->u.unaryop));
585
C->setTailCall(true);
586
+#if LLVM_VERSION < 32
587
C->setDoesNotThrow(true);
589
+ C->setDoesNotThrow();
591
Store(inst->dest, C);
594
@@ -1721,7 +1803,11 @@ class LLVMCodegen {
596
CallInst *C = Builder.CreateCall(CF->FBSwap32, convertOperand(func, inst, inst->u.unaryop));
597
C->setTailCall(true);
598
+#if LLVM_VERSION < 32
599
C->setDoesNotThrow(true);
601
+ C->setDoesNotThrow();
603
Store(inst->dest, C);
606
@@ -1729,7 +1815,11 @@ class LLVMCodegen {
608
CallInst *C = Builder.CreateCall(CF->FBSwap64, convertOperand(func, inst, inst->u.unaryop));
609
C->setTailCall(true);
610
+#if LLVM_VERSION < 32
611
C->setDoesNotThrow(true);
613
+ C->setDoesNotThrow();
615
Store(inst->dest, C);
618
@@ -1834,7 +1924,11 @@ class LLVMCodegen {
619
// entrypoint can only be C, emit wrapper
620
Function *F = Function::Create(Functions[0]->getFunctionType(),
621
Function::ExternalLinkage,
622
+#if LLVM_VERSION < 33
623
Functions[0]->getName()+"_wrap", M);
625
+ Functions[0]->getName().str()+"_wrap", M);
627
F->setDoesNotThrow();
628
BasicBlock *BB = BasicBlock::Create(Context, "", F);
629
std::vector<Value*> Args;
630
@@ -1893,8 +1987,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
632
CF->FHandler->setDoesNotReturn();
633
CF->FHandler->setDoesNotThrow();
634
+#if LLVM_VERSION == 32
635
+ CF->FHandler->addFnAttr(Attributes::NoInline);
637
CF->FHandler->addFnAttr(Attribute::NoInline);
640
EE->addGlobalMapping(CF->FHandler, (void*)(intptr_t)jit_exception_handler);
641
EE->InstallLazyFunctionCreator(noUnknownFunctions);
642
EE->getPointerToFunction(CF->FHandler);
643
@@ -1917,7 +2014,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
646
CF->FMemset->setDoesNotThrow();
647
+#if LLVM_VERSION < 32
648
CF->FMemset->setDoesNotCapture(1, true);
650
+ CF->FMemset->setDoesNotCapture(1);
654
args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
655
@@ -1937,7 +2038,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
658
CF->FMemmove->setDoesNotThrow();
659
+#if LLVM_VERSION < 32
660
CF->FMemmove->setDoesNotCapture(1, true);
662
+ CF->FMemmove->setDoesNotCapture(1);
665
CF->FMemcpy = Function::Create(FuncTy_4, GlobalValue::ExternalLinkage,
667
@@ -1947,7 +2052,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
670
CF->FMemcpy->setDoesNotThrow();
671
+#if LLVM_VERSION < 32
672
CF->FMemcpy->setDoesNotCapture(1, true);
674
+ CF->FMemcpy->setDoesNotCapture(1);
678
args.push_back(Type::getInt16Ty(Context));
679
@@ -1987,7 +2096,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M
681
args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
682
args.push_back(PointerType::getUnqual(Type::getInt8Ty(Context)));
683
+#if LLVM_VERSION < 32
684
args.push_back(EE->getTargetData()->getIntPtrType(Context));
686
+ args.push_back(EE->getDataLayout()->getIntPtrType(Context));
688
FuncTy_5 = FunctionType::get(Type::getInt32Ty(Context),
690
CF->FRealmemcmp = Function::Create(FuncTy_5, GlobalValue::ExternalLinkage, "memcmp", M);
691
@@ -2214,12 +2327,19 @@ static void setGuard(unsigned char* guardbuf)
693
cl_hash_data("md5", salt, 48, guardbuf, NULL);
696
+#if LLVM_VERSION < 32
697
static void addFPasses(FunctionPassManager &FPM, bool trusted, const TargetData *TD)
699
+static void addFPasses(FunctionPassManager &FPM, bool trusted, const DataLayout *TD)
702
// Set up the optimizer pipeline. Start with registering info about how
703
// the target lays out data structures.
704
+#if LLVM_VERSION < 32
705
FPM.add(new TargetData(*TD));
707
+ FPM.add(new DataLayout(*TD));
709
// Promote allocas to registers.
710
FPM.add(createPromoteMemoryToRegisterPass());
711
FPM.add(new BrSimplifier());
712
@@ -2241,6 +2361,24 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
714
std::string ErrorMsg;
715
EngineBuilder builder(M);
717
+#if LLVM_VERSION >= 31
718
+ TargetOptions Options;
720
+ //disable this for now, it leaks
721
+ Options.JITEmitDebugInfo = false;
722
+// Options.JITEmitDebugInfo = true;
724
+ Options.JITEmitDebugInfo = false;
726
+#if LLVM_VERSION < 34
727
+ Options.DwarfExceptionHandling = false;
729
+ // TODO: How to do this now?
731
+ builder.setTargetOptions(Options);
734
builder.setErrorStr(&ErrorMsg);
735
builder.setEngineKind(EngineKind::JIT);
736
builder.setOptLevel(CodeGenOpt::Default);
737
@@ -2265,11 +2403,24 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
738
addFunctionProtos(&CF, EE, M);
740
FunctionPassManager OurFPM(M), OurFPMUnsigned(M);
741
+#if LLVM_VERSION < 32
742
M->setDataLayout(EE->getTargetData()->getStringRepresentation());
744
+ M->setDataLayout(EE->getDataLayout()->getStringRepresentation());
746
+#if LLVM_VERSION < 31
747
M->setTargetTriple(sys::getHostTriple());
750
+ M->setTargetTriple(sys::getDefaultTargetTriple());
752
+#if LLVM_VERSION < 32
753
addFPasses(OurFPM, true, EE->getTargetData());
754
addFPasses(OurFPMUnsigned, false, EE->getTargetData());
756
+ addFPasses(OurFPM, true, EE->getDataLayout());
757
+ addFPasses(OurFPMUnsigned, false, EE->getDataLayout());
761
//TODO: create a wrapper that calls pthread_getspecific
762
unsigned maxh = cli_globals[0].offset + sizeof(struct cli_bc_hooks);
763
@@ -2376,7 +2527,11 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
767
+#if LLVM_VERSION < 32
768
PM.add(new TargetData(*EE->getTargetData()));
770
+ PM.add(new DataLayout(*EE->getDataLayout()));
772
// TODO: only run this on the untrusted bytecodes, not all of them...
774
PM.add(createClamBCRTChecks());
775
@@ -2441,11 +2596,17 @@ int bytecode_init(void)
776
llvm_install_error_handler(llvm_error_handler);
778
sys::PrintStackTraceOnErrorSignal();
779
+#if LLVM_VERSION >= 34
780
+ llvm::EnablePrettyStackTrace();
783
+#if LLVM_VERSION < 34
784
llvm::DisablePrettyStackTrace = true;
789
+#if LLVM_VERSION < 31
791
//disable this for now, it leaks
792
llvm::JITEmitDebugInfo = false;
793
@@ -2454,6 +2615,7 @@ int bytecode_init(void)
794
llvm::JITEmitDebugInfo = false;
796
llvm::DwarfExceptionHandling = false;
798
llvm_start_multithreaded();
800
// If we have a native target, initialize it to ensure it is linked in and
801
@@ -2612,7 +2774,11 @@ namespace ClamBCModule {
802
void stop(const char *msg, llvm::Function* F, llvm::Instruction* I)
804
if (F && F->hasName()) {
805
+#if LLVM_VERSION < 31
806
cli_warnmsg("[Bytecode JIT] in function %s: %s", F->getNameStr().c_str(), msg);
808
+ cli_warnmsg("[Bytecode JIT] in function %s: %s", F->getName().str().c_str(), msg);
811
cli_warnmsg("[Bytecode JIT] %s", msg);
813
@@ -2679,7 +2845,12 @@ static const DbgDeclareInst *findDbgDeclare(const Value *V) {
814
static bool getLocationInfo(const Value *V, std::string &DisplayName,
815
std::string &Type, unsigned &LineNo,
816
std::string &File, std::string &Dir) {
817
+#if LLVM_VERSION < 33
825
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
826
@@ -2691,7 +2862,12 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
829
LineNo = Var.getLineNumber();
830
+#if LLVM_VERSION < 33
831
Unit = Var.getCompileUnit();
833
+ G = Var.getFilename();
834
+ H = Var.getDirectory();
836
TypeD = Var.getType();
837
} else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){
838
Value *DIF = findDbgSubprogramDeclare(F);
839
@@ -2702,7 +2878,12 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
842
LineNo = Var.getLineNumber();
843
+#if LLVM_VERSION < 33
844
Unit = Var.getCompileUnit();
846
+ G = Var.getFilename();
847
+ H = Var.getDirectory();
849
TypeD = Var.getType();
851
const DbgDeclareInst *DDI = findDbgDeclare(V);
852
@@ -2713,19 +2894,27 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName,
855
LineNo = Var.getLineNumber();
856
+#if LLVM_VERSION < 33
857
Unit = Var.getCompileUnit();
859
+ // getFilename and getDirectory are not defined
863
TypeD = Var.getType();
866
StringRef T = TypeD.getName();
869
- StringRef F = Unit.getFilename();
872
- StringRef D = Unit.getDirectory();
875
+#if LLVM_VERSION < 33
876
+ StringRef G = Unit.getFilename();
877
+ StringRef H = Unit.getDirectory();
886
diff --git a/libclamav/c++/configure.ac b/libclamav/c++/configure.ac
887
index db2b9cf..1c50ffd 100644
888
--- a/libclamav/c++/configure.ac
889
+++ b/libclamav/c++/configure.ac
890
@@ -16,7 +16,6 @@ dnl MA 02110-1301, USA.
892
AC_INIT([libclamavc++],[devel],[http://bugs.clamav.net])
893
AC_CONFIG_AUX_DIR([config])
894
-AC_CONFIG_SRCDIR([llvm/configure])
895
AC_CONFIG_MACRO_DIR([m4])
896
AC_CONFIG_HEADER([clamavcxx-config.h])
898
@@ -59,10 +58,7 @@ AC_ARG_WITH([system-llvm], AC_HELP_STRING([-with-system-llvm],
900
llvmconfig="$withval"
901
llvmver=`$llvmconfig --version`
902
- if test "$llvmver" != "2.9" && test "$llvmver" != "3.0svn" &&
903
- test "$llvmver" != "3.0"; then
904
- AC_MSG_ERROR([LLVM 2.9 required, but "$llvmver" found])
907
AC_SUBST(LLVMCONFIG_CXXFLAGS, [`$llvmconfig --cxxflags`])
908
AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
909
AC_SUBST(LLVMCONFIG_LIBS, [`$llvmconfig --libs jit nativecodegen scalaropts ipo`])
910
@@ -75,9 +71,24 @@ AC_ARG_WITH([system-llvm], AC_HELP_STRING([-with-system-llvm],
914
+AC_MSG_CHECKING([for supported LLVM version])
915
if test "x$llvmconfig" = "x"; then
916
AC_CONFIG_SUBDIRS([llvm])
917
+ llvmver=`llvm/configure --version | sed -n 1p | sed 's/llvm configure //'`
920
+llvmver_int=`echo "$llvmver" | sed -e 's/\([[0-9]]\)\.\([[0-9]]\).*/\1\2/g'`
922
+if test $llvmver_int -lt 28; then
923
+ AC_MSG_RESULT([no ($llvmver)])
924
+ AC_MSG_ERROR([LLVM >= 2.8 required, but "$llvmver" found])
925
+elif test $llvmver_int -gt 34; then
926
+ AC_MSG_RESULT([no ($llvmver)])
927
+ AC_MSG_ERROR([LLVM <= 3.4 required, but "$llvmver" found])
929
+AC_MSG_RESULT([ok ($llvmver; $llvmver_int)])
931
+AC_SUBST([LLVM_VERSION], [$llvmver_int])
933
AC_ARG_ENABLE([llvm],AC_HELP_STRING([-enable-llvm],
934
[Enable 'llvm' JIT/verifier support @<:@default=auto@:>@]),
935
diff --git a/libclamav/c++/detect.cpp b/libclamav/c++/detect.cpp
936
index 880255e..0dc6382 100644
937
--- a/libclamav/c++/detect.cpp
938
+++ b/libclamav/c++/detect.cpp
939
@@ -56,16 +56,27 @@ static void warn_assumptions(const char *msg, int a, int b)
941
void cli_detect_env_jit(struct cli_environment *env)
943
+#if LLVM_VERSION < 31
944
std::string host_triple = sys::getHostTriple();
946
+ std::string host_triple = sys::getDefaultTargetTriple();
948
INIT_STRFIELD(env->triple, host_triple.c_str());
950
std::string cpu = sys::getHostCPUName();
951
INIT_STRFIELD(env->cpu, cpu.c_str());
953
+#if LLVM_VERSION < 33
954
if (env->big_endian != (int)sys::isBigEndianHost()) {
955
warn_assumptions("host endianness", env->big_endian, sys::isBigEndianHost());
956
env->big_endian = sys::isBigEndianHost();
959
+ if (env->big_endian != (int)sys::IsBigEndianHost) {
960
+ warn_assumptions("host endianness", env->big_endian, sys::IsBigEndianHost);
961
+ env->big_endian = sys::IsBigEndianHost;
966
env->cpp_version = MAKE_VERSION(0, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
967
@@ -149,7 +160,9 @@ void cli_detect_env_jit(struct cli_environment *env)
969
CASE_OS(NetBSD, os_bsd);
970
CASE_OS(OpenBSD, os_bsd);
971
+#if LLVM_VERSION < 31
972
CASE_OS(Psp, os_unknown);
974
CASE_OS(Solaris, os_solaris);
976
env->os = llvm_os_Win32;