From f31326ebdbe76ce3e03c114fc2354167a8c650d9 Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Tue, 12 Mar 2024 19:26:22 +0100 Subject: [PATCH] Make the sqlite3-dependency optional + minor --- CMakeLists.txt | 8 +++- bootstrap.sh | 2 +- config.h.in | 2 + include/phasar/DB.h | 6 ++- include/phasar/DB/Hexastore.h | 12 +++-- .../DataFlow/Mono/Solver/InterMonoSolver.h | 15 +------ lib/AnalysisStrategy/CMakeLists.txt | 1 - lib/CMakeLists.txt | 44 +++++++++++-------- lib/Controller/CMakeLists.txt | 1 + lib/DB/CMakeLists.txt | 20 ++++----- lib/DB/Hexastore.cpp | 7 ++- lib/PhasarLLVM/ControlFlow/CMakeLists.txt | 1 - .../ControlFlow/Resolver/OTFResolver.cpp | 9 ---- lib/PhasarLLVM/DB/CMakeLists.txt | 1 - .../DataFlow/IfdsIde/CMakeLists.txt | 1 - lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt | 1 - lib/PhasarLLVM/Pointer/CMakeLists.txt | 1 - lib/PhasarLLVM/TaintConfig/CMakeLists.txt | 1 - lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt | 1 + lib/Pointer/CMakeLists.txt | 1 - unittests/DB/CMakeLists.txt | 14 +++--- utils/InstallAptDependencies.sh | 2 +- 22 files changed, 75 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ddf030ca..8dc7ac735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,8 +294,12 @@ else() endif() # SQL -find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) -find_library(SQLITE3_LIBRARY NAMES sqlite3) +find_package(SQLite3) +if(SQLite3_FOUND) + set(PHASAR_HAS_SQLITE ON) +else() + set(PHASAR_HAS_SQLITE OFF) +endif() option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM libraries if possible (default is OFF; always on if BUILD_SHARED_LIBS is ON)" OFF) diff --git a/bootstrap.sh b/bootstrap.sh index bb641b5da..345d88570 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -108,7 +108,7 @@ set -- "${POSITIONAL[@]}" # restore positional parameters echo "installing phasar dependencies..." if [ -x "$(command -v pacman)" ]; then - yes | sudo pacman -Syu --needed which zlib sqlite3 python3 doxygen gcc python-pip ninja cmake + yes | sudo pacman -Syu --needed which zlib python3 doxygen gcc ninja cmake else ./utils/InstallAptDependencies.sh fi diff --git a/config.h.in b/config.h.in index 923329206..253f05f86 100644 --- a/config.h.in +++ b/config.h.in @@ -9,4 +9,6 @@ #cmakedefine DYNAMIC_LOG #cmakedefine BUILD_PHASAR_CLANG +#cmakedefine PHASAR_HAS_SQLITE + #endif /* PHASAR_CONFIG_CONFIG_H */ diff --git a/include/phasar/DB.h b/include/phasar/DB.h index f77b88f01..4ddd16a5e 100644 --- a/include/phasar/DB.h +++ b/include/phasar/DB.h @@ -10,8 +10,12 @@ #ifndef PHASAR_DB_H #define PHASAR_DB_H -#include "phasar/DB/Hexastore.h" +#include "phasar/Config/phasar-config.h" #include "phasar/DB/ProjectIRDBBase.h" + +#ifdef PHASAR_HAS_SQLITE +#include "phasar/DB/Hexastore.h" #include "phasar/DB/Queries.h" +#endif #endif // PHASAR_DB_H diff --git a/include/phasar/DB/Hexastore.h b/include/phasar/DB/Hexastore.h index 02bfb698a..d6960c903 100644 --- a/include/phasar/DB/Hexastore.h +++ b/include/phasar/DB/Hexastore.h @@ -10,17 +10,20 @@ #ifndef PHASAR_DB_HEXASTORE_H_ #define PHASAR_DB_HEXASTORE_H_ -#include "phasar/DB/Queries.h" +#include "phasar/Config/phasar-config.h" +#ifndef PHASAR_HAS_SQLITE +#error \ + "Hexastore requires SQLite3. Please install libsqlite3-dev and reconfigure PhASAR." +#endif #include "llvm/Support/raw_ostream.h" -#include "boost/format.hpp" -#include "sqlite3.h" - #include #include #include +struct sqlite3; + namespace psr { /** * @brief Holds the results of a query to the Hexastore. @@ -51,6 +54,7 @@ struct HSResult { LHS.Object == RHS.Object; } }; + /** * A Hexastore is an efficient approach to store large graphs. * This approach is based on the paper "Database-Backed Program Analysis diff --git a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h index 4e05c9279..0be77db3d 100644 --- a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h +++ b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h @@ -24,7 +24,6 @@ #include #include #include -#include namespace psr { @@ -368,18 +367,8 @@ template class InterMonoSolver { } // Compute the data-flow facts using the respective kind of flows if (ICF->isCallSite(Src)) { - // Handle call flow(s) - if (!isIntraEdge(Edge)) { - // real call - for (auto &[Ctx, Facts] : Analysis[Src]) { - processCall(Edge); // TODO: decompose into processCall and - // processCallToRet - } - } else { - // call-to-return - processCall( - Edge); // TODO: decompose into processCall and processCallToRet - } + // Handle call flow(s) and call-to-return flow + processCall(Edge); } else if (ICF->isExitInst(Src)) { // Handle return flow processExit(Edge); diff --git a/lib/AnalysisStrategy/CMakeLists.txt b/lib/AnalysisStrategy/CMakeLists.txt index 5bb3d4446..8a194cc68 100644 --- a/lib/AnalysisStrategy/CMakeLists.txt +++ b/lib/AnalysisStrategy/CMakeLists.txt @@ -2,6 +2,5 @@ file(GLOB_RECURSE ANALYSIS_STRATEGY_SRC *.h *.cpp) add_phasar_library(phasar_analysis_strategy ${ANALYSIS_STRATEGY_SRC} - LINKS phasar_db phasar_controlflow LLVM_LINK_COMPONENTS Support ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e1cc7b0f6..3c2ab5fdf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -18,29 +18,35 @@ if(PHASAR_BUILD_DYNLIB) set(PHASAR_DYNLIB_KIND SHARED) endif() +set(PHASAR_LINK_LIBS + phasar_utils + phasar_passes + phasar_config + phasar_pointer + phasar_controlflow + + phasar_llvm_utils + phasar_llvm_db + phasar_llvm_pointer + phasar_llvm_typehierarchy + phasar_llvm_controlflow + + phasar_taintconfig + phasar_mono + phasar_llvm + phasar_llvm_ifdside + phasar_analysis_strategy + phasar_controller +) +if(SQLite3_FOUND) + list(APPEND PHASAR_LINK_LIBS phasar_db) +endif() + add_phasar_library(phasar ${PHASAR_DYNLIB_KIND} FILES LibPhasar.cpp LINKS - phasar_utils - phasar_passes - phasar_config - phasar_db - phasar_pointer - phasar_controlflow - - phasar_llvm_utils - phasar_llvm_db - phasar_llvm_pointer - phasar_llvm_typehierarchy - phasar_llvm_controlflow - - phasar_taintconfig - phasar_mono - phasar_llvm - phasar_llvm_ifdside - phasar_analysis_strategy - phasar_controller + ${PHASAR_LINK_LIBS} LINK_PRIVATE ${Boost_LIBRARIES} LLVM_LINK_COMPONENTS diff --git a/lib/Controller/CMakeLists.txt b/lib/Controller/CMakeLists.txt index dba171b58..b5fe95c5b 100644 --- a/lib/Controller/CMakeLists.txt +++ b/lib/Controller/CMakeLists.txt @@ -15,6 +15,7 @@ add_phasar_library(phasar_controller phasar_utils phasar_analysis_strategy phasar_taintconfig + phasar_passes LLVM_LINK_COMPONENTS Core diff --git a/lib/DB/CMakeLists.txt b/lib/DB/CMakeLists.txt index d5dbf67e1..74fef8d36 100644 --- a/lib/DB/CMakeLists.txt +++ b/lib/DB/CMakeLists.txt @@ -1,12 +1,10 @@ -file(GLOB_RECURSE DB_SRC *.h *.cpp) +if(SQLite3_FOUND) + file(GLOB_RECURSE DB_SRC *.h *.cpp) -add_phasar_library(phasar_db - ${DB_SRC} - LINKS phasar_passes phasar_utils - LLVM_LINK_COMPONENTS Support - LINK_PRIVATE ${SQLITE3_LIBRARY} -) - -target_include_directories(phasar_db - PRIVATE ${SQLITE3_INCLUDE_DIR} -) + add_phasar_library(phasar_db + ${DB_SRC} + LINKS phasar_passes phasar_utils + LLVM_LINK_COMPONENTS Support + LINK_PRIVATE SQLite::SQLite3 + ) +endif() diff --git a/lib/DB/Hexastore.cpp b/lib/DB/Hexastore.cpp index 6ae20cdfe..a912b4683 100644 --- a/lib/DB/Hexastore.cpp +++ b/lib/DB/Hexastore.cpp @@ -9,11 +9,16 @@ #include "phasar/DB/Hexastore.h" +#include "phasar/DB/Queries.h" + +#include "boost/format.hpp" +#include "sqlite3.h" + namespace psr { Hexastore::Hexastore(const std::string &Filename) { sqlite3_open(Filename.c_str(), &HSInternalDB); - const std::string Query = INIT; + const std::string &Query = INIT; char *Err; sqlite3_exec(HSInternalDB, Query.c_str(), callback, nullptr, &Err); if (Err != nullptr) { diff --git a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt index ff8f27e28..0000f7b1a 100644 --- a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt +++ b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt @@ -7,7 +7,6 @@ add_phasar_library(phasar_llvm_controlflow phasar_llvm_pointer phasar_llvm_typehierarchy phasar_llvm_utils - phasar_db phasar_controlflow LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp index 347399716..556f53d2b 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp @@ -16,8 +16,6 @@ #include "phasar/Utils/Logger.h" #include "phasar/Utils/Utilities.h" -#include "llvm/ADT/DenseMapInfo.h" -#include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/Constants.h" @@ -27,12 +25,9 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Operator.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" -#include - using namespace psr; OTFResolver::OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, @@ -95,10 +90,6 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite) PHASAR_LOG_LEVEL(DEBUG, "Virtual function table entry is: " << VtableIndex); - // const llvm::Value *Receiver = CallSite->getArgOperand(0); - - const auto *FTy = CallSite->getFunctionType(); - auto PTS = PT.getAliasSet(CallSite->getCalledOperand(), CallSite); for (const auto *P : *PTS) { if (const auto *PGV = llvm::dyn_cast(P)) { diff --git a/lib/PhasarLLVM/DB/CMakeLists.txt b/lib/PhasarLLVM/DB/CMakeLists.txt index 5c89b3aa6..bb6e3c396 100644 --- a/lib/PhasarLLVM/DB/CMakeLists.txt +++ b/lib/PhasarLLVM/DB/CMakeLists.txt @@ -4,7 +4,6 @@ add_phasar_library(phasar_llvm_db ${PSR_LLVM_DB_SRC} LINKS - phasar_db phasar_utils phasar_llvm_utils diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt index 9411bc739..327eb03af 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt @@ -11,7 +11,6 @@ add_phasar_library(phasar_llvm_ifdside phasar_llvm_typehierarchy phasar_llvm_controlflow phasar_llvm_utils - phasar_db phasar_taintconfig LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt index 7c7d00bf9..4bbda6173 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt @@ -8,7 +8,6 @@ add_phasar_library(phasar_mono phasar_utils phasar_llvm_utils phasar_llvm_controlflow - phasar_db phasar_taintconfig LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/Pointer/CMakeLists.txt b/lib/PhasarLLVM/Pointer/CMakeLists.txt index c189f6153..35cabf8af 100644 --- a/lib/PhasarLLVM/Pointer/CMakeLists.txt +++ b/lib/PhasarLLVM/Pointer/CMakeLists.txt @@ -5,7 +5,6 @@ add_phasar_library(phasar_llvm_pointer LINKS phasar_utils - phasar_db phasar_pointer phasar_llvm_utils phasar_llvm_db diff --git a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt index 1a801938f..e3a9050f3 100644 --- a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt +++ b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt @@ -5,7 +5,6 @@ add_phasar_library(phasar_taintconfig LINKS phasar_utils - phasar_db phasar_llvm_db phasar_llvm_utils phasar_controlflow diff --git a/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt b/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt index 3c3d86078..d717d39f5 100644 --- a/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt +++ b/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt @@ -6,6 +6,7 @@ add_phasar_library(phasar_llvm_typehierarchy LINKS phasar_utils + phasar_llvm_db LLVM_LINK_COMPONENTS Core diff --git a/lib/Pointer/CMakeLists.txt b/lib/Pointer/CMakeLists.txt index 5c2f8d43e..4695aeb0a 100644 --- a/lib/Pointer/CMakeLists.txt +++ b/lib/Pointer/CMakeLists.txt @@ -6,7 +6,6 @@ add_phasar_library(phasar_pointer LINKS phasar_utils - phasar_db LLVM_LINK_COMPONENTS Support diff --git a/unittests/DB/CMakeLists.txt b/unittests/DB/CMakeLists.txt index d3b224e01..87e1de139 100644 --- a/unittests/DB/CMakeLists.txt +++ b/unittests/DB/CMakeLists.txt @@ -1,7 +1,9 @@ -set(DBSources - HexastoreTest.cpp -) +if(SQLite3_FOUND) + set(DBSources + HexastoreTest.cpp + ) -foreach(TEST_SRC ${DBSources}) - add_phasar_unittest(${TEST_SRC}) -endforeach(TEST_SRC) + foreach(TEST_SRC ${DBSources}) + add_phasar_unittest(${TEST_SRC}) + endforeach(TEST_SRC) +endif() diff --git a/utils/InstallAptDependencies.sh b/utils/InstallAptDependencies.sh index 37bc530c6..f8d4f3a0a 100755 --- a/utils/InstallAptDependencies.sh +++ b/utils/InstallAptDependencies.sh @@ -3,4 +3,4 @@ set -e sudo apt-get update sudo apt-get install git -y -sudo apt-get install zlib1g-dev sqlite3 libsqlite3-dev python3 doxygen python3-pip g++ ninja-build cmake -y +sudo apt-get install zlib1g-dev python3 g++ ninja-build cmake -y