Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the sqlite3-dependency optional #711

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,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)

Expand Down
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
#cmakedefine DYNAMIC_LOG
#cmakedefine BUILD_PHASAR_CLANG

#cmakedefine PHASAR_HAS_SQLITE

#endif /* PHASAR_CONFIG_CONFIG_H */
6 changes: 5 additions & 1 deletion include/phasar/DB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions include/phasar/DB/Hexastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <array>
#include <string>
#include <vector>

struct sqlite3;

namespace psr {
/**
* @brief Holds the results of a query to the Hexastore.
Expand Down Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

namespace psr {

Expand Down Expand Up @@ -368,18 +367,8 @@ template <typename AnalysisDomainTy, unsigned K> 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);
Expand Down
1 change: 0 additions & 1 deletion lib/AnalysisStrategy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
44 changes: 25 additions & 19 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_phasar_library(phasar_controller
phasar_utils
phasar_analysis_strategy
phasar_taintconfig
phasar_passes

LLVM_LINK_COMPONENTS
Core
Expand Down
20 changes: 9 additions & 11 deletions lib/DB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 6 additions & 1 deletion lib/DB/Hexastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/ControlFlow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 <memory>

using namespace psr;

OTFResolver::OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH,
Expand Down Expand Up @@ -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<llvm::GlobalVariable>(P)) {
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/DB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_phasar_library(phasar_llvm_db
${PSR_LLVM_DB_SRC}

LINKS
phasar_db
phasar_utils
phasar_llvm_utils

Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_phasar_library(phasar_mono
phasar_utils
phasar_llvm_utils
phasar_llvm_controlflow
phasar_db
phasar_taintconfig

LLVM_LINK_COMPONENTS
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/Pointer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_phasar_library(phasar_llvm_pointer

LINKS
phasar_utils
phasar_db
phasar_pointer
phasar_llvm_utils
phasar_llvm_db
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/TaintConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_phasar_library(phasar_taintconfig

LINKS
phasar_utils
phasar_db
phasar_llvm_db
phasar_llvm_utils
phasar_controlflow
Expand Down
1 change: 0 additions & 1 deletion lib/Pointer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ add_phasar_library(phasar_pointer

LINKS
phasar_utils
phasar_db

LLVM_LINK_COMPONENTS
Support
Expand Down
14 changes: 8 additions & 6 deletions unittests/DB/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion utils/InstallAptDependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading