From e862f96ab70fa1dc1ef01300645dfb4722b3c2170dd31e978827ca6a23cb364b Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Thu, 16 Mar 2017 16:19:41 +0000 Subject: [PATCH] fix build & update OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=12 --- ...LEE-compile-against-LLVM-3.5-and-3.6.patch | 740 +++++------------ ...OSIX-make-it-compile-with-glibc-2.25.patch | 65 ++ 0002-Make-KLEE-compile-against-LLVM-3.7.patch | 247 ++---- 0003-Make-KLEE-compile-against-LLVM-3.8.patch | 761 ++---------------- _servicedata | 2 +- klee-1.3.0+20170221.tar.xz | 3 - klee-1.3.0+20170307.tar.xz | 3 + klee.changes | 22 + klee.spec | 6 +- 9 files changed, 481 insertions(+), 1368 deletions(-) create mode 100644 0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch delete mode 100644 klee-1.3.0+20170221.tar.xz create mode 100644 klee-1.3.0+20170307.tar.xz diff --git a/0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch b/0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch index 7b391b2..f596fba 100644 --- a/0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch +++ b/0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch @@ -1,6 +1,6 @@ From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= Date: Sun, 1 May 2016 16:38:21 +0200 -Subject: Make KLEE compile against LLVM 3.5 and 3.6 +Subject: llvm: make KLEE compile against LLVM 3.5 and 3.6 Patch-mainline: no Based on work by @ccadeptic23 and @delcypher. @@ -8,112 +8,54 @@ Formatting fixed by @snf. Fix compiler warning by @martijnthe. Further fixes by @mchalupa. -Signed-off-by: Jiri Slaby ---- - Makefile.rules | 10 +- - lib/Core/Executor.cpp | 43 ++++++-- - lib/Core/ExternalDispatcher.cpp | 34 ++++-- - lib/Core/ExternalDispatcher.h | 8 +- - lib/Core/StatsTracker.cpp | 11 +- - lib/Module/KModule.cpp | 27 +++-- - lib/Module/ModuleUtil.cpp | 225 +++++++++++++++++++++++++++----------- - lib/Module/Optimize.cpp | 17 ++- - lib/Module/RaiseAsm.cpp | 17 ++- - lib/Solver/QueryLoggingSolver.cpp | 5 +- - lib/Solver/QueryLoggingSolver.h | 3 + - lib/Support/CompressionStream.cpp | 19 +++- - test/lit.cfg | 2 +- - tools/klee/Makefile | 10 +- - tools/klee/main.cpp | 31 +++++- - 15 files changed, 341 insertions(+), 121 deletions(-) +Refactored, so that changes can be reviewed -- no massive changes in +whitespace and in the surrounding code. + +Signed-off-by: Jiri Slaby +--- + lib/Core/Executor.cpp | 25 +++++++- + lib/Core/ExternalDispatcher.cpp | 18 ++++++ + lib/Core/ExternalDispatcher.h | 6 ++ + lib/Core/StatsTracker.cpp | 11 ++-- + lib/Module/KModule.cpp | 13 ++++- + lib/Module/ModuleUtil.cpp | 117 +++++++++++++++++++++++++++++++++----- + lib/Module/Optimize.cpp | 14 +++-- + lib/Module/RaiseAsm.cpp | 13 ++++- + lib/Solver/QueryLoggingSolver.cpp | 8 ++- + lib/Support/CompressionStream.cpp | 10 +++- + test/lit.cfg | 2 +- + tools/klee/Makefile | 10 +++- + tools/klee/main.cpp | 16 +++++- + 13 files changed, 227 insertions(+), 36 deletions(-) -diff --git a/Makefile.rules b/Makefile.rules -index d74b1c42b4aa..06cbbec683f2 100644 ---- a/Makefile.rules -+++ b/Makefile.rules -@@ -1618,16 +1618,22 @@ $(ObjDir)/%.s: %.m $(ObjDir)/.dir $(BUILT_SOURCES) - $(Compile.C) $< -o $@ -S - - -+#which PARAM to send to LOPT -+LOPT_PARAM = -std-compile-opts -+ifeq ($(shell python -c "print($(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR) >= 3.6)"), True) -+LOPT_PARAM = -std-link-opts -+endif -+ - # make the C and C++ compilers strip debug info out of bytecode libraries. - ifdef DEBUG_RUNTIME - $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT) - $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)" -- $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -+ $(Verb) $(LLVMAS) $< -o - | $(LOPT) $(LOPT_PARAM) -o $@ - else - $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT) - $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)" - $(Verb) $(LLVMAS) $< -o - | \ -- $(LOPT) -std-compile-opts -strip-debug -o $@ -+ $(LOPT) $(LOPT_PARAM) -strip-debug -o $@ - endif - - diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp -index 58603e7ca146..80b8289d1486 100644 +index 95812dd72587..4148ca22caf3 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp -@@ -82,6 +82,7 @@ +@@ -81,6 +81,7 @@ + #include "llvm/ADT/StringExtras.h" + #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" ++#include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" -+#include "llvm/Support/FileSystem.h" - #if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) - #include "llvm/Support/CallSite.h" -@@ -93,6 +94,10 @@ - #include "klee/Internal/Support/CompressionStream.h" - #endif - -+#if LLVM_VERSION_CODE > LLVM_VERSION(3, 5) -+#include -+#endif -+ - #include - #include - #include -@@ -376,12 +381,19 @@ Executor::Executor(const InterpreterOptions &opts, InterpreterHandler *ih) - optionIsSet(DebugPrintInstructions, FILE_SRC)) { - std::string debug_file_name = - interpreterHandler->getOutputFilename("instructions.txt"); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ std::error_code EC; -+#endif - std::string ErrorInfo; -+ - #ifdef HAVE_ZLIB_H +@@ -383,7 +384,13 @@ Executor::Executor(LLVMContext &ctx, const InterpreterOptions &opts, if (!DebugCompressInstructions) { #endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ debugInstFile = new llvm::raw_fd_ostream(debug_file_name.c_str(), EC, ++ std::error_code ec; ++ debugInstFile = new llvm::raw_fd_ostream(debug_file_name.c_str(), ec, + llvm::sys::fs::OpenFlags::F_Text); ++ if (ec) ++ ErrorInfo = ec.message(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) debugInstFile = new llvm::raw_fd_ostream(debug_file_name.c_str(), ErrorInfo, llvm::sys::fs::OpenFlags::F_Text); #else -@@ -394,7 +406,12 @@ Executor::Executor(const InterpreterOptions &opts, InterpreterHandler *ih) - (debug_file_name + ".gz").c_str(), ErrorInfo); - } - #endif -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ if (EC) { -+ ErrorInfo = EC.message(); -+#else - if (ErrorInfo != "") { -+#endif - klee_error("Could not open file %s : %s", debug_file_name.c_str(), - ErrorInfo.c_str()); - } -@@ -1471,9 +1488,13 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) { +@@ -1479,9 +1486,13 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) { while (true) { if (GlobalValue *gv = dyn_cast(c)) { @@ -128,36 +70,7 @@ index 58603e7ca146..80b8289d1486 100644 std::string alias = state.getFnAlias(gv->getName()); if (alias != "") { llvm::Module* currModule = kmodule->module; -@@ -1484,7 +1505,7 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) { - old_gv->getName().str().c_str()); - } - } -- -+ - if (Function *f = dyn_cast(gv)) - return f; - else if (GlobalAlias *ga = dyn_cast(gv)) -@@ -1646,8 +1667,8 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { - if (ConstantExpr *CE = dyn_cast(cond)) { - // Somewhat gross to create these all the time, but fine till we - // switch to an internal rep. -- LLVM_TYPE_Q llvm::IntegerType *Ty = -- cast(si->getCondition()->getType()); -+ LLVM_TYPE_Q llvm::IntegerType *Ty = -+ cast(si->getCondition()->getType()); - ConstantInt *ci = ConstantInt::get(Ty, CE->getZExtValue()); - #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) - unsigned index = si->findCaseValue(ci).getSuccessorIndex(); -@@ -1703,7 +1724,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { - bool result; - bool success = solver->mayBeTrue(state, match, result); - assert(success && "FIXME: Unhandled solver failure"); -- (void) success; -+ (void)success; - if (result) { - BasicBlock *caseSuccessor = it->second; - -@@ -3072,8 +3093,16 @@ void Executor::callExternalFunction(ExecutionState &state, +@@ -3080,8 +3091,16 @@ void Executor::callExternalFunction(ExecutionState &state, else klee_warning_once(function, "%s", os.str().c_str()); } @@ -166,7 +79,7 @@ index 58603e7ca146..80b8289d1486 100644 + // MCJIT needs unique module, so we create quick external dispatcher for call. + // reference: + // http://blog.llvm.org/2013/07/using-mcjit-with-kaleidoscope-tutorial.html -+ ExternalDispatcher *e = new ExternalDispatcher(); ++ ExternalDispatcher *e = new ExternalDispatcher(function->getContext()); + bool success = e->executeCall(function, target->inst, args); + delete e; +#else @@ -176,7 +89,7 @@ index 58603e7ca146..80b8289d1486 100644 terminateStateOnError(state, "failed external call: " + function->getName(), External); diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp -index ecc9912e9b57..09dd715a53ae 100644 +index 984e3ab2e4a4..9701d35add85 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -23,7 +23,12 @@ @@ -192,8 +105,8 @@ index ecc9912e9b57..09dd715a53ae 100644 #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/raw_ostream.h" -@@ -89,7 +94,12 @@ ExternalDispatcher::ExternalDispatcher() { - dispatchModule = new Module("ExternalDispatcher", getGlobalContext()); +@@ -89,7 +94,12 @@ ExternalDispatcher::ExternalDispatcher(LLVMContext &ctx) { + dispatchModule = new Module("ExternalDispatcher", ctx); std::string error; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) @@ -205,7 +118,7 @@ index ecc9912e9b57..09dd715a53ae 100644 if (!executionEngine) { llvm::errs() << "unable to make jit: " << error << "\n"; abort(); -@@ -98,6 +108,10 @@ ExternalDispatcher::ExternalDispatcher() { +@@ -98,6 +108,10 @@ ExternalDispatcher::ExternalDispatcher(LLVMContext &ctx) { // If we have a native target, initialize it to ensure it is linked in and // usable by the JIT. llvm::InitializeNativeTarget(); @@ -228,68 +141,33 @@ index ecc9912e9b57..09dd715a53ae 100644 } } else { dispatcher = it->second; -@@ -205,13 +223,12 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in - Value **args = new Value*[cs.arg_size()]; - - std::vector nullary; -- -- Function *dispatcher = Function::Create(FunctionType::get(Type::getVoidTy(getGlobalContext()), -- nullary, false), -- GlobalVariable::ExternalLinkage, -- "", -- dispatchModule); - -+ // For MCJIT functions need unique names, or wrong func can be called -+ Function *dispatcher = Function::Create( -+ FunctionType::get(Type::getVoidTy(getGlobalContext()), nullary, false), -+ GlobalVariable::ExternalLinkage, "dispatcher_" + target->getName().str(), -+ dispatchModule); - - BasicBlock *dBB = BasicBlock::Create(getGlobalContext(), "entry", dispatcher); - -@@ -254,9 +271,8 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in - dispatchModule->getOrInsertFunction(target->getName(), FTy, - target->getAttributes()); - #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) -- Instruction *result = CallInst::Create(dispatchTarget, -- llvm::ArrayRef(args, args+i), -- "", dBB); -+ Instruction *result = CallInst::Create( -+ dispatchTarget, llvm::ArrayRef(args, args + i), "", dBB); - #else - Instruction *result = CallInst::Create(dispatchTarget, args, args+i, "", dBB); - #endif diff --git a/lib/Core/ExternalDispatcher.h b/lib/Core/ExternalDispatcher.h -index d8d9dc58b089..e2fb63cd12b4 100644 +index 94363bab5ffc..d869eb6fe0ca 100644 --- a/lib/Core/ExternalDispatcher.h +++ b/lib/Core/ExternalDispatcher.h -@@ -9,11 +9,11 @@ - +@@ -10,7 +10,10 @@ #ifndef KLEE_EXTERNALDISPATCHER_H #define KLEE_EXTERNALDISPATCHER_H -- + +#include "klee/Config/Version.h" ++ #include ++#include #include #include -- -+#include - namespace llvm { - class ExecutionEngine; - class Instruction; -@@ -27,6 +27,10 @@ namespace klee { + +@@ -28,6 +31,9 @@ namespace klee { private: typedef std::map dispatchers_ty; dispatchers_ty dispatchers; -+ -+ #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + std::unique_ptr dispatchModule_uniptr; -+ #endif ++#endif llvm::Module *dispatchModule; llvm::ExecutionEngine *executionEngine; std::map preboundFunctions; diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp -index dbd865248756..ded85f950fe4 100644 +index e8192a8ed754..b93796ecdff7 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -206,13 +206,16 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename, @@ -297,12 +175,12 @@ index dbd865248756..ded85f950fe4 100644 SmallString<128> current(objectFilename); if(sys::fs::make_absolute(current)) { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ Twine current_twine(current.str()); // requires a twine for this. so silly ++ Twine current_twine(current.str()); // requires a twine for this + if (!sys::fs::exists(current_twine)) { -+#elif LLVM_VERSION_CODE == LLVM_VERSION(3, 5) ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + bool exists = false; + if (!sys::fs::exists(current.str(), exists)) { -+#elif LLVM_VERSION_CODE < LLVM_VERSION(3, 5) ++#else bool exists = false; - -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) @@ -314,100 +192,75 @@ index dbd865248756..ded85f950fe4 100644 objectFilename = current.c_str(); } diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp -index 57346a315a1b..598c439f9da0 100644 +index 08ec28efc1f6..45dc34bfec46 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp -@@ -144,11 +144,9 @@ static Function *getStubFunctionForCtorList(Module *m, - - std::vector nullary; - -- Function *fn = Function::Create(FunctionType::get(Type::getVoidTy(getGlobalContext()), -- nullary, false), -- GlobalVariable::InternalLinkage, -- name, -- m); -+ Function *fn = Function::Create( -+ FunctionType::get(Type::getVoidTy(getGlobalContext()), nullary, false), -+ GlobalVariable::InternalLinkage, name, m); - BasicBlock *bb = BasicBlock::Create(getGlobalContext(), "entry", fn); - - // From lli: -@@ -158,8 +156,15 @@ static Function *getStubFunctionForCtorList(Module *m, +@@ -158,8 +158,14 @@ static Function *getStubFunctionForCtorList(Module *m, if (arr) { for (unsigned i=0; igetNumOperands(); i++) { ConstantStruct *cs = cast(arr->getOperand(i)); -- assert(cs->getNumOperands()==2 && "unexpected element in ctor initializer list"); -- -+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) -+ assert(cs->getNumOperands() == 2 && -+ "unexpected element in ctor initializer list"); -+#else ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + // There is a third *optional* element in global_ctor elements (``i8 + // @data``). + assert((cs->getNumOperands() == 2 || cs->getNumOperands() == 3) && + "unexpected element in ctor initializer list"); ++#else + assert(cs->getNumOperands()==2 && "unexpected element in ctor initializer list"); +- +#endif Constant *fp = cs->getOperand(1); if (!fp->isNullValue()) { if (llvm::ConstantExpr *ce = dyn_cast(fp)) -@@ -509,8 +514,12 @@ static int getOperandNum(Value *v, +@@ -513,8 +519,13 @@ static int getOperandNum(Value *v, return registerMap[inst]; } else if (Argument *a = dyn_cast(v)) { return a->getArgNo(); -- } else if (isa(v) || isa(v) || -- isa(v)) { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + // Metadata is no longer a Value + } else if (isa(v) || isa(v)) { +#else -+ } else if (isa(v) || isa(v) || isa(v)) { + } else if (isa(v) || isa(v) || + isa(v)) { +#endif return -1; } else { assert(isa(v)); diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp -index 2cd41c891181..537c9aba4b6f 100644 +index 83dc5045e711..c7f1c6d9d4a7 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp -@@ -212,78 +212,101 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er +@@ -212,15 +212,27 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading modules\n"); // Load all bitcode files in to memory so we can examine their symbols +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + for (object::Archive::child_iterator AI = archive->child_begin(), -+ AE = archive->child_end(); -+ AI != AE; ++AI) ++ AE = archive->child_end(); AI != AE; ++AI) +#else -+ for (object::Archive::child_iterator AI = archive->begin_children(), -- AE = archive->end_children(); AI != AE; ++AI) -+ AE = archive->end_children(); -+ AI != AE; ++AI) + AE = archive->end_children(); AI != AE; ++AI) +#endif { -- + StringRef memberName; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ ErrorOr errorOr_memberName = AI->getName(); -+ std::error_code ec = errorOr_memberName.getError(); -+ if (!ec) -+ memberName = errorOr_memberName.get(); ++ ErrorOr memberNameErr = AI->getName(); ++ std::error_code ec = memberNameErr.getError(); ++ if (!ec) { ++ memberName = memberNameErr.get(); +#else error_code ec = AI->getName(memberName); -- -- if ( ec == errc::success ) -- { + + if ( ec == errc::success ) + { +#endif -+ if (!ec) { KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading archive member " << memberName << "\n"); -- } -- else -- { -+ } else { - errorMessage="Archive member does not have a name!\n"; + } + else +@@ -229,17 +241,29 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er return false; } -- + +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + ErrorOr > child = AI->getAsBinary(); + ec = child.getError(); @@ -420,285 +273,170 @@ index 2cd41c891181..537c9aba4b6f 100644 + if (ec) { // If we can't open as a binary object file its hopefully a bitcode file - -- OwningPtr buff; // Once this is destroyed will Module still be valid?? ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ ErrorOr buff = AI->getMemoryBufferRef(); ++ ec = buff.getError(); ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ ErrorOr > buffErr = AI->getMemoryBuffer(); ++ std::unique_ptr buff = nullptr; ++ ec = buffErr.getError(); ++ if (!ec) ++ buff = std::move(buffErr.get()); ++#else + OwningPtr buff; // Once this is destroyed will Module still be valid?? - Module *Result = 0; - - if (error_code ec = AI->getMemoryBuffer(buff)) - { -- SS << "Failed to get MemoryBuffer: " <= LLVM_VERSION(3, 6) -+ ErrorOr buff = AI->getMemoryBufferRef(); -+ ec = buff.getError(); -+#elif LLVM_VERSION_CODE == LLVM_VERSION(3, 5) -+ ErrorOr > errorOr_buff = -+ AI->getMemoryBuffer(); -+ std::unique_ptr buff = nullptr; -+ ec = errorOr_buff.getError(); -+ if (!ec) -+ buff = std::move(errorOr_buff.get()); -+#else -+ OwningPtr buff; // Once this is destroyed will Module still -+ // be valid?? + ec = AI->getMemoryBuffer(buff); +#endif + if (ec) { -+ SS << "Failed to get MemoryBuffer: " << ec.message(); + SS << "Failed to get MemoryBuffer: " <= LLVM_VERSION(3, 5) -+ ErrorOr Result_error = -+ parseBitcodeFile(buff.get(), getGlobalContext()); -+ ec = Result_error.getError(); ++ ErrorOr resultErr = parseBitcodeFile(buff.get(), ++ composite->getContext()); ++ ec = resultErr.getError(); + if (ec) + errorMessage = ec.message(); + else -+ Result = Result_error.get(); ++ Result = resultErr.get(); +#else -+ Result = -+ ParseBitcodeFile(buff.get(), getGlobalContext(), &errorMessage); + Result = ParseBitcodeFile(buff.get(), composite->getContext(), + &errorMessage); +- +#endif -+ if (!Result) { + if(!Result) + { SS << "Loading module failed : " << errorMessage << "\n"; - SS.flush(); - return false; - } - archiveModules.push_back(Result); -- } -- else -- { -- errorMessage="Buffer was NULL!"; -+ } else { -+ errorMessage = "Buffer was NULL!"; - return false; - } -- -- } -- else if (object::ObjectFile *o = dyn_cast(child.get())) -- { -- SS << "Object file " << o->getFileName().data() << -- " in archive is not supported"; -+ } else if (child.get()->isObject()) { -+ SS << "Object file " << child.get()->getFileName().data() -+ << " in archive is not supported"; - SS.flush(); - return false; -- } -- else -- { -- SS << "Loading archive child with error "<< ec.message(); -+ } else { -+ SS << "Loading archive child with error " << ec.message(); - SS.flush(); - return false; - } -- - } - - KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loaded " << archiveModules.size() << " modules\n"); - -- - std::set previouslyUndefinedSymbols; - - // Walk through the modules looking for definitions of undefined symbols -@@ -315,9 +338,12 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - +@@ -317,8 +351,11 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Found " << GV->getName() << " in " << M->getModuleIdentifier() << "\n"); + - -- -- if (Linker::LinkModules(composite, M, Linker::DestroySource, &errorMessage)) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + if (Linker::LinkModules(composite, M)) +#else -+ if (Linker::LinkModules(composite, M, Linker::DestroySource, -+ &errorMessage)) + if (Linker::LinkModules(composite, M, Linker::DestroySource, &errorMessage)) +#endif { // Linking failed SS << "Linking archive module with composite failed:" << errorMessage; -@@ -358,8 +384,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - return true; - - } --#endif -- -+#endif // LLVM 3.3+ - - Module *klee::linkWithLibrary(Module *module, - const std::string &libraryName) { -@@ -369,11 +394,84 @@ Module *klee::linkWithLibrary(Module *module, - klee_error("Link with library %s failed. No such file.", +@@ -371,36 +408,86 @@ Module *klee::linkWithLibrary(Module *module, libraryName.c_str()); } -+#endif -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ ErrorOr > Buffer = -+ MemoryBuffer::getFile(libraryName); -+ std::error_code ec; -+ if ((ec = Buffer.getError())) { -+ klee_error("Link with library %s failed: %s", libraryName.c_str(), -+ ec.message().c_str()); -+ } -+ -+ sys::fs::file_magic magic = -+ sys::fs::identify_magic(Buffer.get()->getBuffer()); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ MemoryBufferRef buff = Buffer.get()->getMemBufferRef(); -+#else // LLVM 3.5 -+ MemoryBuffer *buff = Buffer->get(); -+#endif -+ LLVMContext &Context = getGlobalContext(); -+ std::string ErrorMessage; -+ -+ if (magic == sys::fs::file_magic::bitcode) { -+ ErrorOr Result = parseBitcodeFile(buff, Context); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ if ((ec = Buffer.getError()) || Linker::LinkModules(module, Result.get())) -+#else // LLVM 3.5 -+ if ((ec = Buffer.getError()) || -+ Linker::LinkModules(module, Result.get(), Linker::DestroySource, -+ &ErrorMessage)) -+#endif -+ klee_error("Link with library %s failed: %s", libraryName.c_str(), -+ ec.message().c_str()); -+ -+ delete Result.get(); -+ -+ } else if (magic == sys::fs::file_magic::archive) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ ErrorOr > arch = -+ object::createBinary(buff, &Context); -+#else // LLVM 3.5 -+ ErrorOr arch = -+ object::createBinary(std::move(Buffer.get()), &Context); -+#endif -+ if ((ec = arch.getError())) -+ klee_error("Link with library %s failed: %s", libraryName.c_str(), -+ arch.getError().message().c_str()); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ if (object::Archive *a = dyn_cast(arch->get())) { -+#else // LLVM 3.5 -+ if (object::Archive *a = dyn_cast(arch.get())) { -+#endif -+ // Handle in helper -+ if (!linkBCA(a, module, ErrorMessage)) -+ klee_error("Link with library %s failed: %s", libraryName.c_str(), -+ ErrorMessage.c_str()); -+ } else { -+ klee_error("Link with library %s failed: Cast to archive failed", -+ libraryName.c_str()); -+ } -+ -+ } else if (magic.is_object()) { -+ std::unique_ptr obj; -+ if (object::ObjectFile *o = dyn_cast(obj.get())) { -+ klee_warning("Link with library: Object file %s in archive %s found. " -+ "Currently not supported.", -+ o->getFileName().data(), libraryName.c_str()); -+ } -+ } else { -+ klee_error("Link with library %s failed: Unrecognized file type.", -+ libraryName.c_str()); -+ } -+ return module; -+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) -+ error_code ec; ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ ErrorOr > bufferErr = ++ MemoryBuffer::getFile(libraryName); ++ std::error_code ec = bufferErr.getError(); ++#else OwningPtr Buffer; - if (error_code ec = MemoryBuffer::getFile(libraryName,Buffer)) { -+ if (ec = MemoryBuffer::getFile(libraryName, Buffer)) { ++ error_code ec = MemoryBuffer::getFile(libraryName,Buffer); ++#endif ++ if (ec) { klee_error("Link with library %s failed: %s", libraryName.c_str(), -- ec.message().c_str()); -+ ec.message().c_str()); + ec.message().c_str()); } ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef(); ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ MemoryBuffer *Buffer = bufferErr->get(); ++#endif ++ ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer()); ++#else sys::fs::file_magic magic = sys::fs::identify_magic(Buffer->getBuffer()); -@@ -385,53 +483,52 @@ Module *klee::linkWithLibrary(Module *module, - Module *Result = 0; - Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage); ++#endif -- - if (!Result || Linker::LinkModules(module, Result, Linker::DestroySource, + LLVMContext &Context = module->getContext(); + std::string ErrorMessage; + + if (magic == sys::fs::file_magic::bitcode) { + Module *Result = 0; ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ ErrorOr ResultErr = parseBitcodeFile(Buffer, Context); ++ if ((ec = ResultErr.getError())) { ++ ErrorMessage = ec.message(); ++#else + Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage); ++ if (!Result) { ++#endif ++ klee_error("Link with library %s failed: %s", libraryName.c_str(), ++ ErrorMessage.c_str()); ++ } + ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ Result = ResultErr.get(); ++#endif + +- if (!Result || Linker::LinkModules(module, Result, Linker::DestroySource, - &ErrorMessage)) -+ &ErrorMessage)) ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ if (Linker::LinkModules(module, Result)) { ++ ErrorMessage = "linking error"; ++#else ++ if (Linker::LinkModules(module, Result, Linker::DestroySource, &ErrorMessage)) { ++#endif klee_error("Link with library %s failed: %s", libraryName.c_str(), -- ErrorMessage.c_str()); -+ ErrorMessage.c_str()); + ErrorMessage.c_str()); ++ } delete Result; } else if (magic == sys::fs::file_magic::archive) { ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ ErrorOr > arch = ++ object::createBinary(Buffer, &Context); ++ ec = arch.getError(); ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ ErrorOr arch = ++ object::createBinary(std::move(bufferErr.get()), &Context); ++ ec = arch.getError(); ++#else OwningPtr arch; - if (error_code ec = object::createBinary(Buffer.take(), arch)) -+ if (ec = object::createBinary(Buffer.take(), arch)) ++ ec = object::createBinary(Buffer.take(), arch); ++#endif ++ if (ec) klee_error("Link with library %s failed: %s", libraryName.c_str(), -- ec.message().c_str()); -+ ec.message().c_str()); + ec.message().c_str()); ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ if (object::Archive *a = dyn_cast(arch->get())) { ++#else if (object::Archive *a = dyn_cast(arch.get())) { ++#endif // Handle in helper if (!linkBCA(a, module, ErrorMessage)) klee_error("Link with library %s failed: %s", libraryName.c_str(), -- ErrorMessage.c_str()); -- } -- else { -- klee_error("Link with library %s failed: Cast to archive failed", libraryName.c_str()); -+ ErrorMessage.c_str()); -+ } else { -+ klee_error("Link with library %s failed: Cast to archive failed", -+ libraryName.c_str()); +@@ -411,7 +498,11 @@ Module *klee::linkWithLibrary(Module *module, } } else if (magic.is_object()) { ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++ std::unique_ptr obj; ++#else OwningPtr obj; - if (object::ObjectFile *o = dyn_cast(obj.get())) { ++#endif + if (obj.get()->isObject()) { klee_warning("Link with library: Object file %s in archive %s found. " -- "Currently not supported.", -- o->getFileName().data(), libraryName.c_str()); -+ "Currently not supported.", -+ o->getFileName().data(), libraryName.c_str()); - } - } else { - klee_error("Link with library %s failed: Unrecognized file type.", -- libraryName.c_str()); -+ libraryName.c_str()); - } - - return module; --#else -+#else // LLVM 3.2- - Linker linker("klee", module, false); - - llvm::sys::Path libraryPath(libraryName); - bool native = false; -- -+ - if (linker.LinkInFile(libraryPath, native)) { - klee_error("Linking library %s failed", libraryName.c_str()); - } -- -+ - return linker.releaseModule(); - #endif - } + "Currently not supported.", diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp -index 3d9c8cc17bf3..8cd592069523 100644 +index 3d9c8cc17bf3..c0f3f34ca8e8 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp -@@ -172,15 +172,20 @@ void Optimize(Module *M, const std::string &EntryPoint) { +@@ -172,15 +172,17 @@ void Optimize(Module *M, const std::string &EntryPoint) { if (VerifyEach) Passes.add(createVerifierPass()); @@ -706,27 +444,24 @@ index 3d9c8cc17bf3..8cd592069523 100644 - // Add an appropriate TargetData instance for this module... - addPass(Passes, new TargetData(M)); -#elif LLVM_VERSION_CODE < LLVM_VERSION(3, 5) -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) // Add an appropriate DataLayout instance for this module... -- addPass(Passes, new DataLayout(M)); --#else ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + DataLayoutPass *dlpass = new DataLayoutPass(); + dlpass->doInitialization(*M); + addPass(Passes, dlpass); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) - // Add an appropriate DataLayout instance for this module... - addPass(Passes, new DataLayoutPass(M)); -+#elif LLVM_VERSION_CODE > LLVM_VERSION(3, 1) -+ // Add an appropriate DataLayout instance for this module... -+ addPass(Passes, new DataLayout(M)); -+#else -+ // Add an appropriate TargetData instance for this module... ++ addPass(Passes, new DataLayoutPass(M)); ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) + addPass(Passes, new DataLayout(M)); + #else +- // Add an appropriate DataLayout instance for this module... +- addPass(Passes, new DataLayoutPass(M)); + addPass(Passes, new TargetData(M)); #endif // DWD - Run the opt standard pass list as well. diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp -index e612ca636465..bde9fba93c3a 100644 +index af92b74b41b0..5fc54ef17743 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp @@ -24,6 +24,10 @@ @@ -745,14 +480,12 @@ index e612ca636465..bde9fba93c3a 100644 TLI = 0; } else { -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) -- TM = NativeTarget->createTargetMachine(HostTriple, "", "", -- TargetOptions()); -+ +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions()); + TLI = TM->getSubtargetImpl()->getTargetLowering(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) -+ TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions()); + TM = NativeTarget->createTargetMachine(HostTriple, "", "", + TargetOptions()); + TLI = TM->getTargetLowering(); #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) TM = NativeTarget->createTargetMachine(HostTriple, "", ""); @@ -766,37 +499,26 @@ index e612ca636465..bde9fba93c3a 100644 triple = llvm::Triple(HostTriple); } diff --git a/lib/Solver/QueryLoggingSolver.cpp b/lib/Solver/QueryLoggingSolver.cpp -index a858a7d7ed87..80b14c13fc7c 100644 +index a858a7d7ed87..cf4966cd4861 100644 --- a/lib/Solver/QueryLoggingSolver.cpp +++ b/lib/Solver/QueryLoggingSolver.cpp -@@ -42,7 +42,10 @@ QueryLoggingSolver::QueryLoggingSolver(Solver *_solver, std::string path, +@@ -42,7 +42,13 @@ QueryLoggingSolver::QueryLoggingSolver(Solver *_solver, std::string path, #ifdef HAVE_ZLIB_H if (!CreateCompressedQueryLog) { #endif -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++ std::error_code ec; + os = new llvm::raw_fd_ostream(path.c_str(), ec, + llvm::sys::fs::OpenFlags::F_Text); ++ if (ec) ++ ErrorInfo = ec.message(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) os = new llvm::raw_fd_ostream(path.c_str(), ErrorInfo, llvm::sys::fs::OpenFlags::F_Text); #else -diff --git a/lib/Solver/QueryLoggingSolver.h b/lib/Solver/QueryLoggingSolver.h -index 7ac783d1211c..ba185aa10863 100644 ---- a/lib/Solver/QueryLoggingSolver.h -+++ b/lib/Solver/QueryLoggingSolver.h -@@ -27,6 +27,9 @@ protected: - Solver *solver; - std::string ErrorInfo; - llvm::raw_ostream *os; -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ std::error_code ec; -+#endif - // @brief Buffer used by logBuffer - std::string BufferString; - // @brief buffer to store logs before flushing to file diff --git a/lib/Support/CompressionStream.cpp b/lib/Support/CompressionStream.cpp -index eb208edfa395..58193c9a98a2 100644 +index eb208edfa395..363038786f6b 100644 --- a/lib/Support/CompressionStream.cpp +++ b/lib/Support/CompressionStream.cpp @@ -10,9 +10,11 @@ @@ -812,34 +534,21 @@ index eb208edfa395..58193c9a98a2 100644 #include #include #include -@@ -25,10 +27,19 @@ compressed_fd_ostream::compressed_fd_ostream(const char *Filename, - std::string &ErrorInfo) - : llvm::raw_ostream(), pos(0) { +@@ -27,9 +29,13 @@ compressed_fd_ostream::compressed_fd_ostream(const char *Filename, ErrorInfo = ""; --#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) // Open file in binary mode -+#if LLVM_VERSION_CODE == LLVM_VERSION(3, 4) - llvm::error_code EC = -- llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_Binary); -+#else -+ std::error_code EC = -+#endif -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) -+ llvm::sys::fs::openFileForWrite(Filename, FD, +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ llvm::sys::fs::F_None); -+#else -+ llvm::sys::fs::F_Binary); ++ std::error_code EC = ++ llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_None); ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) + llvm::error_code EC = + llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_Binary); +- +#endif - if (EC) { ErrorInfo = EC.message(); -@@ -116,4 +127,4 @@ void compressed_fd_ostream::write_file(const char *Ptr, size_t Size) { - } while (Size > 0); - } - } --#endif -+#endif // HAVE_ZLIB_H + FD = -1; diff --git a/test/lit.cfg b/test/lit.cfg index 31552882c55e..6ce6dc955847 100644 --- a/test/lit.cfg @@ -880,7 +589,7 @@ index 8d50403fc1da..2930427c7bde 100644 \ No newline at end of file +endif diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp -index e95522a019ad..3747d69db0ed 100644 +index c65953d1399e..90d54e064dd3 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp @@ -385,7 +385,12 @@ llvm::raw_fd_ostream *KleeHandler::openOutputFile(const std::string &filename) { @@ -897,54 +606,33 @@ index e95522a019ad..3747d69db0ed 100644 f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::sys::fs::F_None); #elif LLVM_VERSION_CODE >= LLVM_VERSION(3,4) f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::sys::fs::F_Binary); -@@ -645,8 +650,13 @@ static std::string strip(std::string &in) { - } - - static void parseArguments(int argc, char **argv) { -+ - cl::SetVersionPrinter(klee::printVersion); --#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) -+ -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ cl::ParseCommandLineOptions(argc, (char **)argv, " klee\n"); // removes -+ // warning -+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) - // This version always reads response files - cl::ParseCommandLineOptions(argc, argv, " klee\n"); - #else -@@ -1036,9 +1046,14 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) +@@ -1038,9 +1043,14 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) SmallString<128> uclibcBCA(libDir); llvm::sys::path::append(uclibcBCA, KLEE_UCLIBC_BCA_NAME); -- bool uclibcExists=false; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + Twine uclibcBCA_twine(uclibcBCA.c_str()); + if (!llvm::sys::fs::exists(uclibcBCA_twine)) +#else -+ bool uclibcExists = false; + bool uclibcExists=false; llvm::sys::fs::exists(uclibcBCA.c_str(), uclibcExists); if (!uclibcExists) +#endif klee_error("Cannot find klee-uclibc : %s", uclibcBCA.c_str()); Function *f; -@@ -1261,9 +1276,13 @@ int main(int argc, char **argv, char **envp) { - if (!Buffer) +@@ -1265,7 +1275,11 @@ int main(int argc, char **argv, char **envp) { klee_error("error loading program '%s': %s", InputFile.c_str(), Buffer.getError().message().c_str()); -- -- auto mainModuleOrError = getLazyBitcodeModule(Buffer->get(), getGlobalContext()); -- + +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+ auto mainModuleOrError = -+ getLazyBitcodeModule(std::move(Buffer.get()), getGlobalContext()); ++ auto mainModuleOrError = getLazyBitcodeModule(std::move(Buffer.get()), ctx); +#else -+ auto mainModuleOrError = -+ getLazyBitcodeModule(Buffer->get(), getGlobalContext()); + auto mainModuleOrError = getLazyBitcodeModule(Buffer->get(), ctx); +#endif + if (!mainModuleOrError) { klee_error("error loading program '%s': %s", InputFile.c_str(), - mainModuleOrError.getError().message().c_str()); -- -2.11.1 +2.12.0 diff --git a/0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch b/0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch new file mode 100644 index 0000000..c6c0e39 --- /dev/null +++ b/0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch @@ -0,0 +1,65 @@ +From: Jiri Slaby +Date: Wed, 15 Mar 2017 13:42:26 +0100 +Subject: runtime: POSIX, make it compile with glibc 2.25 +Patch-mainline: no + +With glibc 2.25, we see: +runtime/POSIX/stubs.c:243:14: error: conflicting types for 'gnu_dev_major' +unsigned int gnu_dev_major(unsigned long long int __dev) __attribute__((weak)); + ^ +/usr/include/sys/sysmacros.h:79:27: note: previous definition is here +__SYSMACROS_DEFINE_MAJOR (__SYSMACROS_IMPL_TEMPL) + ^ + +Glibc 2.25 switched from ULL to dev_t for gnu_dev_major, gnu_dev_minor, +and gnu_dev_makedev. Handle by using an appropriate type according to +the glibc version. + +Signed-off-by: Jiri Slaby +--- + runtime/POSIX/stubs.c | 22 ++++++++++++++-------- + 1 file changed, 14 insertions(+), 8 deletions(-) + +diff --git a/runtime/POSIX/stubs.c b/runtime/POSIX/stubs.c +index b4f31bf7d109..bb528ad4a263 100644 +--- a/runtime/POSIX/stubs.c ++++ b/runtime/POSIX/stubs.c +@@ -240,21 +240,27 @@ int strverscmp (__const char *__s1, __const char *__s2) { + return strcmp(__s1, __s2); /* XXX no doubt this is bad */ + } + +-unsigned int gnu_dev_major(unsigned long long int __dev) __attribute__((weak)); +-unsigned int gnu_dev_major(unsigned long long int __dev) { ++#if __GLIBC_PREREQ(2, 25) ++#define gnu_dev_type dev_t ++#else ++#define gnu_dev_type unsigned long long int ++#endif ++ ++unsigned int gnu_dev_major(gnu_dev_type __dev) __attribute__((weak)); ++unsigned int gnu_dev_major(gnu_dev_type __dev) { + return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); + } + +-unsigned int gnu_dev_minor(unsigned long long int __dev) __attribute__((weak)); +-unsigned int gnu_dev_minor(unsigned long long int __dev) { ++unsigned int gnu_dev_minor(gnu_dev_type __dev) __attribute__((weak)); ++unsigned int gnu_dev_minor(gnu_dev_type __dev) { + return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); + } + +-unsigned long long int gnu_dev_makedev(unsigned int __major, unsigned int __minor) __attribute__((weak)); +-unsigned long long int gnu_dev_makedev(unsigned int __major, unsigned int __minor) { ++gnu_dev_type gnu_dev_makedev(unsigned int __major, unsigned int __minor) __attribute__((weak)); ++gnu_dev_type gnu_dev_makedev(unsigned int __major, unsigned int __minor) { + return ((__minor & 0xff) | ((__major & 0xfff) << 8) +- | (((unsigned long long int) (__minor & ~0xff)) << 12) +- | (((unsigned long long int) (__major & ~0xfff)) << 32)); ++ | (((gnu_dev_type) (__minor & ~0xff)) << 12) ++ | (((gnu_dev_type) (__major & ~0xfff)) << 32)); + } + + char *canonicalize_file_name (const char *name) __attribute__((weak)); +-- +2.12.0 + diff --git a/0002-Make-KLEE-compile-against-LLVM-3.7.patch b/0002-Make-KLEE-compile-against-LLVM-3.7.patch index 2eea3be..9f88d36 100644 --- a/0002-Make-KLEE-compile-against-LLVM-3.7.patch +++ b/0002-Make-KLEE-compile-against-LLVM-3.7.patch @@ -1,37 +1,21 @@ From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= Date: Thu, 28 Apr 2016 18:27:24 +0200 -Subject: Make KLEE compile against LLVM 3.7 +Subject: llvm: make KLEE compile against LLVM 3.7 Patch-mainline: no -Signed-off-by: Jiri Slaby +Signed-off-by: Jiri Slaby --- - include/klee/CommandLine.h | 3 +- - include/klee/Internal/Support/FloatEvaluation.h | 7 +++++ - lib/Core/ExternalDispatcher.cpp | 15 ++++++---- - lib/Core/StatsTracker.cpp | 3 +- - lib/Module/InstructionInfoTable.cpp | 8 ++++- - lib/Module/IntrinsicCleaner.cpp | 14 +++++++++ - lib/Module/KModule.cpp | 13 ++++++++- - lib/Module/ModuleUtil.cpp | 24 +++++++++++++-- - lib/Module/Optimize.cpp | 39 +++++++++++++++++-------- - lib/Module/RaiseAsm.cpp | 6 ++-- - tools/klee/main.cpp | 9 +++++- - 11 files changed, 113 insertions(+), 28 deletions(-) + include/klee/Internal/Support/FloatEvaluation.h | 7 +++++++ + lib/Core/ExternalDispatcher.cpp | 4 ++++ + lib/Module/InstructionInfoTable.cpp | 8 +++++++- + lib/Module/IntrinsicCleaner.cpp | 14 ++++++++++++++ + lib/Module/KModule.cpp | 13 ++++++++++++- + lib/Module/ModuleUtil.cpp | 22 +++++++++++++++++++--- + lib/Module/Optimize.cpp | 21 +++++++++++++++++++-- + lib/Module/RaiseAsm.cpp | 5 ++++- + tools/klee/main.cpp | 6 +++++- + 9 files changed, 91 insertions(+), 9 deletions(-) -diff --git a/include/klee/CommandLine.h b/include/klee/CommandLine.h -index 95aa51e041e2..cc186db711fc 100644 ---- a/include/klee/CommandLine.h -+++ b/include/klee/CommandLine.h -@@ -70,8 +70,7 @@ extern llvm::cl::opt MetaSMTBackend; - - //A bit of ugliness so we can use cl::list<> like cl::bits<>, see queryLoggingOptions - template --static bool optionIsSet(llvm::cl::list list, T option) --{ -+static bool optionIsSet(llvm::cl::list &list, T option) { - return std::find(list.begin(), list.end(), option) != list.end(); - } - diff --git a/include/klee/Internal/Support/FloatEvaluation.h b/include/klee/Internal/Support/FloatEvaluation.h index 6d9092f2ea37..436e0dc8152f 100644 --- a/include/klee/Internal/Support/FloatEvaluation.h @@ -53,48 +37,23 @@ index 6d9092f2ea37..436e0dc8152f 100644 } } diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp -index 09dd715a53ae..fa29f6e3047c 100644 +index 9701d35add85..d49373f84e64 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp -@@ -253,11 +253,16 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in - // functions. +@@ -257,7 +257,11 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in LLVM_TYPE_Q Type *argTy = (i < FTy->getNumParams() ? FTy->getParamType(i) : (*ai)->getType()); -- Instruction *argI64p = -- GetElementPtrInst::Create(argI64s, -- ConstantInt::get(Type::getInt32Ty(getGlobalContext()), -- idx), -- "", dBB); -+ Instruction *argI64p = + Instruction *argI64p = +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ GetElementPtrInst::Create( -+ nullptr, argI64s, ++ GetElementPtrInst::Create(nullptr, argI64s, +#else -+ GetElementPtrInst::Create( -+ argI64s, + GetElementPtrInst::Create(argI64s, +#endif -+ ConstantInt::get(Type::getInt32Ty(getGlobalContext()), idx), "", -+ dBB); + ConstantInt::get(Type::getInt32Ty(ctx), idx), + "", dBB); - Instruction *argp = new BitCastInst(argI64p, PointerType::getUnqual(argTy), - "", dBB); -diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp -index ded85f950fe4..ae12708c130c 100644 ---- a/lib/Core/StatsTracker.cpp -+++ b/lib/Core/StatsTracker.cpp -@@ -167,8 +167,9 @@ static bool instructionIsCoverable(Instruction *i) { - } else { - Instruction *prev = --it; - if (isa(prev) || isa(prev)) { -+ CallSite cs(prev); - Function *target = -- getDirectCallTarget(prev, /*moduleIsFullyLinked=*/true); -+ getDirectCallTarget(cs, /*moduleIsFullyLinked=*/true); - if (target && target->doesNotReturn()) - return false; - } diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp -index 7e9a9e268b40..53c64878391f 100644 +index adf054423f13..625c4a297ead 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -87,7 +87,7 @@ static void buildInstructionToLineMap(Module *m, @@ -123,28 +82,28 @@ index 7e9a9e268b40..53c64878391f 100644 } diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp -index 54582e6954cf..66e9392a618d 100644 +index 3f7644af3d37..9af6f9f40f21 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp -@@ -109,11 +109,25 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { +@@ -110,11 +110,25 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { Value *pSrc = CastInst::CreatePointerCast(src, i64p, "vacopy.cast.src", ii); Value *val = new LoadInst(pSrc, std::string(), ii); new StoreInst(val, pDst, ii); - Value *off = ConstantInt::get(Type::getInt64Ty(getGlobalContext()), 1); + Value *off = ConstantInt::get(Type::getInt64Ty(ctx), 1); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ pDst = -+ GetElementPtrInst::Create(nullptr, pDst, off, std::string(), ii); -+ pSrc = -+ GetElementPtrInst::Create(nullptr, pSrc, off, std::string(), ii); ++ pDst = GetElementPtrInst::Create(nullptr, pDst, off, std::string(), ++ ii); ++ pSrc = GetElementPtrInst::Create(nullptr, pSrc, off, std::string(), ++ ii); +#else pDst = GetElementPtrInst::Create(pDst, off, std::string(), ii); pSrc = GetElementPtrInst::Create(pSrc, off, std::string(), ii); +#endif val = new LoadInst(pSrc, std::string(), ii); new StoreInst(val, pDst, ii); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ pDst = -+ GetElementPtrInst::Create(nullptr, pDst, off, std::string(), ii); -+ pSrc = -+ GetElementPtrInst::Create(nullptr, pSrc, off, std::string(), ii); ++ pDst = GetElementPtrInst::Create(nullptr, pDst, off, std::string(), ++ ii); ++ pSrc = GetElementPtrInst::Create(nullptr, pSrc, off, std::string(), ++ ii); +#else pDst = GetElementPtrInst::Create(pDst, off, std::string(), ii); pSrc = GetElementPtrInst::Create(pSrc, off, std::string(), ii); @@ -153,7 +112,7 @@ index 54582e6954cf..66e9392a618d 100644 } ii->removeFromParent(); diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp -index 598c439f9da0..cc328b1bb974 100644 +index 45dc34bfec46..4fac18739aba 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -46,8 +46,11 @@ @@ -169,7 +128,7 @@ index 598c439f9da0..cc328b1bb974 100644 #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_os_ostream.h" -@@ -301,7 +304,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, +@@ -305,7 +308,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, // invariant transformations that we will end up doing later so that // optimize is seeing what is as close as possible to the final // module. @@ -181,7 +140,7 @@ index 598c439f9da0..cc328b1bb974 100644 pm.add(new RaiseAsmPass()); if (opts.CheckDivZero) pm.add(new DivCheckPass()); if (opts.CheckOvershift) pm.add(new OvershiftCheckPass()); -@@ -369,7 +376,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, +@@ -373,7 +380,11 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, // linked in something with intrinsics but any external calls are // going to be unresolved. We really need to handle the intrinsics // directly I think? @@ -194,65 +153,60 @@ index 598c439f9da0..cc328b1bb974 100644 switch(SwitchType) { case eSwitchTypeInternal: break; diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp -index 537c9aba4b6f..2aa9b8e6b0ab 100644 +index c7f1c6d9d4a7..de0130a2632c 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp -@@ -272,14 +272,22 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - // FIXME: Maybe load bitcode file lazily? Then if we need to link, materialise - // the module +@@ -274,13 +274,21 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er + Module *Result = 0; + // FIXME: Maybe load bitcode file lazily? Then if we need to link, materialise the module #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +- ErrorOr resultErr = parseBitcodeFile(buff.get(), +- composite->getContext()); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ ErrorOr > Result_error = ++ ErrorOr > resultErr = +#else - ErrorOr Result_error = ++ ErrorOr resultErr = +#endif - parseBitcodeFile(buff.get(), getGlobalContext()); - ec = Result_error.getError(); ++ parseBitcodeFile(buff.get(), composite->getContext()); + ec = resultErr.getError(); if (ec) errorMessage = ec.message(); else -- Result = Result_error.get(); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ Result = Result_error->release(); - #else -+ Result = Result_error.get(); ++ Result = resultErr->release(); ++#else + Result = resultErr.get(); +#endif -+#else // LLVM 3.3, 3.4 - Result = - ParseBitcodeFile(buff.get(), getGlobalContext(), &errorMessage); - #endif -@@ -416,8 +424,15 @@ Module *klee::linkWithLibrary(Module *module, - + #else + Result = ParseBitcodeFile(buff.get(), composite->getContext(), + &errorMessage); +@@ -439,7 +447,12 @@ Module *klee::linkWithLibrary(Module *module, if (magic == sys::fs::file_magic::bitcode) { - + Module *Result = 0; + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +- ErrorOr ResultErr = parseBitcodeFile(Buffer, Context); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) -+ ErrorOr > Result = parseBitcodeFile(buff, Context); -+ -+ if ((ec = Buffer.getError()) || Linker::LinkModules(module, Result->get())) -+ klee_error("Link with library %s failed: %s", libraryName.c_str(), -+ ec.message().c_str()); -+#else // LLVM 3.5, 3.6 - ErrorOr Result = parseBitcodeFile(buff, Context); --#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+#if LLVM_VERSION_CODE == LLVM_VERSION(3, 6) - if ((ec = Buffer.getError()) || Linker::LinkModules(module, Result.get())) - #else // LLVM 3.5 - if ((ec = Buffer.getError()) || -@@ -426,8 +441,11 @@ Module *klee::linkWithLibrary(Module *module, - #endif - klee_error("Link with library %s failed: %s", libraryName.c_str(), - ec.message().c_str()); -- ++ ErrorOr > ResultErr = ++#else ++ ErrorOr ResultErr = ++#endif ++ parseBitcodeFile(Buffer, Context); + if ((ec = ResultErr.getError())) { + ErrorMessage = ec.message(); + #else +@@ -464,7 +477,10 @@ Module *klee::linkWithLibrary(Module *module, + ErrorMessage.c_str()); + } + +// unique_ptr owns the Module, we don't have to delete it +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 7) - delete Result.get(); -+#endif + delete Result; +#endif } else if (magic == sys::fs::file_magic::archive) { #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp -index 8cd592069523..3eca0db6c174 100644 +index c0f3f34ca8e8..68acd2b17dda 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -16,7 +16,11 @@ @@ -292,7 +246,7 @@ index 8cd592069523..3eca0db6c174 100644 PM.add(createVerifierPass()); // Verify that input is correct #if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) -@@ -166,27 +177,31 @@ static void AddStandardCompilePasses(PassManager &PM) { +@@ -166,14 +177,20 @@ static void AddStandardCompilePasses(PassManager &PM) { void Optimize(Module *M, const std::string &EntryPoint) { // Instantiate the pass manager to organize the passes. @@ -306,44 +260,22 @@ index 8cd592069523..3eca0db6c174 100644 if (VerifyEach) Passes.add(createVerifierPass()); + // Add an appropriate DataLayout instance for this module... -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) -+#if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) -+ // Add an appropriate TargetData instance for this module... -+ addPass(Passes, new TargetData(M)); -+#elif LLVM_VERSION_CODE <= LLVM_VERSION(3, 4) - // Add an appropriate DataLayout instance for this module... -- DataLayoutPass *dlpass = new DataLayoutPass(); -- dlpass->doInitialization(*M); -- addPass(Passes, dlpass); --#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ addPass(Passes, new DataLayout(M)); -+#elif LLVM_VERSION_CODE == LLVM_VERSION(3, 5) - // Add an appropriate DataLayout instance for this module... - addPass(Passes, new DataLayoutPass(M)); --#elif LLVM_VERSION_CODE > LLVM_VERSION(3, 1) -+#elif LLVM_VERSION_CODE == LLVM_VERSION(3, 6) - // Add an appropriate DataLayout instance for this module... -- addPass(Passes, new DataLayout(M)); --#else -- // Add an appropriate TargetData instance for this module... -- addPass(Passes, new TargetData(M)); --#endif -+ DataLayoutPass *dlpass = new DataLayoutPass(); -+ dlpass->doInitialization(*M); -+ addPass(Passes, dlpass); -+#endif // LLVM 3.7+ doesn't have DataLayoutPass anymore. - - // DWD - Run the opt standard pass list as well. - AddStandardCompilePasses(Passes); ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) ++ // LLVM 3.7+ doesn't have DataLayoutPass anymore. ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + DataLayoutPass *dlpass = new DataLayoutPass(); + dlpass->doInitialization(*M); + addPass(Passes, dlpass); diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp -index bde9fba93c3a..a2972ce7ee9b 100644 +index 5fc54ef17743..29576ad10e9e 100644 --- a/lib/Module/RaiseAsm.cpp +++ b/lib/Module/RaiseAsm.cpp -@@ -103,8 +103,10 @@ bool RaiseAsmPass::runOnModule(Module &M) { +@@ -103,7 +103,10 @@ bool RaiseAsmPass::runOnModule(Module &M) { klee_warning("Warning: unable to select native target: %s", Err.c_str()); TLI = 0; } else { -- -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) + TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions()); @@ -353,21 +285,18 @@ index bde9fba93c3a..a2972ce7ee9b 100644 TLI = TM->getSubtargetImpl()->getTargetLowering(); #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp -index 3747d69db0ed..9265abe04820 100644 +index 90d54e064dd3..20b1e33a6617 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp -@@ -59,6 +59,10 @@ - #include "llvm/Support/system_error.h" - #endif - -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) +@@ -46,6 +46,7 @@ + #include "llvm/Support/CommandLine.h" + #include "llvm/Support/ManagedStatic.h" + #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" -+#endif -+ - #include - #include - #include -@@ -1292,8 +1296,11 @@ int main(int argc, char **argv, char **envp) { + #include "llvm/Support/raw_ostream.h" + + #if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) +@@ -1290,8 +1291,11 @@ int main(int argc, char **argv, char **envp) { // from the std::unique_ptr Buffer->release(); } @@ -381,5 +310,5 @@ index 3747d69db0ed..9265abe04820 100644 klee_error("error loading program '%s': %s", InputFile.c_str(), ec.message().c_str()); -- -2.11.1 +2.12.0 diff --git a/0003-Make-KLEE-compile-against-LLVM-3.8.patch b/0003-Make-KLEE-compile-against-LLVM-3.8.patch index 6c6ef65..215f0d4 100644 --- a/0003-Make-KLEE-compile-against-LLVM-3.8.patch +++ b/0003-Make-KLEE-compile-against-LLVM-3.8.patch @@ -1,108 +1,24 @@ From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= Date: Wed, 4 May 2016 15:21:45 +0200 -Subject: Make KLEE compile against LLVM 3.8 +Subject: llvm: make KLEE compile against LLVM 3.8 Patch-mainline: no -Mainly explicit casts from pointers to iterators and back. - -Signed-off-by: Jiri Slaby +Signed-off-by: Jiri Slaby --- - lib/Core/Executor.cpp | 47 ++++++++++++++++++++------ - lib/Core/StatsTracker.cpp | 66 +++++++++++++++++++++++++++--------- - lib/Module/Checks.cpp | 34 +++++++++++-------- - lib/Module/InstructionInfoTable.cpp | 15 +++++++-- - lib/Module/IntrinsicCleaner.cpp | 12 +++++-- - lib/Module/KModule.cpp | 67 +++++++++++++++++++++++++++---------- - lib/Module/LowerSwitch.cpp | 15 ++++++++- - lib/Module/ModuleUtil.cpp | 65 ++++++++++++++++++++++++----------- - lib/Module/Optimize.cpp | 13 ++++++- - lib/Module/RaiseAsm.cpp | 4 +++ - tools/klee/main.cpp | 32 +++++++++++++++--- - 11 files changed, 282 insertions(+), 88 deletions(-) + lib/Core/Executor.cpp | 5 +++++ + lib/Core/StatsTracker.cpp | 4 ++++ + lib/Module/IntrinsicCleaner.cpp | 10 +++++++++- + lib/Module/LowerSwitch.cpp | 8 ++++++++ + lib/Module/ModuleUtil.cpp | 38 ++++++++++++++++++++++++++++++-------- + lib/Module/Optimize.cpp | 13 ++++++++++++- + tools/klee/main.cpp | 11 ++++++++++- + 7 files changed, 78 insertions(+), 11 deletions(-) diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp -index 80b8289d1486..b3ec990dc9ae 100644 +index 4148ca22caf3..794346e0950d 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp -@@ -554,7 +554,11 @@ void Executor::initializeGlobals(ExecutionState &state) { - // ensures that we won't conflict. we don't need to allocate a memory object - // since reading/writing via a function pointer is unsupported anyway. - for (Module::iterator i = m->begin(), ie = m->end(); i != ie; ++i) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Function *f = static_cast(i); -+#else - Function *f = i; -+#endif - ref addr(0); - - // If the symbol has external weak linkage then it is implicitly -@@ -608,6 +612,11 @@ void Executor::initializeGlobals(ExecutionState &state) { - for (Module::const_global_iterator i = m->global_begin(), - e = m->global_end(); - i != e; ++i) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ const GlobalVariable *v = static_cast(i); -+#else -+ const GlobalVariable *v = i; -+#endif - if (i->isDeclaration()) { - // FIXME: We have no general way of handling unknown external - // symbols. If we really cared about making external stuff work -@@ -638,11 +647,10 @@ void Executor::initializeGlobals(ExecutionState &state) { - klee_warning("Unable to find size for global variable: %.*s (use will result in out of bounds access)", - (int)i->getName().size(), i->getName().data()); - } -- -- MemoryObject *mo = memory->allocate(size, false, true, i); -+ MemoryObject *mo = memory->allocate(size, false, true, v); - ObjectState *os = bindObjectInState(state, mo, false); -- globalObjects.insert(std::make_pair(i, mo)); -- globalAddresses.insert(std::make_pair(i, mo->getBaseExpr())); -+ globalObjects.insert(std::make_pair(v, mo)); -+ globalAddresses.insert(std::make_pair(v, mo->getBaseExpr())); - - // Program already running = object already initialized. Read - // concrete value and write it to our copy. -@@ -667,8 +675,8 @@ void Executor::initializeGlobals(ExecutionState &state) { - if (!mo) - llvm::report_fatal_error("out of memory"); - ObjectState *os = bindObjectInState(state, mo, false); -- globalObjects.insert(std::make_pair(i, mo)); -- globalAddresses.insert(std::make_pair(i, mo->getBaseExpr())); -+ globalObjects.insert(std::make_pair(v, mo)); -+ globalAddresses.insert(std::make_pair(v, mo->getBaseExpr())); - - if (!i->hasInitializer()) - os->initializeToRandom(); -@@ -679,8 +687,13 @@ void Executor::initializeGlobals(ExecutionState &state) { - for (Module::alias_iterator i = m->alias_begin(), ie = m->alias_end(); - i != ie; ++i) { - // Map the alias to its aliasee's address. This works because we have -- // addresses for everything, even undefined functions. -+ // addresses for everything, even undefined functions. -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ globalAddresses.insert(std::make_pair(static_cast(i), -+ evalConstant(i->getAliasee()))); -+#else - globalAddresses.insert(std::make_pair(i, evalConstant(i->getAliasee()))); -+#endif - } - - // once all objects are allocated, do the actual initialization -@@ -688,7 +701,12 @@ void Executor::initializeGlobals(ExecutionState &state) { - e = m->global_end(); - i != e; ++i) { - if (i->hasInitializer()) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ MemoryObject *mo = -+ globalObjects.find(static_cast(i))->second; -+#else - MemoryObject *mo = globalObjects.find(i)->second; -+#endif - const ObjectState *os = state.addressSpace.findObject(mo); - assert(os); - ObjectState *wos = state.addressSpace.getWriteable(mo, os); -@@ -2303,8 +2321,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { +@@ -2301,8 +2301,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) { return terminateStateOnExecError(state, "Unsupported FRem operation"); #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue()); @@ -116,258 +32,27 @@ index 80b8289d1486..b3ec990dc9ae 100644 #else llvm::APFloat Res(left->getAPValue()); Res.mod(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven); -@@ -3563,9 +3586,13 @@ void Executor::runFunctionAsMain(Function *f, - arguments.push_back(ConstantExpr::alloc(argc, Expr::Int32)); - - if (++ai!=ae) { -- argvMO = memory->allocate((argc+1+envc+1+1) * NumPtrBytes, false, true, -- f->begin()->begin()); -- -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *first = static_cast(f->begin()->begin()); -+#else -+ Instruction *first = f->begin()->begin(); -+#endif -+ argvMO = memory->allocate((argc + 1 + envc + 1 + 1) * NumPtrBytes, false, -+ true, first); - if (!argvMO) - klee_error("Could not allocate memory for function arguments"); - diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp -index ae12708c130c..fff266aca19b 100644 +index b93796ecdff7..fc4cb786e902 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp -@@ -162,10 +162,14 @@ static bool instructionIsCoverable(Instruction *i) { - if (i->getOpcode() == Instruction::Unreachable) { - BasicBlock *bb = i->getParent(); - BasicBlock::iterator it(i); -- if (it==bb->begin()) { -+ if (it == bb->begin()) { - return true; - } else { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *prev = static_cast(--it); -+#else - Instruction *prev = --it; -+#endif - if (isa(prev) || isa(prev)) { - CallSite cs(prev); - Function *target = -@@ -543,7 +547,12 @@ void StatsTracker::writeIStats() { - // Always try to write the filename before the function name, as otherwise - // KCachegrind can create two entries for the function, one with an - // unnamed file and one without. -- const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fnIt); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Function *fn = static_cast(fnIt); -+#else -+ Function *fn = fnIt; -+#endif -+ const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fn); - if (ii.file != sourceFile) { - of << "fl=" << ii.file << "\n"; - sourceFile = ii.file; -@@ -639,9 +648,17 @@ static std::vector getSuccs(Instruction *i) { - - if (i==bb->getTerminator()) { +@@ -641,7 +641,11 @@ static std::vector getSuccs(Instruction *i) { for (succ_iterator it = succ_begin(bb), ie = succ_end(bb); it != ie; ++it) -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ res.push_back(static_cast(it->begin())); -+#else - res.push_back(it->begin()); -+#endif + res.push_back(static_cast(it->begin())); } else { +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) + res.push_back(static_cast(++(i->getIterator()))); +#else - res.push_back(++BasicBlock::iterator(i)); + res.push_back(static_cast(++BasicBlock::iterator(i))); +#endif } return res; -@@ -688,20 +705,24 @@ void StatsTracker::computeReachableUncovered() { - bbIt != bb_ie; ++bbIt) { - for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end(); - it != ie; ++it) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *inst = static_cast(it); -+#else -+ Instruction *inst = it; -+#endif - if (isa(it) || isa(it)) { -- CallSite cs(it); -+ CallSite cs(inst); - if (isa(cs.getCalledValue())) { - // We can never call through here so assume no targets - // (which should be correct anyhow). -- callTargets.insert(std::make_pair(it, -+ callTargets.insert(std::make_pair(inst, - std::vector())); - } else if (Function *target = getDirectCallTarget( - cs, /*moduleIsFullyLinked=*/true)) { -- callTargets[it].push_back(target); -+ callTargets[inst].push_back(target); - } else { -- callTargets[it] = -- std::vector(km->escapingFunctions.begin(), -- km->escapingFunctions.end()); -+ callTargets[inst] = std::vector( -+ km->escapingFunctions.begin(), km->escapingFunctions.end()); - } - } - } -@@ -720,14 +741,19 @@ void StatsTracker::computeReachableUncovered() { - std::vector instructions; - for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); - fnIt != fn_ie; ++fnIt) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Function *fn = static_cast(fnIt); -+#else -+ Function *fn = fnIt; -+#endif - if (fnIt->isDeclaration()) { - if (fnIt->doesNotReturn()) { -- functionShortestPath[fnIt] = 0; -+ functionShortestPath[fn] = 0; - } else { -- functionShortestPath[fnIt] = 1; // whatever -+ functionShortestPath[fn] = 1; // whatever - } - } else { -- functionShortestPath[fnIt] = 0; -+ functionShortestPath[fn] = 0; - } - - // Not sure if I should bother to preorder here. XXX I should. -@@ -735,8 +761,13 @@ void StatsTracker::computeReachableUncovered() { - bbIt != bb_ie; ++bbIt) { - for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end(); - it != ie; ++it) { -- instructions.push_back(it); -- unsigned id = infos.getInfo(it).id; -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *inst = static_cast(it); -+#else -+ Instruction *inst = it; -+#endif -+ instructions.push_back(inst); -+ unsigned id = infos.getInfo(inst).id; - sm.setIndexedValue(stats::minDistToReturn, - id, - isa(it) -@@ -817,8 +848,13 @@ void StatsTracker::computeReachableUncovered() { - bbIt != bb_ie; ++bbIt) { - for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end(); - it != ie; ++it) { -- unsigned id = infos.getInfo(it).id; -- instructions.push_back(&*it); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *inst = static_cast(it); -+#else -+ Instruction *inst = it; -+#endif -+ unsigned id = infos.getInfo(inst).id; -+ instructions.push_back(inst); - sm.setIndexedValue(stats::minDistToUncovered, - id, - sm.getIndexedValue(stats::uncoveredInstructions, id)); -diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp -index 7d9b72841753..2a1681f3a7c5 100644 ---- a/lib/Module/Checks.cpp -+++ b/lib/Module/Checks.cpp -@@ -64,14 +64,17 @@ bool DivCheckPass::runOnModule(Module &M) { - Instruction::BinaryOps opcode = binOp->getOpcode(); - if (opcode == Instruction::SDiv || opcode == Instruction::UDiv || - opcode == Instruction::SRem || opcode == Instruction::URem) { -- -- CastInst *denominator = -- CastInst::CreateIntegerCast(i->getOperand(1), -- Type::getInt64Ty(getGlobalContext()), -- false, /* sign doesn't matter */ -- "int_cast_to_i64", -- i); -- -+ -+ CastInst *denominator = CastInst::CreateIntegerCast( -+ i->getOperand(1), Type::getInt64Ty(getGlobalContext()), -+ false, /* sign doesn't matter */ -+ "int_cast_to_i64", -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ static_cast(i)); -+#else -+ i); -+#endif -+ - // Lazily bind the function to avoid always importing it. - if (!divZeroCheckFunction) { - Constant *fc = M.getOrInsertFunction("klee_div_zero_check", -@@ -121,12 +124,15 @@ bool OvershiftCheckPass::runOnModule(Module &M) { - ConstantInt *bitWidthC = ConstantInt::get(Type::getInt64Ty(getGlobalContext()),bitWidth,false); - args.push_back(bitWidthC); - -- CastInst *shift = -- CastInst::CreateIntegerCast(i->getOperand(1), -- Type::getInt64Ty(getGlobalContext()), -- false, /* sign doesn't matter */ -- "int_cast_to_i64", -- i); -+ CastInst *shift = CastInst::CreateIntegerCast( -+ i->getOperand(1), Type::getInt64Ty(getGlobalContext()), -+ false, /* sign doesn't matter */ -+ "int_cast_to_i64", -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ static_cast(i)); -+#else -+ i); -+#endif - args.push_back(shift); - - -diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp -index 53c64878391f..52238786f49e 100644 ---- a/lib/Module/InstructionInfoTable.cpp -+++ b/lib/Module/InstructionInfoTable.cpp -@@ -134,7 +134,12 @@ InstructionInfoTable::InstructionInfoTable(Module *m) - // if any. - const std::string *initialFile = &dummyString; - unsigned initialLine = 0; -- for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Function *fn = static_cast(fnIt); -+#else -+ Function *fn = fnIt; -+#endif -+ for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie; - ++it) { - if (getInstructionDebugInfo(&*it, initialFile, initialLine)) - break; -@@ -142,8 +147,8 @@ InstructionInfoTable::InstructionInfoTable(Module *m) - - const std::string *file = initialFile; - unsigned line = initialLine; -- for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; -- ++it) { -+ for (inst_iterator it = inst_begin(fn), ie = inst_end(fn); it != ie; -+ ++it) { - Instruction *instr = &*it; - unsigned assemblyLine = lineTable[instr]; - -@@ -199,6 +204,10 @@ InstructionInfoTable::getFunctionInfo(const Function *f) const { - // and construct a test case for it if it does, though. - return dummyInfo; - } else { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ return getInfo(static_cast(f->begin()->begin())); -+#else - return getInfo(f->begin()->begin()); -+#endif - } - } diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp -index 66e9392a618d..8ec47195dd3b 100644 +index 9af6f9f40f21..1e43463e6a5c 100644 --- a/lib/Module/IntrinsicCleaner.cpp +++ b/lib/Module/IntrinsicCleaner.cpp -@@ -79,8 +79,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { +@@ -80,6 +80,10 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { for (BasicBlock::iterator i = b.begin(), ie = b.end(); (i != ie) && (block_split == false);) { IntrinsicInst *ii = dyn_cast(&*i); @@ -376,12 +61,9 @@ index 66e9392a618d..8ec47195dd3b 100644 + BasicBlock::iterator i_ = i; +#endif // increment now since LowerIntrinsic deletion makes iterator invalid. -- ++i; -+ ++i; + ++i; if(ii) { - switch (ii->getIntrinsicID()) { - case Intrinsic::vastart: -@@ -141,8 +145,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { +@@ -142,8 +146,12 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) { case Intrinsic::uadd_with_overflow: case Intrinsic::usub_with_overflow: case Intrinsic::umul_with_overflow: { @@ -395,171 +77,14 @@ index 66e9392a618d..8ec47195dd3b 100644 Value *op1 = ii->getArgOperand(0); Value *op2 = ii->getArgOperand(1); -diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp -index cc328b1bb974..75e92804c91d 100644 ---- a/lib/Module/KModule.cpp -+++ b/lib/Module/KModule.cpp -@@ -120,12 +120,15 @@ KModule::~KModule() { - delete[] constantTable; - delete infos; - -- for (std::vector::iterator it = functions.begin(), -- ie = functions.end(); it != ie; ++it) -+ for (std::vector::iterator it = functions.begin(), -+ ie = functions.end(); -+ it != ie; ++it) - delete *it; - -- for (std::map::iterator it=constantMap.begin(), -- itE=constantMap.end(); it!=itE;++it) -+ for (std::map::iterator -+ it = constantMap.begin(), -+ itE = constantMap.end(); -+ it != itE; ++it) - delete it->second; - - delete targetData; -@@ -197,8 +200,14 @@ static void injectStaticConstructorsAndDestructors(Module *m) { - klee_error("Could not find main() function."); - - if (ctors) -- CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"), -- "", mainFn->begin()->begin()); -+ CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"), -+ "", -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ static_cast(mainFn->begin()->begin())); -+#else -+ mainFn->begin()->begin()); -+#endif -+ - if (dtors) { - Function *dtorStub = getStubFunctionForCtorList(m, dtors, "klee.dtor_stub"); - for (Function::iterator it = mainFn->begin(), ie = mainFn->end(); -@@ -278,22 +287,27 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, - #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0) - result = PHINode::Create(f->getReturnType(), 0, "retval", exit); - #else -- result = PHINode::Create(f->getReturnType(), "retval", exit); -+ result = PHINode::Create(f->getReturnType(), "retval", exit); - #endif - CallInst::Create(mergeFn, "", exit); - ReturnInst::Create(getGlobalContext(), result, exit); - - llvm::errs() << "KLEE: adding klee_merge at exit of: " << name << "\n"; -- for (llvm::Function::iterator bbit = f->begin(), bbie = f->end(); -+ for (llvm::Function::iterator bbit = f->begin(), bbie = f->end(); - bbit != bbie; ++bbit) { -- if (&*bbit != exit) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ BasicBlock *bb = static_cast(bbit); -+#else -+ BasicBlock *bb = bbit; -+#endif -+ if (bb != exit) { - Instruction *i = bbit->getTerminator(); - if (i->getOpcode()==Instruction::Ret) { - if (result) { -- result->addIncoming(i->getOperand(0), bbit); -+ result->addIncoming(i->getOperand(0), bb); - } - i->eraseFromParent(); -- BranchInst::Create(exit, bbit); -+ BranchInst::Create(exit, bb); - } - } - } -@@ -458,15 +472,20 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts, - if (it->isDeclaration()) - continue; - -- KFunction *kf = new KFunction(it, this); -- -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Function *fn = static_cast(it); -+#else -+ Function *fn = it; -+#endif -+ KFunction *kf = new KFunction(fn, this); -+ - for (unsigned i=0; inumInstructions; ++i) { - KInstruction *ki = kf->instructions[i]; - ki->info = &infos->getInfo(ki->inst); - } - - functions.push_back(kf); -- functionMap.insert(std::make_pair(it, kf)); -+ functionMap.insert(std::make_pair(fn, kf)); - } - - /* Compute various interesting properties */ -@@ -547,7 +566,11 @@ KFunction::KFunction(llvm::Function *_function, - trackCoverage(true) { - for (llvm::Function::iterator bbit = function->begin(), - bbie = function->end(); bbit != bbie; ++bbit) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ BasicBlock *bb = static_cast(bbit); -+#else - BasicBlock *bb = bbit; -+#endif - basicBlockEntry[bb] = numInstructions; - numInstructions += bb->size(); - } -@@ -562,7 +585,11 @@ KFunction::KFunction(llvm::Function *_function, - bbie = function->end(); bbit != bbie; ++bbit) { - for (llvm::BasicBlock::iterator it = bbit->begin(), ie = bbit->end(); - it != ie; ++it) -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ registerMap[static_cast(it)] = rnum++; -+#else - registerMap[it] = rnum++; -+#endif - } - numRegisters = rnum; - -@@ -581,12 +608,16 @@ KFunction::KFunction(llvm::Function *_function, - default: - ki = new KInstruction(); break; - } -- -- ki->inst = it; -- ki->dest = registerMap[it]; -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ Instruction *inst = static_cast(it); -+#else -+ Instruction *inst = it; -+#endif -+ ki->inst = inst; -+ ki->dest = registerMap[inst]; - - if (isa(it) || isa(it)) { -- CallSite cs(it); -+ CallSite cs(inst); - unsigned numArgs = cs.arg_size(); - ki->operands = new int[numArgs+1]; - ki->operands[0] = getOperandNum(cs.getCalledValue(), registerMap, km, diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp -index a98b84add5d7..7cdd5fba2bf8 100644 +index 5cc6b991c6d1..4a5658912a0c 100644 --- a/lib/Module/LowerSwitch.cpp +++ b/lib/Module/LowerSwitch.cpp -@@ -44,7 +44,12 @@ bool LowerSwitchPass::runOnFunction(Function &F) { - bool changed = false; - - for (Function::iterator I = F.begin(), E = F.end(); I != E; ) { -- BasicBlock *cur = I++; // Advance over block so we don't traverse new blocks -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ BasicBlock *cur = static_cast(I); -+#else -+ BasicBlock *cur = I; -+#endif -+ I++; // Advance over block so we don't traverse new blocks - - if (SwitchInst *SI = dyn_cast(cur->getTerminator())) { - changed = true; -@@ -67,7 +72,11 @@ void LowerSwitchPass::switchConvert(CaseItr begin, CaseItr end, +@@ -68,7 +68,11 @@ void LowerSwitchPass::switchConvert(CaseItr begin, CaseItr end, // iterate through all the cases, creating a new BasicBlock for each for (CaseItr it = begin; it < end; ++it) { - BasicBlock *newBlock = BasicBlock::Create(getGlobalContext(), "NodeBlock"); + BasicBlock *newBlock = BasicBlock::Create(F->getContext(), "NodeBlock"); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) + Function::iterator FI = origBlock->getIterator(); +#else @@ -568,9 +93,9 @@ index a98b84add5d7..7cdd5fba2bf8 100644 F->getBasicBlockList().insert(++FI, newBlock); ICmpInst *cmpInst = -@@ -104,7 +113,11 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) { +@@ -105,7 +109,11 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) { // if-then statements go to this and the PHI nodes are happy. - BasicBlock* newDefault = BasicBlock::Create(getGlobalContext(), "newDefault"); + BasicBlock* newDefault = BasicBlock::Create(F->getContext(), "newDefault"); +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) + F->getBasicBlockList().insert(defaultBlock->getIterator(), newDefault); @@ -581,113 +106,62 @@ index a98b84add5d7..7cdd5fba2bf8 100644 // If there is an entry in any PHI nodes for the default edge, make sure diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp -index 2aa9b8e6b0ab..1e62498dc845 100644 +index de0130a2632c..6b50b037bc65 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp -@@ -217,42 +217,59 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - AE = archive->child_end(); - AI != AE; ++AI) - #else -- - for (object::Archive::child_iterator AI = archive->begin_children(), - AE = archive->end_children(); - AI != AE; ++AI) - #endif - { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ std::error_code ec; -+#else -+ error_code ec; -+#endif +@@ -223,8 +223,19 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er + StringRef memberName; -+ + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +- ErrorOr memberNameErr = AI->getName(); +- std::error_code ec = memberNameErr.getError(); ++ std::error_code ec; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ ErrorOr child = *AI; -+ ec = child.getError(); ++ ErrorOr childErr = *AI; ++ ec = childErr.getError(); + if (ec) { + errorMessage = ec.message(); + return false; + } -+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -+ object::Archive::child_iterator child = AI; ++#else ++ object::Archive::child_iterator childErr = AI; +#endif -+ - #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) -- ErrorOr errorOr_memberName = AI->getName(); -- std::error_code ec = errorOr_memberName.getError(); -+ ErrorOr errorOr_memberName = child->getName(); -+ ec = errorOr_memberName.getError(); - if (!ec) - memberName = errorOr_memberName.get(); --#else -- error_code ec = AI->getName(memberName); -+#else // LLVM 3.3, 3.4 -+ ec = AI->getName(memberName); - #endif ++ ErrorOr memberNameErr = childErr->getName(); ++ ec = memberNameErr.getError(); if (!ec) { - KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading archive member " << memberName << "\n"); - } else { -- errorMessage="Archive member does not have a name!\n"; -+ errorMessage = "Archive member does not have a name!"; - return false; + memberName = memberNameErr.get(); + #else +@@ -242,7 +253,8 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er } + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) - ErrorOr > child = AI->getAsBinary(); -- ec = child.getError(); -+ ErrorOr > childBin = -+ child->getAsBinary(); -+ ec = childBin.getError(); ++ ErrorOr > child = ++ childErr->getAsBinary(); + ec = child.getError(); #else -- OwningPtr child; -- ec = AI->getAsBinary(child); -+ OwningPtr childBin; -+ ec = AI->getAsBinary(childBin); - #endif + OwningPtr child; +@@ -251,7 +263,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er if (ec) { // If we can't open as a binary object file its hopefully a bitcode file #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) - ErrorOr buff = AI->getMemoryBufferRef(); -+ ErrorOr buff = child->getMemoryBufferRef(); ++ ErrorOr buff = childErr->getMemoryBufferRef(); ec = buff.getError(); - #elif LLVM_VERSION_CODE == LLVM_VERSION(3, 5) - ErrorOr > errorOr_buff = -- AI->getMemoryBuffer(); -+ child->getMemoryBuffer(); - std::unique_ptr buff = nullptr; - ec = errorOr_buff.getError(); - if (!ec) -@@ -292,7 +309,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - ParseBitcodeFile(buff.get(), getGlobalContext(), &errorMessage); - #endif - if (!Result) { -- SS << "Loading module failed : " << errorMessage << "\n"; -+ SS << "Loading module failed : " << errorMessage; - SS.flush(); - return false; - } -@@ -301,8 +318,8 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - errorMessage = "Buffer was NULL!"; - return false; - } -- } else if (child.get()->isObject()) { -- SS << "Object file " << child.get()->getFileName().data() -+ } else if (childBin.get()->isObject()) { -+ SS << "Object file " << childBin.get()->getFileName().data() - << " in archive is not supported"; - SS.flush(); - return false; -@@ -346,7 +363,9 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er - + #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + ErrorOr > buffErr = AI->getMemoryBuffer(); +@@ -359,7 +371,9 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Found " << GV->getName() << " in " << M->getModuleIdentifier() << "\n"); + -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) + if (Linker::linkModules(*composite, std::unique_ptr(M))) +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) if (Linker::LinkModules(composite, M)) #else - if (Linker::LinkModules(composite, M, Linker::DestroySource, -@@ -364,8 +383,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er + if (Linker::LinkModules(composite, M, Linker::DestroySource, &errorMessage)) +@@ -376,8 +390,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er // Link succeed, now clean up modulesLoadedOnPass++; KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Linking succeeded.\n"); @@ -699,40 +173,36 @@ index 2aa9b8e6b0ab..1e62498dc845 100644 archiveModules[i] = 0; // We need to recompute the undefined symbols in the composite module -@@ -426,8 +447,12 @@ Module *klee::linkWithLibrary(Module *module, +@@ -445,7 +461,9 @@ Module *klee::linkWithLibrary(Module *module, + std::string ErrorMessage; - #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) - ErrorOr > Result = parseBitcodeFile(buff, Context); -- -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ if ((ec = Buffer.getError()) || -+ Linker::linkModules(*module, std::move(Result.get()))) -+#else - if ((ec = Buffer.getError()) || Linker::LinkModules(module, Result->get())) + if (magic == sys::fs::file_magic::bitcode) { ++#if LLVM_VERSION_CODE < LLVM_VERSION(3, 8) + Module *Result = 0; +#endif - klee_error("Link with library %s failed: %s", libraryName.c_str(), - ec.message().c_str()); - #else // LLVM 3.5, 3.6 -@@ -487,7 +512,7 @@ Module *klee::linkWithLibrary(Module *module, - #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) - error_code ec; - OwningPtr Buffer; -- if (ec = MemoryBuffer::getFile(libraryName, Buffer)) { -+ if ((ec = MemoryBuffer::getFile(libraryName, Buffer))) { - klee_error("Link with library %s failed: %s", libraryName.c_str(), - ec.message().c_str()); - } -@@ -510,7 +535,7 @@ Module *klee::linkWithLibrary(Module *module, + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7) + ErrorOr > ResultErr = +@@ -463,11 +481,15 @@ Module *klee::linkWithLibrary(Module *module, + ErrorMessage.c_str()); + } - } else if (magic == sys::fs::file_magic::archive) { - OwningPtr arch; -- if (ec = object::createBinary(Buffer.take(), arch)) -+ if ((ec = object::createBinary(Buffer.take(), arch))) - klee_error("Link with library %s failed: %s", libraryName.c_str(), - ec.message().c_str()); +-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) && \ ++ LLVM_VERSION_CODE < LLVM_VERSION(3, 8) + Result = ResultErr.get(); + #endif +-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) ++#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) ++ if (Linker::linkModules(*module, std::move(ResultErr.get()))) { ++ ErrorMessage = "linking error"; ++#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + if (Linker::LinkModules(module, Result)) { + ErrorMessage = "linking error"; + #else diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp -index 3eca0db6c174..e6a6c35e9ce2 100644 +index 68acd2b17dda..46ab7d028224 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -126,7 +126,12 @@ static void AddStandardCompilePasses(PassManager &PM) { @@ -749,7 +219,7 @@ index 3eca0db6c174..e6a6c35e9ce2 100644 if (!DisableInline) addPass(PM, createFunctionInliningPass()); // Inline small functions -@@ -258,8 +263,14 @@ void Optimize(Module *M, const std::string &EntryPoint) { +@@ -257,8 +262,14 @@ void Optimize(Module *M, const std::string &EntryPoint) { addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas // Run a few AA driven optimizations here and now, to cleanup the code. @@ -764,27 +234,11 @@ index 3eca0db6c174..e6a6c35e9ce2 100644 addPass(Passes, createLICMPass()); // Hoist loop invariants addPass(Passes, createGVNPass()); // Remove redundancies -diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp -index a2972ce7ee9b..c820736f5d66 100644 ---- a/lib/Module/RaiseAsm.cpp -+++ b/lib/Module/RaiseAsm.cpp -@@ -126,7 +126,11 @@ bool RaiseAsmPass::runOnModule(Module &M) { - for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) { - for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) { - for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ auto i = static_cast(ii); -+#else - Instruction *i = ii; -+#endif - ++ii; - changed |= runOnInstruction(M, i); - } diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp -index 9265abe04820..80af2c253997 100644 +index 20b1e33a6617..4acefbf8c4de 100644 --- a/tools/klee/main.cpp +++ b/tools/klee/main.cpp -@@ -313,7 +313,12 @@ KleeHandler::KleeHandler(int argc, char **argv) +@@ -310,7 +310,12 @@ KleeHandler::KleeHandler(int argc, char **argv) for (; i <= INT_MAX; ++i) { SmallString<128> d(directory); llvm::sys::path::append(d, "klee-out-"); @@ -798,54 +252,7 @@ index 9265abe04820..80af2c253997 100644 // create directory and try to link klee-last if (mkdir(d.c_str(), 0775) == 0) { -@@ -690,11 +695,17 @@ static int initEnv(Module *mainModule) { - if (mainFn->arg_size() < 2) { - klee_error("Cannot handle ""--posix-runtime"" when main() has less than two arguments.\n"); - } -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ auto firstInst = static_cast(mainFn->begin()->begin()); - -- Instruction* firstInst = mainFn->begin()->begin(); -+ auto oldArgc = static_cast(mainFn->arg_begin()); -+ auto oldArgv = static_cast(++mainFn->arg_begin()); -+#else -+ Instruction *firstInst = mainFn->begin()->begin(); - -- Value* oldArgc = mainFn->arg_begin(); -- Value* oldArgv = ++mainFn->arg_begin(); -+ Value *oldArgc = mainFn->arg_begin(); -+ Value *oldArgv = ++mainFn->arg_begin(); -+#endif - - AllocaInst* argcPtr = - new AllocaInst(oldArgc->getType(), "argcPtr", firstInst); -@@ -1099,7 +1110,11 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) - // naming conflict. - for (Module::iterator fi = mainModule->begin(), fe = mainModule->end(); - fi != fe; ++fi) { -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ auto f = static_cast(fi); -+#else - Function *f = fi; -+#endif - const std::string &name = f->getName(); - if (name[0]=='\01') { - unsigned size = name.size(); -@@ -1158,8 +1173,13 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) - std::vector args; - args.push_back(llvm::ConstantExpr::getBitCast(userMainFn, - ft->getParamType(0))); -+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8) -+ args.push_back(static_cast(stub->arg_begin())); // argc -+ args.push_back(static_cast(++stub->arg_begin())); // argv -+#else - args.push_back(stub->arg_begin()); // argc - args.push_back(++stub->arg_begin()); // argv -+#endif - args.push_back(Constant::getNullValue(ft->getParamType(3))); // app_init - args.push_back(Constant::getNullValue(ft->getParamType(4))); // app_fini - args.push_back(Constant::getNullValue(ft->getParamType(5))); // rtld_fini -@@ -1301,7 +1321,11 @@ int main(int argc, char **argv, char **envp) { +@@ -1296,7 +1301,11 @@ int main(int argc, char **argv, char **envp) { #else mainModule = *mainModuleOrError; #endif @@ -858,5 +265,5 @@ index 9265abe04820..80af2c253997 100644 ec.message().c_str()); } -- -2.11.1 +2.12.0 diff --git a/_servicedata b/_servicedata index 596a82a..487e162 100644 --- a/_servicedata +++ b/_servicedata @@ -1,4 +1,4 @@ git://github.com/klee/klee.git - 62ee2e574b9f920e6679c91da25f8941552277d9 \ No newline at end of file + 76bcb45aab9c86c63db3b834cca6126effd1c112 \ No newline at end of file diff --git a/klee-1.3.0+20170221.tar.xz b/klee-1.3.0+20170221.tar.xz deleted file mode 100644 index 53e1ae5..0000000 --- a/klee-1.3.0+20170221.tar.xz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:841212a2355f09d4d479d54487889eaeabc3c4f2dbda90961f31ad60e2e3192c -size 646268 diff --git a/klee-1.3.0+20170307.tar.xz b/klee-1.3.0+20170307.tar.xz new file mode 100644 index 0000000..97ba0d4 --- /dev/null +++ b/klee-1.3.0+20170307.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6800445fc72bb9f36aa46e5debcbb406eb853fc0659e889aa98d9ea13f310074 +size 648328 diff --git a/klee.changes b/klee.changes index 483219c..ce42bfb 100644 --- a/klee.changes +++ b/klee.changes @@ -1,3 +1,25 @@ +------------------------------------------------------------------- +Wed Mar 15 12:57:25 UTC 2017 - jslaby@suse.com + +- add 0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch +- Update to version 1.3.0+20170307: + * klee: remove use of deprecated 'register' + * Makefile: change -std-compile-opts to -O3 + * CommandLine: do not copy list in optionIsSet + * Teach KLEE to respect the requested memory alignment of globals and stack variables when possible. + * llvm: stop using global context + * Module: simplify is_object checks + * convert iterators using static_cast + * Core: MCJIT functions need unique names + * Added new option --warnings-only-to-file which causes warnings to be written to warnings.txt only. Disabled by default. + * Updated test cases that check warning messages. + * Core: explicitly create CallSite from Instruction + * fix for PathOS.id + * Using klee_message instead of llvm:errs + * Moved printFileLine() to be part of KInstruction + * test: POSIX/DirSeek, cleanup + * test: ConstantExpr, fix bogus test + ------------------------------------------------------------------- Thu Mar 2 14:11:06 UTC 2017 - jslaby@suse.com diff --git a/klee.spec b/klee.spec index b288191..d746e20 100644 --- a/klee.spec +++ b/klee.spec @@ -17,7 +17,7 @@ %define llvm_version 3_8 -%define version_unconverted 1.3.0+20170221 +%define version_unconverted 1.3.0+20170307 %ifarch %{ix86} x86_64 %define with_uclibc 1 @@ -29,7 +29,7 @@ Name: klee Summary: LLVM Execution Engine License: NCSA Group: Development/Languages/Other -Version: 1.3.0+20170221 +Version: 1.3.0+20170307 Release: 0 Url: http://klee.github.io/ Source0: %{name}-%{version}.tar.xz @@ -37,6 +37,7 @@ Source1: %{name}-rpmlintrc Patch0: 0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch Patch1: 0002-Make-KLEE-compile-against-LLVM-3.7.patch Patch2: 0003-Make-KLEE-compile-against-LLVM-3.8.patch +Patch3: 0001-runtime-POSIX-make-it-compile-with-glibc-2.25.patch BuildRequires: bison BuildRequires: clang%{llvm_version} BuildRequires: cmake @@ -65,6 +66,7 @@ information on what KLEE is and what it can do, see the OSDI 2008 paper. %patch0 -p1 %patch1 -p1 %patch2 -p1 +%patch3 -p1 %build %define __builder ninja