From 9eda5e2678bd6c2a799dbd84db8d4a983af76361 Mon Sep 17 00:00:00 2001 From: Fabian Schiebel <52407375+fabianbs96@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:52:43 +0200 Subject: [PATCH] Cleanup Build (#673) * Pin swift version * Some build cleanup * Correctly find unittests even if the build-folder is not called "build" * Greater build variety in the CI * Minimize direct modification of CMAKE_CXX_FLAGS + use portable variants of some compilation flags if available + add the ability to turn on -march=native + minor * Add compile options only for C++ build + link LLVM publicly to support BUILD_SHARED_LIBS * Only add asan for CXX builds * Some build cleanup * Correctly find unittests even if the build-folder is not called "build" * Greater build variety in the CI * Minimize direct modification of CMAKE_CXX_FLAGS + use portable variants of some compilation flags if available + add the ability to turn on -march=native + minor * Add compile options only for C++ build + link LLVM publicly to support BUILD_SHARED_LIBS * Only add asan for CXX builds * Move config defines to config.h.in * Fix add_cxx_* macros + link more privately * Make PhasarClang optional * Install phasar-config.h * Out-factor DebugSan in PHASAR_ENABLE_SANITIZERS * Allow for multi-config (not tested) * Make dependencies independent from phasar build flags + enable more warnings * Support for manually setting USE_LLVM_FAT_LIB + remove some obsolete system dependencies * Cleanup system deps * Fix install boost in CI * Modernize LLVM build + minor improvements in bootstrap.sh * Improve add_phasar_library * Fix phasar_llvm lib build * Cleanup inclusion of OpenSSL- and Swift tests * minor * Remove explicit definition of linker language and lib prefix * Update install * Improve install by adding phasar include directories to the targets interfaces * minor * Small fixes for the in-tree build * minor style * minor tweak for in-tree build --- .clang-tidy | 1 + .github/ISSUE_TEMPLATE/bug_report.md | 11 +- .github/workflows/ci.yml | 24 +- BreakingChanges.md | 1 + CMakeLists.txt | 450 ++++++++++-------- Config.cmake.in | 41 +- Dockerfile | 3 +- bootstrap.sh | 44 +- cmake/phasar_macros.cmake | 127 +++-- config.h.in | 14 +- examples/use-phasar-as-library/CMakeLists.txt | 15 +- include/CMakeLists.txt | 1 - include/phasar/CMakeLists.txt | 0 include/phasar/Config/Configuration.h | 3 - include/phasar/ControlFlow/CallGraphBase.h | 2 - .../DataFlow/Mono/Solver/InterMonoSolver.h | 4 +- include/phasar/Utils/Logger.h | 2 + include/phasar/Utils/PAMMMacros.h | 2 + include/phasar/Utils/Utilities.h | 10 +- lib/AnalysisStrategy/CMakeLists.txt | 29 +- lib/CMakeLists.txt | 80 ++-- lib/Config/CMakeLists.txt | 34 +- lib/Config/Configuration.cpp | 10 +- lib/ControlFlow/CMakeLists.txt | 27 +- lib/Controller/CMakeLists.txt | 59 +-- lib/DB/CMakeLists.txt | 39 +- lib/PhasarClang/CMakeLists.txt | 45 +- lib/PhasarLLVM/CMakeLists.txt | 25 +- lib/PhasarLLVM/ControlFlow/CMakeLists.txt | 40 +- .../ControlFlow/Resolver/OTFResolver.cpp | 2 +- lib/PhasarLLVM/DB/CMakeLists.txt | 40 +- .../DataFlow/IfdsIde/CMakeLists.txt | 50 +- .../BranchSwitchInstFlowFunction.cpp | 2 +- .../AbstractMemoryLocationFactory.cpp | 3 +- .../Problems/IDEExtendedTaintAnalysis.cpp | 2 +- lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt | 40 +- lib/PhasarLLVM/Passes/CMakeLists.txt | 38 +- lib/PhasarLLVM/Pointer/CMakeLists.txt | 52 +- lib/PhasarLLVM/TaintConfig/CMakeLists.txt | 45 +- lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt | 43 +- lib/PhasarLLVM/Utils/CMakeLists.txt | 45 +- lib/PhasarPass/CMakeLists.txt | 60 +-- lib/PhasarPass/PhasarPass.cpp | 2 +- lib/Pointer/CMakeLists.txt | 32 +- lib/Pointer/PointsToInfo.cpp | 8 +- lib/Utils/CMakeLists.txt | 36 +- tools/example-tool/CMakeLists.txt | 9 +- tools/phasar-cli/CMakeLists.txt | 36 +- tools/phasar-cli/phasar-cli.cpp | 2 +- unittests/CMakeLists.txt | 4 +- .../DataFlow/IfdsIde/Problems/CMakeLists.txt | 48 +- .../IDELinearConstantAnalysis_DotTest.cpp | 1 - .../PhasarLLVM/Pointer/LLVMAliasSetTest.cpp | 8 +- unittests/TestUtils/TestConfig.h | 14 +- unittests/Utils/EquivalenceClassMapTest.cpp | 2 +- utils/InstallAptDependencies.sh | 6 +- utils/install-llvm.sh | 4 +- 57 files changed, 744 insertions(+), 1033 deletions(-) delete mode 100644 include/CMakeLists.txt delete mode 100644 include/phasar/CMakeLists.txt diff --git a/.clang-tidy b/.clang-tidy index 063d1090a..5d40d294d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -25,6 +25,7 @@ Checks: '-*, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-init-variables, -cppcoreguidelines-macro-usage, + -cppcoreguidelines-avoid-do-while, bugprone-*, -bugprone-easily-swappable-parameters, modernize-*, diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index a571a74a2..24e0ca0b9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -11,7 +11,7 @@ assignees: '' Replace the empty checkboxes [ ] below with checked ones [x] accordingly. --> - [ ] I have searched open and closed issues for duplicates - - [ ] I made sure that I am not using an old project version (DO: pull Phasar, update git submodules, rebuild the project and check if the bug is still there) + - [ ] I made sure that I am not using an old project version (DO: pull PhASAR, update git submodules, rebuild the project and check if the bug is still there) ---------------------------------------- @@ -24,9 +24,9 @@ Describe here the issue that you are experiencing. - that reproduce the bug - e.g. cli arguments and flags -**Actual result:** Describe here what happens after you run the steps above (i.e. the buggy behaviour) +**Actual result:** Describe here what happens after you run the steps above (i.e. the buggy behavior) -**Expected result:** Describe here what should happen after you run the steps above (i.e. what would be the correct behaviour) +**Expected result:** Describe here what should happen after you run the steps above (i.e. what would be the correct behavior) ### Context (Environment) @@ -35,7 +35,7 @@ Describe here the issue that you are experiencing. - **phasar:** \[commit-id] - **googletest:** \[commit-id] - **json:** \[commit-id] - - **WALi-OpenNWA:** \[commit-id] + - **json-schema-validator** \[commit-id] @@ -48,11 +48,12 @@ Describe here the issue that you are experiencing. **Build Type:** - [ ] cmake + - [ ] bootstrap.sh - [ ] custom build ### Possible solution -We are happy to discuss possible solutions to this problem, especially if it origniates from a design flaw. +We are happy to discuss possible solutions to this problem, especially if it originates from a design flaw. ### Example files diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccf529334..d109a180f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,11 @@ jobs: matrix: compiler: [ [clang++-14, clang-14] ] build: [ Debug, Release ] + include: + - build: Debug + flags: -DPHASAR_BUILD_DYNLIB=ON -DPHASAR_ENABLE_SANITIZERS=ON + - build: Release + flags: -DPHASAR_ENABLE_DYNAMIC_LOG=OFF continue-on-error: false steps: @@ -23,20 +28,11 @@ jobs: fetch-depth: 0 submodules: recursive - - name: Install Basic Dependencies - shell: bash - run: | - sudo apt-get update - sudo apt-get -y install --no-install-recommends \ - cmake \ - ninja-build \ - libstdc++6 \ - libboost-all-dev - - name: Install Phasar Dependencies shell: bash run: | ./utils/InstallAptDependencies.sh + sudo apt-get -y install --no-install-recommends libboost-graph-dev - name: Install Strategy Dependencies shell: bash @@ -59,7 +55,6 @@ jobs: swift-version: "5.8.1" - name: Building Phasar in ${{ matrix.build }} with ${{ matrix.compiler[0] }} env: - BUILD_TYPE: ${{ matrix.build }} CXX: ${{ matrix.compiler[0] }} CC: ${{ matrix.compiler[1] }} shell: bash @@ -67,9 +62,10 @@ jobs: mkdir build cd build cmake .. \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_CXX_COMPILER=$CXX \ - -DBUILD_SWIFT_TESTS=1 \ + -DCMAKE_BUILD_TYPE=${{ matrix.build }} \ + -DBUILD_SWIFT_TESTS=ON \ + -DPHASAR_DEBUG_LIBDEPS=ON \ + ${{ matrix.flags }} \ -G Ninja cmake --build . diff --git a/BreakingChanges.md b/BreakingChanges.md index 477de93b7..ad40d45f6 100644 --- a/BreakingChanges.md +++ b/BreakingChanges.md @@ -3,6 +3,7 @@ ## Development HEAD - Default build mode is no longer `SHARED` but `STATIC`. To build in shared mode, use the cmake option `BUILD_SHARED_LIBS` which we don't recommend anymore. Consider using `PHASAR_BUILD_DYNLIB` instead to build one big libphasar.so. +- Build type `DebugSan` has been removed in favor of a new CMake option `PHASAR_ENABLE_SANITIZERS` that not only works in `Debug` mode. ## v0323 diff --git a/CMakeLists.txt b/CMakeLists.txt index b9eb75366..68c3607c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,14 @@ cmake_minimum_required (VERSION 3.9) cmake_policy(SET CMP0069 NEW) set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) +# Allow overwriting options of external projects from this CMakeLists file +cmake_policy(SET CMP0077 NEW) +set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + +# Allow portable use of CMAKE_VISIBILITY_INLINES_HIDDEN not only for shared libraries +cmake_policy(SET CMP0063 NEW) +set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) + # Check if we build within the llvm source tree if (DEFINED LLVM_MAIN_SRC_DIR) set(PHASAR_IN_TREE 1) @@ -18,7 +26,7 @@ option(PHASAR_EXPERIMENTAL_CXX20 "Build phasar in C++20 mode. This is an experim set(CMAKE_EXPORT_COMPILE_COMMANDS YES) if(PHASAR_EXPERIMENTAL_CXX20) - message(STATUS "Selected experimental C++ build") + message(STATUS "Selected experimental C++20 build") set(CMAKE_CXX_STANDARD 20) else() set(CMAKE_CXX_STANDARD 17) @@ -30,60 +38,95 @@ include(GNUInstallDirs) set_property(GLOBAL PROPERTY TARGET_MESSAGES OFF) -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build mode ('DebugSan' or 'Debug' or 'Release', default is 'Debug')" FORCE) +option(PHASAR_ENABLE_SANITIZERS "Build PhASAR with AddressSanitizer and UBSanitizer (default is OFF)" OFF) + +set(PHASAR_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(PHASAR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PHASAR_SRC_DIR}/cmake") +include("phasar_macros") + +if (NOT CMAKE_BUILD_TYPE AND NOT GENERATOR_IS_MULTI_CONFIG) + message(STATUS "No CMAKE_BUILD_TYPE specified, setting it to Debug") + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build mode ('Debug' or 'Release', default is 'Debug')" FORCE) endif () -if(CMAKE_BUILD_TYPE STREQUAL "DebugSan") - message(STATUS "Selected Debug Build with sanitizers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g -fno-omit-frame-pointer -fsanitize=address,undefined") -elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS "Selected Debug Build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g") +if(GENERATOR_IS_MULTI_CONFIG) + message(STATUS "Selected multi-config Build") + set(CMAKE_CONFIGURATION_TYPES Debug RelWithDebInfo Release CACHE STRING "Configuration types: Debug, RelWithDebInfo and Release" FORCE) else() - message(STATUS "Selected Release Build") + message(STATUS "Selected ${CMAKE_BUILD_TYPE} Build") +endif() - include(CheckIPOSupported) - check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_SUPPORT_ERROR) +set(DEBUG_CONFIGURATIONS DEBUG CACHE INTERNAL "" FORCE) +set(RELEASE_CONFIGURATIONS RELWITHDEBINFO RELEASE CACHE INTERNAL "" FORCE) +# TODO: Once available, we may want to use -fextend-lifetimes on Debug- and RelWithDebInfo builds to improve debugging experience +# https://reviews.llvm.org/D157613 - if(LTO_SUPPORTED) - message(STATUS "IPO/LTO enabled") - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) # LTO - else() - message(STATUS "IPO/LTO not supported: ${LTO_SUPPORT_ERROR}") - endif() +string(APPEND CMAKE_CXX_FLAGS " -MP -fstack-protector-strong -ffunction-sections -fdata-sections -pipe") +string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Og -fno-omit-frame-pointer") +string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -fno-omit-frame-pointer") +string(APPEND CMAKE_CXX_FLAGS_RELEASE "") + +option(CMAKE_VISIBILITY_INLINES_HIDDEN "Hide inlined functions from the DSO table (default ON)" ON) +# march=native - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe") +# NOTE: Use gcc -march=native -Q --help=target | grep -- '-march=' | cut -f3 +# to check the architecture detected by match=native +# set(PHASAR_TARGET_ARCH "" CACHE STRING "Optimize the build for the given target architecture, e.g. -march=native. Most useful in Release builds. Disabled by default") +if (DEFINED PHASAR_TARGET_ARCH) + if (NOT CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT GENERATOR_IS_MULTI_CONFIG) + message(WARNING "The PHASAR_TARGET_ARCH flag will be ignored in non-Release build type ${CMAKE_BUILD_TYPE}") + else() + set(PHASAR_TARGET_ARCH_INTERNAL "${PHASAR_TARGET_ARCH}") + endif() +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + set(PHASAR_TARGET_ARCH_INTERNAL "native") endif() -# Enable testing -enable_testing() +if (NOT "${PHASAR_TARGET_ARCH_INTERNAL}" STREQUAL "") + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-march=${PHASAR_TARGET_ARCH_INTERNAL}" MARCH_SUPPORTED) + if (MARCH_SUPPORTED) + message(STATUS "Target architecture '${PHASAR_TARGET_ARCH_INTERNAL}' enabled") + string(APPEND CMAKE_CXX_FLAGS_RELEASE " -march=${PHASAR_TARGET_ARCH_INTERNAL}") + else() + message(WARNING "Target architecture '${PHASAR_TARGET_ARCH_INTERNAL}' not supported. Fallback to generic build") + endif() +endif() -# TODO: allow Phasar to be build as a llvm drop-in as well -# if (NOT DEFINED LLVM_MAIN_SRC_DIR) -# message(FATAL_ERROR "Phasar is not a llvm drop-in, abort!") -# endif() +# Sanitizers +if (PHASAR_ENABLE_SANITIZERS) + message(STATUS "Selected ${CMAKE_BUILD_TYPE} Build with Sanitizers") -set(PHASAR_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PHASAR_SRC_DIR}/cmake") + if(MSVC) + set(ASAN_FLAG "/fsanitize=address") + else() + set(ASAN_FLAG "-fsanitize=address,undefined") + endif() -file(STRINGS ${PHASAR_SRC_DIR}/include/phasar/Config/Version.h VERSION_NUMBER_FILE) -string(REPLACE " " ";" VERSION_NUMBER_FILE ${VERSION_NUMBER_FILE}) -list(GET VERSION_NUMBER_FILE 2 VERSION_NUMBER_PHASAR) + string(APPEND CMAKE_CXX_FLAGS " ${ASAN_FLAG}") +endif() -include("phasar_macros") +# LTO +if (GENERATOR_IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE STREQUAL "Release") + include(CheckIPOSupported) + check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_SUPPORT_ERROR) -option(PHASAR_BUILD_UNITTESTS "Build all tests (default is ON)" ON) + if(LTO_SUPPORTED) + message(STATUS "IPO/LTO enabled in Release mode") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) # LTO + else() + message(STATUS "IPO/LTO not supported: ${LTO_SUPPORT_ERROR}") + endif() +endif() -option(BUILD_SWIFT_TESTS "Builds the Swift tests (Swift compiler has to be installed manually beforehand!)" OFF) -if (BUILD_SWIFT_TESTS) - set(CMAKE_Swift_FLAGS_RELEASE "-g") - set(CMAKE_Swift_FLAGS_RELWITHDEBINFO "-g") - enable_language(Swift) -endif(BUILD_SWIFT_TESTS) +# Enable testing +enable_testing() + +option(PHASAR_BUILD_UNITTESTS "Build all tests (default is ON)" ON) option(PHASAR_BUILD_OPENSSL_TS_UNITTESTS "Build OPENSSL typestate tests (require OpenSSL, default is OFF)" OFF) @@ -102,25 +145,21 @@ if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS) message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS") endif() -option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON) -if (PHASAR_ENABLE_WARNINGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-return-type-c-linkage ") -endif (PHASAR_ENABLE_WARNINGS) - option(PHASAR_ENABLE_PIC "Build Position-Independed Code" ON) if (PHASAR_ENABLE_PIC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif (PHASAR_ENABLE_PIC) +# PAMM if (NOT PHASAR_ENABLE_PAMM) set(PHASAR_ENABLE_PAMM "Off" CACHE STRING "Enable the performance measurement mechanism ('Off', 'Core' or 'Full', default is 'Off')" FORCE) set_property(CACHE PHASAR_ENABLE_PAMM PROPERTY STRINGS "Off" "Core" "Full") endif() if(PHASAR_ENABLE_PAMM STREQUAL "Core" AND NOT PHASAR_BUILD_UNITTESTS) - add_compile_definitions(PAMM_CORE) + set(PAMM_CORE ON) message(STATUS "PAMM metric severity level: Core") elseif(PHASAR_ENABLE_PAMM STREQUAL "Full" AND NOT PHASAR_BUILD_UNITTESTS) - add_compile_definitions(PAMM_FULL) + set(PAMM_FULL ON) message(STATUS "PAMM metric severity level: Full") elseif(PHASAR_BUILD_UNITTESTS AND (PHASAR_ENABLE_PAMM STREQUAL "Core" OR PHASAR_ENABLE_PAMM STREQUAL "Full")) message(WARNING "PAMM metric severity level: Off (due to unittests)") @@ -128,22 +167,17 @@ else() message(STATUS "PAMM metric severity level: Off") endif() +# Logger option(PHASAR_ENABLE_DYNAMIC_LOG "Makes it possible to switch the logger on and off at runtime (default is ON)" ON) if (PHASAR_ENABLE_DYNAMIC_LOG) message(STATUS "Dynamic log enabled") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDYNAMIC_LOG") + set(DYNAMIC_LOG ON) else() message(STATUS "Dynamic log disabled") endif() -configure_file(config.h.in config.h @ONLY) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -include_directories( - ${PHASAR_SRC_DIR}/include -) - +# RPATH if (NOT PHASAR_IN_TREE) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) @@ -155,12 +189,14 @@ if (NOT PHASAR_IN_TREE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) endif() +# Filesystem if (LLVM_ENABLE_LIBCXX) set(PHASAR_STD_FILESYSTEM c++fs) else() set(PHASAR_STD_FILESYSTEM stdc++fs) endif() +# Config set(PHASAR_CUSTOM_CONFIG_INSTALL_DIR "" CACHE STRING "If set, customizes the directory, where configuration files for PhASAR are installed (default is /usr/local/.phasar-config)") if ("${PHASAR_CUSTOM_CONFIG_INSTALL_DIR}" STREQUAL "") set(PHASAR_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/.phasar-config/") @@ -168,28 +204,21 @@ else() set(PHASAR_CONFIG_INSTALL_DIR "${PHASAR_CUSTOM_CONFIG_INSTALL_DIR}") endif() -add_compile_definitions(PHASAR_CONFIG_DIR="${PHASAR_CONFIG_INSTALL_DIR}") -add_compile_definitions(PHASAR_DIR="${PHASAR_SRC_DIR}") - - ### Adding external libraries + # Threads find_package(Threads) # Boost -find_package(Boost 1.65.1 COMPONENTS graph ${BOOST_THREAD} REQUIRED) -#find_package(Boost 1.72.0 COMPONENTS graph ${BOOST_THREAD} REQUIRED) -include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) +find_package(Boost 1.65.1 COMPONENTS graph REQUIRED) # Disable clang-tidy for the external projects set(CMAKE_CXX_CLANG_TIDY "") # Nlohmann JSON - set(JSON_BuildTests OFF) set(JSON_Install ON) add_subdirectory(external/json) -include_directories(SYSTEM external/json/include/) # We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here # The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator @@ -209,88 +238,90 @@ endif() # Json Schema Validator set(JSON_VALIDATOR_INSTALL ON) add_subdirectory(external/json-schema-validator) -include_directories(SYSTEM external/json-schema-validator/src/) # Googletest if (NOT PHASAR_IN_TREE) + set(BUILD_GMOCK OFF) + set(INSTALL_GTEST OFF) add_subdirectory(external/googletest EXCLUDE_FROM_ALL) - include_directories(SYSTEM external/googletest/googletest/include) - include_directories(SYSTEM external/googletest/googlemock/include) + set(GTEST_INCLUDE_DIR "external/googletest/googletest/include") else() # Set llvm distributed includes for gtest header - include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) - include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include) + set(GTEST_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include") endif() # SQL find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) find_library(SQLITE3_LIBRARY NAMES sqlite3) -include_directories(SYSTEM ${SQLITE3_INCLUDE_DIR}) + +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) # LLVM if (NOT PHASAR_IN_TREE) # Only search for LLVM if we build out of tree find_package(LLVM 14 REQUIRED CONFIG) - include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) - link_directories(${LLVM_LIB_PATH} ${LLVM_LIBRARY_DIRS}) -endif() - -add_definitions(${LLVM_DEFINITIONS}) -if (NOT PHASAR_IN_TREE) find_library(LLVM_LIBRARY NAMES LLVM PATHS ${LLVM_LIBRARY_DIRS} NO_DEFAULT_PATH) - if(NOT ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND") - message(STATUS "Found consolidated shared LLVM lib " ${LLVM_LIBRARY} " that will be linked against.") - set(USE_LLVM_FAT_LIB on) + + if(USE_LLVM_FAT_LIB AND ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND") + message(WARNING "Did not find requested libLLVM.so. Link against individual modules instead") + set(USE_LLVM_FAT_LIB OFF) + elseif(BUILD_SHARED_LIBS AND NOT ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND") + message(STATUS "Found consolidated shared LLVM lib ${LLVM_LIBRARY} that will be linked against.") + set(USE_LLVM_FAT_LIB ON) endif() endif() +if(NOT LLVM_ENABLE_RTTI AND NOT PHASAR_IN_TREE) + message(FATAL_ERROR "PhASAR requires a LLVM version that is built with RTTI") +endif() + # Clang -# The clang-cpp shared library is now the preferred way to link dynamically against libclang if we build out of tree. -if(NOT PHASAR_IN_TREE) - find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp REQUIRED HINTS ${LLVM_LIBRARY_DIRS}) - if(${CLANG_LIBRARY} STREQUAL "CLANG_LIBRARY-NOTFOUND") - set(NEED_LIBCLANG_COMPONENT_LIBS on) +option(BUILD_PHASAR_CLANG "Build the phasar_clang library (default is ON)" ON) + +if(BUILD_PHASAR_CLANG) + # The clang-cpp shared library is now the preferred way to link dynamically against libclang if we build out of tree. + if(NOT PHASAR_IN_TREE) + find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp HINTS ${LLVM_LIBRARY_DIRS}) + if(${CLANG_LIBRARY} STREQUAL "CLANG_LIBRARY-NOTFOUND") + set(NEED_LIBCLANG_COMPONENT_LIBS on) + endif() + endif() + # As fallback, look for the small clang libraries + if(PHASAR_IN_TREE OR NEED_LIBCLANG_COMPONENT_LIBS) + set(CLANG_LIBRARY + clangTooling + clangFrontendTool + clangFrontend + clangDriver + clangSerialization + clangCodeGen + clangParse + clangSema + clangStaticAnalyzerFrontend + clangStaticAnalyzerCheckers + clangStaticAnalyzerCore + clangAnalysis + clangARCMigrate + clangRewrite + clangRewriteFrontend + clangEdit + clangAST + clangASTMatchers + clangLex + clangBasic + LLVMFrontendOpenMP) endif() -endif() -# As fallback, look for the small clang libraries -if(PHASAR_IN_TREE OR NEED_LIBCLANG_COMPONENT_LIBS) - set(CLANG_LIBRARY - clangTooling - clangFrontendTool - clangFrontend - clangDriver - clangSerialization - clangCodeGen - clangParse - clangSema - clangStaticAnalyzerFrontend - clangStaticAnalyzerCheckers - clangStaticAnalyzerCore - clangAnalysis - clangARCMigrate - clangRewrite - clangRewriteFrontend - clangEdit - clangAST - clangASTMatchers - clangLex - clangBasic - LLVMFrontendOpenMP) -endif() -if (NOT PHASAR_IN_TREE) - # Only search for clang if we build out of tree - link_directories(${CLANG_LIB_PATH}) -endif() -if (PHASAR_IN_TREE) - # Phasar needs clang headers, specificaly some that are generated by clangs table-gen - include_directories(SYSTEM - ${CLANG_INCLUDE_DIR} - ${PHASAR_SRC_DIR}/../clang/include - ${PROJECT_BINARY_DIR}/tools/clang/include - ) -endif() + if (PHASAR_IN_TREE) + # Phasar needs clang headers, specificaly some that are generated by clangs table-gen + include_directories(SYSTEM + ${CLANG_INCLUDE_DIR} + ${PHASAR_SRC_DIR}/../clang/include + ${PROJECT_BINARY_DIR}/tools/clang/include + ) + endif() +endif(BUILD_PHASAR_CLANG) # Set up clang-tidy to run during PhASAR's compilation to indicate code smells if (PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD) @@ -302,44 +333,56 @@ if (PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD) ) endif () -# Add PhASAR's subdirectories -add_subdirectory(include) -add_subdirectory(lib) +# Library Dependency Dirs +if(NOT PHASAR_IN_TREE) + include_directories(${LLVM_INCLUDE_DIRS}) + link_directories(${LLVM_LIB_PATH} ${LLVM_LIBRARY_DIRS}) + separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) + add_definitions(${LLVM_DEFINITIONS_LIST}) + if (BUILD_PHASAR_CLANG) + link_directories(${CLANG_LIB_PATH}) + endif() +endif() -set(LLVM_LINK_COMPONENTS - coverage - coroutines - demangle - libdriver - lto - support - analysis - bitwriter - core - ipo - irreader - instcombine - instrumentation - linker - objcarcopts - scalaropts - transformutils - codegen - vectorize -) +# Installed config +configure_file(config.h.in include/phasar/Config/phasar-config.h @ONLY) -llvm_map_components_to_libnames(llvm_libs - ${LLVM_LINK_COMPONENTS} -) +# Warnings +option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON) +if (PHASAR_ENABLE_WARNINGS) + if (MSVC) + string(APPEND CMAKE_CXX_FLAGS " /W4") + else() + string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wno-unused-parameter") + endif() +endif (PHASAR_ENABLE_WARNINGS) + +# Some preprocessor symbols that need to be available in phasar sources, but should not be installed +add_cxx_compile_definitions(PHASAR_SRC_DIR="${CMAKE_SOURCE_DIR}") +add_cxx_compile_definitions(PHASAR_BUILD_DIR="${CMAKE_BINARY_DIR}") + +# Add PhASAR's subdirectories +add_subdirectory(lib) # phasar-based binaries add_subdirectory(tools) +# Swift tests +option(BUILD_SWIFT_TESTS "Builds the Swift tests (Swift compiler has to be installed manually beforehand!)" OFF) +if (BUILD_SWIFT_TESTS) + set(CMAKE_Swift_FLAGS_RELEASE "-g") + set(CMAKE_Swift_FLAGS_RELWITHDEBINFO "-g") + enable_language(Swift) +endif(BUILD_SWIFT_TESTS) + # Add Phasar unittests and build all IR test code if (PHASAR_BUILD_UNITTESTS) message("Phasar unittests") add_subdirectory(unittests) - set(PHASAR_BUILD_IR ON) + if(NOT PHASAR_BUILD_IR) + message(WARNING "Set PHASAR_BUILD_IR=ON, because PHASAR_BUILD_UNITTESTS is ON") + set(PHASAR_BUILD_IR ON) + endif() endif() # Build all IR test code @@ -348,7 +391,8 @@ if (PHASAR_BUILD_IR) add_subdirectory(test) endif() -set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Install dir of headers") +set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Install dir of headers") +set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Install dir of libraries") # Install targets of phasar-cli, other executables, and libraries are to be # found in the individual subdirectories of tools/ @@ -361,6 +405,14 @@ install(DIRECTORY include/ PATTERN "*.h" ) +# Install the config file +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/phasar/Config/ + DESTINATION include/phasar/Config + FILES_MATCHING + PATTERN "*.def" + PATTERN "*.h" +) + # Install the header only json container install(DIRECTORY external/json/single_include/ DESTINATION include @@ -397,21 +449,21 @@ configure_package_config_file( Config.cmake.in phasarConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar - PATH_VARS INCLUDE_INSTALL_DIR - ) + PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR +) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake VERSION 1.0.0 COMPATIBILITY SameMajorVersion - ) +) ### Install Config and ConfigVersion files install( FILES "${CMAKE_CURRENT_BINARY_DIR}/phasarConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar" - ) +) # If the Phasar shared object libraries are not installed into a system folder # the so libs must be added manually to the linker search path and the linker @@ -433,62 +485,44 @@ set(MAJOR_VERSION 1) set(MINOR_VERSION 0) set(PATCH_VERSION 0) if (NOT PHASAR_IN_TREE) -IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") -INCLUDE(InstallRequiredSystemLibraries) -set(CPACK_SET_DESTDIR "on") -set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - -#set(CPACK_GENERATOR "DEB") -set(CPACK_GENERATOR "RPM") -set(CPACK_PACKAGE_DESCRIPTION "Phasar") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Phasar a LLVM-based static analysis framework") -set(CPACK_PACKAGE_VENDOR "Phasar Team - Philipp Schubert and others") -set(CPACK_PACKAGE_CONTACT "philipp.schubert@upb.de") -set(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}") -set(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}") -set(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}") -set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}") -set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}") -# package dependencies can be set-up here -# better use autogenerated dependency information -set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) -# set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost_program_options (>= 1.66.0), -# libboost_graph (>= 1.66.0), -# libboost_thread (>= 1.66.0), -# libsqlite3 (>= 4.5.0), -# libpthread (>= 4.5.0), -# libdl (>= 4.5.0), -# librt (>= 4.5.0), -# libtinfo (>= 4.5.0), -# libz (>= 4.5.0), -# libm (>= 4.5.0), -# libstdc++ (>= 4.5.0), -# libgcc_s (>= 4.5.0), -# libc (>= 4.5.0), -# ld-linux-x86-64 (>= 4.5.0)") -set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") -set(CPACK_DEBIAN_PACKAGE_SECTION "kde") -set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) -set(CPACK_COMPONENTS_ALL Libraries ApplicationData) -INCLUDE(CPack) -ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") + if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") + include(InstallRequiredSystemLibraries) + set(CPACK_SET_DESTDIR "on") + set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + + set(CPACK_GENERATOR "DEB") + set(CPACK_PACKAGE_DESCRIPTION "Phasar") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Phasar a LLVM-based static analysis framework") + set(CPACK_PACKAGE_VENDOR "Phasar Team - Philipp Schubert and others") + set(CPACK_PACKAGE_CONTACT "philipp.schubert@upb.de") + set(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}") + set(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}") + set(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}") + set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}") + set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}") + # package dependencies can be set-up here + # better use autogenerated dependency information + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + set(CPACK_DEBIAN_PACKAGE_SECTION "kde") + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + set(CPACK_COMPONENTS_ALL Libraries ApplicationData) + include(CPack) + endif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") endif() # Setup the doxygen code documentation if(PHASAR_BUILD_DOC) - find_package(Doxygen) - if (DOXYGEN_FOUND) - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - message("Doxygen build started") - add_custom_target(doc_doxygen ALL - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM - ) - else(DOXYGEN_FOUND) - message(FATAL_ERROR "Doxygen need to be installed to generate the doxygen documentation.") - endif() + find_package(Doxygen REQUIRED) + + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + + add_custom_target(doc_doxygen ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM + ) endif() diff --git a/Config.cmake.in b/Config.cmake.in index 78e7bb723..98d5c07c7 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -2,13 +2,19 @@ set(PHASAR_VERSION 1.0.0) @PACKAGE_INIT@ set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(PHASAR_LIBRARY_DIR "@PACKAGE_LIBRARY_INSTALL_DIR@") include (CMakeFindDependencyMacro) find_dependency(nlohmann_json) find_dependency(nlohmann_json_schema_validator) -find_package(Boost 1.65.1 COMPONENTS program_options graph REQUIRED) -# TODO: The order seems to be important. Fix this! +find_package(Boost 1.65.1 COMPONENTS graph REQUIRED) +find_package(LLVM 14 REQUIRED CONFIG) + +set(PHASAR_USE_LLVM_FAT_LIB @USE_LLVM_FAT_LIB@) +set(PHASAR_BUILD_DYNLIB @PHASAR_BUILD_DYNLIB@) + +# TODO: The order seems to be important in the include'ing loop below. Fix this! set(PHASAR_COMPONENTS utils @@ -32,27 +38,32 @@ set(PHASAR_COMPONENTS controller ) +list(REMOVE_DUPLICATES phasar_FIND_COMPONENTS) + +foreach(component ${phasar_FIND_COMPONENTS}) + if(NOT ${component} IN_LIST PHASAR_COMPONENTS) + set(phasar_FOUND false) + set(phasar_NOT_FOUND_MESSAGE "Unsupported component: ${component}. valid components are: ${PHASAR_COMPONENTS}") + endif() +endforeach() + foreach(component ${PHASAR_COMPONENTS}) include("${CMAKE_CURRENT_LIST_DIR}/phasar_${component}-targets.cmake") - list(APPEND PHASAR_NEEDED_LIBS phasar::phasar_${component}) endforeach() +include("${CMAKE_CURRENT_LIST_DIR}/phasar-targets.cmake") -list(REMOVE_DUPLICATES PHASAR_NEEDED_LIBS) +if (NOT phasar_FIND_COMPONENTS) + list(APPEND PHASAR_NEEDED_LIBS phasar::phasar) + set(phasar_FIND_COMPONENTS ${PHASAR_NEEDED_LIBS}) +endif() -find_package(LLVM 14 REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -link_directories(${LLVM_LIB_PATH} ${LLVM_LIBRARY_DIRS}) -find_library(LLVM_LIBRARY NAMES LLVM HINTS ${LLVM_LIBRARY_DIRS}) +foreach(component ${phasar_FIND_COMPONENTS}) + list(APPEND PHASAR_NEEDED_LIBS phasar::phasar_${component}) +endforeach() function(phasar_config executable) - if(NOT ${LLVM_LIBRARY} STREQUAL "LLVM_LIBRARY-NOTFOUND") - llvm_config(${executable} USE_SHARED ${PHASAR_LLVM_DEPS}) - else() - llvm_config(${executable} ${PHASAR_LLVM_DEPS}) - endif() - target_link_libraries(${executable} PUBLIC - ${PHASAR_NEEDED_LIBS} + ${PHASAR_NEEDED_LIBS} ) endfunction() diff --git a/Dockerfile b/Dockerfile index f91375c66..f5893f5a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN apt-get -y install --no-install-recommends \ cmake \ ninja-build \ libstdc++6 \ - libboost-all-dev + libboost-graph-dev COPY ./utils/InstallAptDependencies.sh /usr/src/phasar/utils/ RUN ./utils/InstallAptDependencies.sh @@ -53,6 +53,7 @@ RUN git submodule update RUN mkdir -p build && cd build && \ cmake .. \ -DCMAKE_BUILD_TYPE=Release \ + -DPHASAR_TARGET_ARCH="" \ -DCMAKE_CXX_COMPILER=$CXX \ -G Ninja && \ cmake --build . diff --git a/bootstrap.sh b/bootstrap.sh index 2b5bfe397..9e615a1b3 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -9,12 +9,26 @@ readonly PHASAR_INSTALL_DIR="/usr/local/phasar" readonly LLVM_INSTALL_DIR="/usr/local/llvm-14" NUM_THREADS=$(nproc) -LLVM_RELEASE=llvmorg-14.0.0 +LLVM_RELEASE=llvmorg-14.0.6 DO_UNIT_TEST=true DO_INSTALL=false BUILD_TYPE=Release +function usage { + echo "USAGE: ./bootstrap.sh [options]" + echo "" + echo "OPTIONS:" + echo -e "\t--jobs\t\t-j\t\t- Number of parallel jobs used for compilation (default is nproc -- $(nproc))" + echo -e "\t--unittest\t-u\t\t- Build and run PhASARs unit-tests (default is true)" + echo -e "\t--install\t\t\t- Install PhASAR system-wide after building (default is false)" + echo -e "\t--help\t\t-h\t\t- Display this help message" + echo -e "\t-DBOOST_DIR=\t\t- The directory where boost should be installed (optional)" + echo -e "\t-DBOOST_VERSION=\t- The desired boost version to install (optional)" + echo -e "\t-DCMAKE_BUILD_TYPE=\t- The build mode for building PhASAR. One of {Debug, RelWithDebInfo, Release} (default is Release)" + echo -e "\t-DPHASAR_INSTALL_DIR=\t- The folder where to install PhASAR if --install is specified (default is /usr/local/phasar)" +} + # Parsing command-line-parameters # See "https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash" as a reference @@ -59,6 +73,19 @@ case $key in DO_INSTALL=true shift # past argument ;; + -DPHASAR_INSTALL_DIR) + PHASAR_INSTALL_DIR="$2" + shift # past argument + shift # past value + ;; + -DPHASAR_INSTALL_DIR=*) + PHASAR_INSTALL_DIR="${key#*=}" + shift # past argument=value + ;; + -h|--help) + usage + exit 0 + ;; *) # unknown option POSITIONAL+=("$1") # save it in an array for later shift # past argument @@ -71,14 +98,11 @@ set -- "${POSITIONAL[@]}" # restore positional parameters echo "installing phasar dependencies..." if [ -x "$(command -v pacman)" ]; then - yes | sudo pacman -Syu --needed which zlib sqlite3 ncurses make python3 doxygen libxml2 swig gcc z3 libedit graphviz python-sphinx openmp curl python-pip ninja - ./utils/installBuildEAR.sh + yes | sudo pacman -Syu --needed which zlib sqlite3 python3 doxygen gcc python-pip ninja cmake else ./utils/InstallAptDependencies.sh fi -pip3 install cmake - if [ ! -z "${DESIRED_BOOST_DIR}" ]; then BOOST_PARAMS="-DBOOST_ROOT=${DESIRED_BOOST_DIR}" else @@ -91,10 +115,10 @@ else yes | sudo pacman -Syu --needed boost-libs boost else if [ -z "$DESIRED_BOOST_VERSION" ] ;then - sudo apt install libboost-all-dev -y + sudo apt-get install libboost-graph-dev -y else # DESIRED_BOOST_VERSION in form d.d, i.e. 1.65 (this is the latest version I found in the apt repo) - sudo apt install "libboost${DESIRED_BOOST_VERSION}-all-dev" -y + sudo apt-get install "libboost${DESIRED_BOOST_VERSION}-graph-dev" -y fi #verify installation BOOST_VERSION=$(echo -e '#include \nBOOST_LIB_VERSION' | gcc -s -x c++ -E - 2>/dev/null| grep "^[^#;]" | tr -d '\"') @@ -110,9 +134,7 @@ else if [ -x "$(command -v apt)" ]; then DESIRED_BOOST_VERSION=${BOOST_VERSION//_/.} # install missing packages if necessary - boostlibnames=("libboost-system" "libboost-filesystem" - "libboost-graph" "libboost-program-options" - "libboost-thread") + boostlibnames=("libboost-graph") additional_boost_libs=() for boost_lib in ${boostlibnames[@]}; do dpkg -s "$boost_lib${DESIRED_BOOST_VERSION}" >/dev/null 2>&1 || @@ -123,7 +145,7 @@ else done if [ ${#additional_boost_libs[@]} -gt 0 ] ;then echo "Installing additional ${#additional_boost_libs[@]} boost packages: ${additional_boost_libs[*]}" - sudo apt install "${additional_boost_libs[@]}" -y || true + sudo apt-get install "${additional_boost_libs[@]}" -y || true fi fi fi diff --git a/cmake/phasar_macros.cmake b/cmake/phasar_macros.cmake index db0096471..4e7b2a901 100644 --- a/cmake/phasar_macros.cmake +++ b/cmake/phasar_macros.cmake @@ -1,3 +1,18 @@ + +function(phasar_link_llvm executable) + # llvm_config links LLVM as PRIVATE. We need to link PUBLIC + if (USE_LLVM_FAT_LIB) + target_link_libraries(${executable} PUBLIC LLVM) + else() + llvm_map_components_to_libnames(LLVM_LIBRARIES ${ARGN}) + target_link_libraries(${executable} PUBLIC ${LLVM_LIBRARIES}) + endif() +endfunction() + +macro(add_cxx_compile_definitions) + add_compile_definitions("$<$:${ARGN}>") +endmacro() + function(add_phasar_unittest test_name) message("Set-up unittest: ${test_name}") get_filename_component(test ${test_name} NAME_WE) @@ -6,22 +21,12 @@ function(add_phasar_unittest test_name) ) add_dependencies(PhasarUnitTests ${test}) - if(USE_LLVM_FAT_LIB) - llvm_config(${test} USE_SHARED ${LLVM_LINK_COMPONENTS}) - else() - llvm_config(${test} ${LLVM_LINK_COMPONENTS}) - endif() + phasar_link_llvm(${test} ${LLVM_LINK_COMPONENTS}) target_link_libraries(${test} - LINK_PUBLIC - phasar - nlohmann_json_schema_validator - ${SQLITE3_LIBRARY} - ${Boost_LIBRARIES} - ${CMAKE_DL_LIBS} - ${CMAKE_THREAD_LIBS_INIT} - curl - gtest + PRIVATE + phasar + gtest ) add_test(NAME "${test}" @@ -147,25 +152,31 @@ macro(add_phasar_executable name) ) endmacro(add_phasar_executable) -macro(add_phasar_library name) - set(srcs ${ARGN}) +function(add_phasar_library name) + set(PHASAR_LIB_OPTIONS SHARED STATIC MODULE INTERFACE) + set(PHASAR_LIB_MULTIVAL LLVM_LINK_COMPONENTS LINKS LINK_PUBLIC LINK_PRIVATE FILES) + cmake_parse_arguments(PHASAR_LIB "${PHASAR_LIB_OPTIONS}" "" "${PHASAR_LIB_MULTIVAL}" ${ARGN}) + set(srcs ${PHASAR_LIB_UNPARSED_ARGUMENTS}) + list(APPEND srcs ${PHASAR_LIB_FILES}) if(MSVC_IDE OR XCODE) file(GLOB_RECURSE headers *.h *.td *.def) - set(srcs ${srcs} ${headers}) + list(APPEND srcs ${headers}) string(REGEX MATCHALL "/[^/]" split_path ${CMAKE_CURRENT_SOURCE_DIR}) list(GET split_path -1 dir) file(GLOB_RECURSE headers ../../include/phasar${dir}/*.h) - set(srcs ${srcs} ${headers}) + list(APPEND srcs ${headers}) endif(MSVC_IDE OR XCODE) - if(MODULE) + if(PHASAR_LIB_MODULE) set(libkind MODULE) - elseif(SHARED_LIBRARY) + elseif(PHASAR_LIB_INTERFACE) + set(libkind INTERFACE) + elseif(PHASAR_LIB_SHARED OR BUILD_SHARED_LIBS) set(libkind SHARED) else() - set(libkind) + set(libkind STATIC) endif() add_library(${name} ${libkind} ${srcs}) @@ -175,29 +186,28 @@ macro(add_phasar_library name) add_dependencies(${name} ${LLVM_COMMON_DEPENDS}) endif(LLVM_COMMON_DEPENDS) - if(LLVM_USED_LIBS) - foreach(lib ${LLVM_USED_LIBS}) - target_link_libraries(${name} ${lib}) - endforeach(lib) - endif(LLVM_USED_LIBS) - - if(PHASAR_LINK_LIBS) - foreach(lib ${PHASAR_LINK_LIBS}) - if(PHASAR_DEBUG_LIBDEPS) - target_link_libraries(${name} LINK_PRIVATE ${lib}) - else() - target_link_libraries(${name} LINK_PUBLIC ${lib}) - endif(PHASAR_DEBUG_LIBDEPS) - endforeach(lib) - endif(PHASAR_LINK_LIBS) - - if(LLVM_LINK_COMPONENTS) - if(USE_LLVM_FAT_LIB) - llvm_config(${name} USE_SHARED ${LLVM_LINK_COMPONENTS}) - else() - llvm_config(${name} ${LLVM_LINK_COMPONENTS}) - endif() - endif(LLVM_LINK_COMPONENTS) + if(PHASAR_DEBUG_LIBDEPS) + target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINKS}) + else() + target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINKS}) + endif() + + target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINK_PUBLIC}) + target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINK_PRIVATE}) + + phasar_link_llvm(${name} ${PHASAR_LIB_LLVM_LINK_COMPONENTS}) + + target_include_directories(${name} + PUBLIC + $ # The regular include folder + $ # The location of phasar-config.h + ) + + # Set the target property such that installed PhASAR knows where to find its includes (must be relative paths in this case in contrast to non-installed PhASAR!) + set_property(TARGET ${name} APPEND + PROPERTY INTERFACE_INCLUDE_DIRECTORIES + $ + ) if(MSVC) get_target_property(cflag ${name} COMPILE_FLAGS) @@ -211,7 +221,7 @@ macro(add_phasar_library name) endif(MSVC) # cut off prefix phasar_ for convenient component names - string(REGEX REPLACE phasar_ "" name component_name) + string(REGEX REPLACE phasar_ "" component_name ${name}) if(PHASAR_IN_TREE) install(TARGETS ${name} @@ -238,32 +248,7 @@ macro(add_phasar_library name) endif() set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) -endmacro(add_phasar_library) - -macro(add_phasar_loadable_module name) - set(srcs ${ARGN}) - - # klduge: pass different values for MODULE with multiple targets in same dir - # this allows building shared-lib and module in same dir - # there must be a cleaner way to achieve this.... - if(MODULE) - else() - set(GLOBAL_NOT_MODULE TRUE) - endif() - - set(MODULE TRUE) - add_phasar_library(${name} ${srcs}) - - if(GLOBAL_NOT_MODULE) - unset(MODULE) - endif() - - if(APPLE) - # Darwin-specific linker flags for loadable modules. - set_target_properties(${name} PROPERTIES - LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") - endif() -endmacro(add_phasar_loadable_module) +endfunction(add_phasar_library) macro(subdirlist result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) diff --git a/config.h.in b/config.h.in index ac0e9c09a..d5df1dd0f 100644 --- a/config.h.in +++ b/config.h.in @@ -1,7 +1,11 @@ -#ifndef __CONFIG_H__ -#define __CONFIG_H__ +#ifndef PHASAR_CONFIG_CONFIG_H +#define PHASAR_CONFIG_CONFIG_H -#define PHASAR_SRC_DIR "@CMAKE_SOURCE_DIR@" -#define PHASAR_BUILD_DIR "@CMAKE_BINARY_DIR@" +#define PHASAR_CONFIG_DIR "@PHASAR_CONFIG_INSTALL_DIR@" -#endif /* __CONFIG_H__ */ +#cmakedefine PAMM_CORE +#cmakedefine PAMM_FULL + +#cmakedefine DYNAMIC_LOG + +#endif /* PHASAR_CONFIG_CONFIG_H */ diff --git a/examples/use-phasar-as-library/CMakeLists.txt b/examples/use-phasar-as-library/CMakeLists.txt index bba4e8e6d..de0f50fd1 100644 --- a/examples/use-phasar-as-library/CMakeLists.txt +++ b/examples/use-phasar-as-library/CMakeLists.txt @@ -7,17 +7,24 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +find_package(phasar COMPONENTS llvm_ifdside REQUIRED) + +# Or without specifying components +# find_package(phasar REQUIRED) # Build a small test tool to show how phasar may be used add_executable(myphasartool myphasartool.cpp ) -find_package(phasar COMPONENTS ifdside REQUIRED) -include_directories(${PHASAR_INCLUDE_DIR}) -link_directories(${PHASAR_LIBRARY_DIR}) +# Old way using phasar_config: +# phasar_config(myphasartool) + +# New way using target_link_libraries: +target_link_libraries(myphasartool phasar::phasar_llvm_ifdside) -phasar_config(myphasartool) +# If find_package did not specify components: +# target_link_libraries(myphasartool phasar::phasar) install(TARGETS myphasartool RUNTIME DESTINATION bin diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt deleted file mode 100644 index 0e8996497..000000000 --- a/include/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(phasar) diff --git a/include/phasar/CMakeLists.txt b/include/phasar/CMakeLists.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/phasar/Config/Configuration.h b/include/phasar/Config/Configuration.h index 24db00a2d..86528c338 100644 --- a/include/phasar/Config/Configuration.h +++ b/include/phasar/Config/Configuration.h @@ -28,9 +28,6 @@ #include #include -#define XSTR(S) STR(S) -#define STR(S) #S - namespace psr { class PhasarConfig { diff --git a/include/phasar/ControlFlow/CallGraphBase.h b/include/phasar/ControlFlow/CallGraphBase.h index e2b1e01e5..2f2371618 100644 --- a/include/phasar/ControlFlow/CallGraphBase.h +++ b/include/phasar/ControlFlow/CallGraphBase.h @@ -13,8 +13,6 @@ #include "phasar/Utils/ByRef.h" #include "phasar/Utils/TypeTraits.h" -#include "nlohmann/json.hpp" - namespace psr { template struct CGTraits { // using n_t diff --git a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h index 518d80c7d..4e05c9279 100644 --- a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h +++ b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h @@ -92,7 +92,7 @@ template class InterMonoSolver { void addCalleesToWorklist(std::pair Edge) { auto Src = Edge.first; - auto Dst = Edge.second; + // auto Dst = Edge.second; // Add inter- and intra-edges of callee(s) for (auto Callee : ICF->getCalleesOfCallAt(Src)) { if (AddedFunctions.find(Callee) != AddedFunctions.end()) { @@ -362,7 +362,7 @@ template class InterMonoSolver { std::pair Edge = Worklist.front(); Worklist.pop_front(); auto Src = Edge.first; - auto Dst = Edge.second; + // auto Dst = Edge.second; if (ICF->isCallSite(Src)) { addCalleesToWorklist(Edge); } diff --git a/include/phasar/Utils/Logger.h b/include/phasar/Utils/Logger.h index 7ffdfdc2d..b35b3f806 100644 --- a/include/phasar/Utils/Logger.h +++ b/include/phasar/Utils/Logger.h @@ -10,6 +10,8 @@ #ifndef PHASAR_UTILS_LOGGER_H #define PHASAR_UTILS_LOGGER_H +#include "phasar/Config/phasar-config.h" + #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" // LLVM_UNLIKELY diff --git a/include/phasar/Utils/PAMMMacros.h b/include/phasar/Utils/PAMMMacros.h index f41ef4a0e..cc74e6631 100644 --- a/include/phasar/Utils/PAMMMacros.h +++ b/include/phasar/Utils/PAMMMacros.h @@ -17,6 +17,8 @@ #ifndef PHASAR_UTILS_PAMMMACROS_H_ #define PHASAR_UTILS_PAMMMACROS_H_ +#include "phasar/Config/phasar-config.h" + namespace psr { /// Defines the different level of severity of PAMM's performance evaluation enum class PAMM_SEVERITY_LEVEL { Off = 0, Core, Full }; // NOLINT diff --git a/include/phasar/Utils/Utilities.h b/include/phasar/Utils/Utilities.h index 762735bfe..5bc01ecd2 100644 --- a/include/phasar/Utils/Utilities.h +++ b/include/phasar/Utils/Utilities.h @@ -270,19 +270,21 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, } template -LLVM_ATTRIBUTE_ALWAYS_INLINE void assertNotNull(const T &Value) {} +LLVM_ATTRIBUTE_ALWAYS_INLINE void assertNotNull(const T & /*Value*/) {} template -LLVM_ATTRIBUTE_ALWAYS_INLINE void assertNotNull(const std::optional &Value) { +LLVM_ATTRIBUTE_ALWAYS_INLINE void +assertNotNull([[maybe_unused]] const std::optional &Value) { assert(Value.has_value()); } template -LLVM_ATTRIBUTE_ALWAYS_INLINE void assertNotNull(const T *Value) { +LLVM_ATTRIBUTE_ALWAYS_INLINE void +assertNotNull([[maybe_unused]] const T *Value) { assert(Value != nullptr); } -template void assertAllNotNull(const T &Range) { +template void assertAllNotNull([[maybe_unused]] const T &Range) { assertNotNull(Range); for (const auto &Elem : Range) { assertNotNull(Elem); diff --git a/lib/AnalysisStrategy/CMakeLists.txt b/lib/AnalysisStrategy/CMakeLists.txt index 3b205207d..5bb3d4446 100644 --- a/lib/AnalysisStrategy/CMakeLists.txt +++ b/lib/AnalysisStrategy/CMakeLists.txt @@ -1,28 +1,7 @@ file(GLOB_RECURSE ANALYSIS_STRATEGY_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_db - phasar_controlflow -) - -set(LLVM_LINK_COMPONENTS - Support -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_analysis_strategy - SHARED - ${ANALYSIS_STRATEGY_SRC} - ) -else() - add_phasar_library(phasar_analysis_strategy - STATIC - ${ANALYSIS_STRATEGY_SRC} - ) -endif() - -set_target_properties(phasar_analysis_strategy - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +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 2045abbfe..cbcfbaa01 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,58 +1,56 @@ add_subdirectory(AnalysisStrategy) add_subdirectory(PhasarLLVM) add_subdirectory(PhasarPass) -add_subdirectory(PhasarClang) add_subdirectory(DB) add_subdirectory(Config) add_subdirectory(Utils) add_subdirectory(Controller) add_subdirectory(Pointer) add_subdirectory(ControlFlow) - -set(PHASAR_LINK_LIBS - 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 - ${Boost_LIBRARIES} -) - -set(LLVM_LINK_COMPONENTS - Core - Support - BitWriter - Analysis - Passes - Demangle -) +if(BUILD_PHASAR_CLANG) + add_subdirectory(PhasarClang) +endif() # The fat lib relies on transitive dependencies... set(PHASAR_DEBUG_LIBDEPS_SAVE ${PHASAR_DEBUG_LIBDEPS}) set(PHASAR_DEBUG_LIBDEPS OFF) -if(BUILD_SHARED_LIBS OR PHASAR_BUILD_DYNLIB) - add_phasar_library(phasar SHARED - LibPhasar.cpp - ) -else() - add_phasar_library(phasar STATIC - LibPhasar.cpp - ) +if(PHASAR_BUILD_DYNLIB) + set(PHASAR_DYNLIB_KIND SHARED) 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 + LINK_PRIVATE + ${Boost_LIBRARIES} + LLVM_LINK_COMPONENTS + Core + Support + BitWriter + Analysis + Passes + Demangle +) + set(PHASAR_DEBUG_LIBDEPS ${PHASAR_DEBUG_LIBDEPS_SAVE}) diff --git a/lib/Config/CMakeLists.txt b/lib/Config/CMakeLists.txt index 10ae4447d..455fa8fbf 100644 --- a/lib/Config/CMakeLists.txt +++ b/lib/Config/CMakeLists.txt @@ -1,32 +1,8 @@ file(GLOB_RECURSE CONFIG_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils -) - -set(LLVM_LINK_COMPONENTS - Support -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_config - SHARED - ${CONFIG_SRC} - ) -else() - add_phasar_library(phasar_config - STATIC - ${CONFIG_SRC} - ) -endif() - -target_link_libraries(phasar_config - LINK_PUBLIC - ${Boost_LIBRARIES} -) - -set_target_properties(phasar_config - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +add_phasar_library(phasar_config + ${CONFIG_SRC} + LINKS phasar_utils + LINK_PRIVATE ${Boost_LIBRARIES} + LLVM_LINK_COMPONENTS Support ) diff --git a/lib/Config/Configuration.cpp b/lib/Config/Configuration.cpp index 5ad3665c1..8e9708f94 100644 --- a/lib/Config/Configuration.cpp +++ b/lib/Config/Configuration.cpp @@ -16,6 +16,7 @@ #include "phasar/Config/Configuration.h" +#include "phasar/Config/phasar-config.h" #include "phasar/Utils/ErrorHandling.h" #include "phasar/Utils/IO.h" #include "phasar/Utils/Logger.h" @@ -32,6 +33,9 @@ #include #include +#define XSTR(S) STR(S) +#define STR(S) #S + using namespace psr; namespace psr { @@ -43,10 +47,12 @@ llvm::StringRef PhasarConfig::GlobalConfigurationDirectory() noexcept { return PHASAR_CONFIG_DIR; } -llvm::StringRef PhasarConfig::PhasarDirectory() noexcept { return PHASAR_DIR; } +llvm::StringRef PhasarConfig::PhasarDirectory() noexcept { + return PHASAR_SRC_DIR; +} llvm::StringRef PhasarConfig::DefaultSourceSinkFunctionsPath() noexcept { - return PHASAR_DIR "/config/phasar-source-sink-function.json"; + return PHASAR_SRC_DIR "/config/phasar-source-sink-function.json"; } PhasarConfig::PhasarConfig() { diff --git a/lib/ControlFlow/CMakeLists.txt b/lib/ControlFlow/CMakeLists.txt index b757c3d62..39084cd11 100644 --- a/lib/ControlFlow/CMakeLists.txt +++ b/lib/ControlFlow/CMakeLists.txt @@ -1,26 +1,7 @@ file(GLOB_RECURSE CONTROLFLOW_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS -) - -set(LLVM_LINK_COMPONENTS - Support -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_controlflow - SHARED - ${CONTROLFLOW_SRC} - ) -else() - add_phasar_library(phasar_controlflow - STATIC - ${CONTROLFLOW_SRC} - ) -endif() - -set_target_properties(phasar_controlflow - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +add_phasar_library(phasar_controlflow + ${CONTROLFLOW_SRC} + LLVM_LINK_COMPONENTS Support + LINK_PRIVATE nlohmann_json::nlohmann_json ) diff --git a/lib/Controller/CMakeLists.txt b/lib/Controller/CMakeLists.txt index 8b3df9478..dba171b58 100644 --- a/lib/Controller/CMakeLists.txt +++ b/lib/Controller/CMakeLists.txt @@ -1,45 +1,26 @@ file(GLOB_RECURSE CONTROLLER_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_llvm_ifdside - phasar_mono - phasar_llvm_db - phasar_llvm_pointer - phasar_llvm_typehierarchy - phasar_llvm_controlflow - phasar_llvm_utils - phasar_utils - phasar_analysis_strategy - phasar_taintconfig -) - -set(LLVM_LINK_COMPONENTS - Core - Support - Demangle -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_controller - SHARED +add_phasar_library(phasar_controller + FILES ${CONTROLLER_SRC} - ) -else() - add_phasar_library(phasar_controller - STATIC - ${CONTROLLER_SRC} - ) -endif() -target_link_libraries(phasar_controller - LINK_PUBLIC - curl - ${CMAKE_THREAD_LIBS_INIT} - ${PHASAR_STD_FILESYSTEM} -) + LINKS + phasar_llvm_ifdside + phasar_mono + phasar_llvm_db + phasar_llvm_pointer + phasar_llvm_typehierarchy + phasar_llvm_controlflow + phasar_llvm_utils + phasar_utils + phasar_analysis_strategy + phasar_taintconfig + + LLVM_LINK_COMPONENTS + Core + Support + Demangle -set_target_properties(phasar_controller - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LINK_PRIVATE + ${PHASAR_STD_FILESYSTEM} ) diff --git a/lib/DB/CMakeLists.txt b/lib/DB/CMakeLists.txt index 4579879ce..d5dbf67e1 100644 --- a/lib/DB/CMakeLists.txt +++ b/lib/DB/CMakeLists.txt @@ -1,37 +1,12 @@ file(GLOB_RECURSE DB_SRC *.h *.cpp) -include_directories( - ${SQLITE3_INCLUDE_DIR} +add_phasar_library(phasar_db + ${DB_SRC} + LINKS phasar_passes phasar_utils + LLVM_LINK_COMPONENTS Support + LINK_PRIVATE ${SQLITE3_LIBRARY} ) -set(PHASAR_LINK_LIBS - phasar_passes - phasar_utils -) - -set(LLVM_LINK_COMPONENTS - Support -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_db - SHARED - ${DB_SRC} - ) -else() - add_phasar_library(phasar_db - STATIC - ${DB_SRC} - ) -endif() - -target_link_libraries(phasar_db - LINK_PUBLIC - ${SQLITE3_LIBRARY} -) - -set_target_properties(phasar_db - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +target_include_directories(phasar_db + PRIVATE ${SQLITE3_INCLUDE_DIR} ) diff --git a/lib/PhasarClang/CMakeLists.txt b/lib/PhasarClang/CMakeLists.txt index cd6955610..961953ae2 100644 --- a/lib/PhasarClang/CMakeLists.txt +++ b/lib/PhasarClang/CMakeLists.txt @@ -1,37 +1,28 @@ file(GLOB_RECURSE PHASARCLANG_SRC *.h *.cpp) -include_directories(${CLANG_INCLUDE_DIRS}) -set(PHASAR_LINK_LIBS - phasar_utils - phasar_taintconfig -) -set(LLVM_LINK_COMPONENTS - Support - Core - Option -) +add_phasar_library(phasar_clang + ${PHASARCLANG_SRC} + LINKS + phasar_utils + phasar_taintconfig -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_clang - SHARED - ${PHASARCLANG_SRC} - ) -else() - add_phasar_library(phasar_clang - STATIC - ${PHASARCLANG_SRC} - ) -endif() + LLVM_LINK_COMPONENTS + Support + Core + Option -target_link_libraries(phasar_clang LINK_PUBLIC - ${CLANG_LIBRARY} + ${CLANG_LIBRARY} ) -set_target_properties(phasar_clang - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +target_include_directories(phasar_clang + PUBLIC ${CLANG_INCLUDE_DIRS} ) + +if(PHASAR_IN_TREE) + # Some phasar-clang headers depend on generated files e.g files included from clang/AST/ASTFwd.h + # Make sure, phasar-clang is built *after* these files have been generated + add_dependencies(phasar_clang intrinsics_gen) +endif() diff --git a/lib/PhasarLLVM/CMakeLists.txt b/lib/PhasarLLVM/CMakeLists.txt index 7d446b251..be4adc5e0 100644 --- a/lib/PhasarLLVM/CMakeLists.txt +++ b/lib/PhasarLLVM/CMakeLists.txt @@ -9,26 +9,17 @@ add_subdirectory(Utils) file(GLOB PHASAR_LLVM_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS +add_phasar_library(phasar_llvm + ${PHASAR_LLVM_SRC} + + LINKS + phasar_utils phasar_llvm_pointer phasar_llvm_db phasar_llvm_controlflow phasar_llvm_typehierarchy -) -set(LLVM_LINK_COMPONENTS - Core - Support + LLVM_LINK_COMPONENTS + Core + Support ) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm - SHARED - ${PHASAR_LLVM_SRC} - ) -else() - add_phasar_library(phasar_llvm - STATIC - ${PHASAR_LLVM_SRC} - ) -endif() diff --git a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt index 3f93e7e90..162f9a6cf 100644 --- a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt +++ b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt @@ -1,33 +1,17 @@ file(GLOB_RECURSE CONTROLFLOW_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_llvm_pointer - phasar_llvm_typehierarchy - phasar_db - phasar_utils - phasar_controlflow -) - -set(LLVM_LINK_COMPONENTS - Core - Support - Demangle -) +add_phasar_library(phasar_llvm_controlflow + ${CONTROLFLOW_SRC} -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_controlflow - SHARED - ${CONTROLFLOW_SRC} - ) -else() - add_phasar_library(phasar_llvm_controlflow - STATIC - ${CONTROLFLOW_SRC} - ) -endif() + LINKS + phasar_llvm_pointer + phasar_llvm_typehierarchy + phasar_db + phasar_utils + phasar_controlflow -set_target_properties(phasar_llvm_controlflow - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LLVM_LINK_COMPONENTS + Core + Support + Demangle ) diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp index b1e99e85d..8fd7621bf 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp @@ -94,7 +94,7 @@ 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 llvm::Value *Receiver = CallSite->getArgOperand(0); if (CallSite->getCalledOperand() && CallSite->getCalledOperand()->getType()->isPointerTy()) { diff --git a/lib/PhasarLLVM/DB/CMakeLists.txt b/lib/PhasarLLVM/DB/CMakeLists.txt index cda931d3f..5c89b3aa6 100644 --- a/lib/PhasarLLVM/DB/CMakeLists.txt +++ b/lib/PhasarLLVM/DB/CMakeLists.txt @@ -1,31 +1,15 @@ file(GLOB_RECURSE PSR_LLVM_DB_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_db - phasar_utils - phasar_llvm_utils -) - -set(LLVM_LINK_COMPONENTS - Core - Support - IRReader -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_db - SHARED - ${PSR_LLVM_DB_SRC} - ) -else() - add_phasar_library(phasar_llvm_db - STATIC - ${PSR_LLVM_DB_SRC} - ) -endif() - -set_target_properties(phasar_llvm_db - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +add_phasar_library(phasar_llvm_db + ${PSR_LLVM_DB_SRC} + + LINKS + phasar_db + phasar_utils + phasar_llvm_utils + + LLVM_LINK_COMPONENTS + Core + Support + IRReader ) diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt index 7ab2b533a..9411bc739 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt @@ -1,38 +1,24 @@ file(GLOB_RECURSE IFDSIDE_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_config - phasar_utils - phasar_llvm_pointer - phasar_llvm - phasar_llvm_typehierarchy - phasar_llvm_controlflow - phasar_llvm_utils - phasar_db - phasar_taintconfig - ${Boost_LIBRARIES} -) +add_phasar_library(phasar_llvm_ifdside + ${IFDSIDE_SRC} -set(LLVM_LINK_COMPONENTS - Core - Support - Demangle -) + LINKS + phasar_config + phasar_utils + phasar_llvm_pointer + phasar_llvm + phasar_llvm_typehierarchy + phasar_llvm_controlflow + phasar_llvm_utils + phasar_db + phasar_taintconfig -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_ifdside - SHARED - ${IFDSIDE_SRC} - ) -else() - add_phasar_library(phasar_llvm_ifdside - STATIC - ${IFDSIDE_SRC} - ) -endif() + LLVM_LINK_COMPONENTS + Core + Support + Demangle -set_target_properties(phasar_llvm_ifdside - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LINK_PRIVATE + ${Boost_LIBRARIES} ) diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/IFDSFieldSensTaintAnalysis/FlowFunctions/BranchSwitchInstFlowFunction.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/IFDSFieldSensTaintAnalysis/FlowFunctions/BranchSwitchInstFlowFunction.cpp index fa57a4022..0a2f03623 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/IFDSFieldSensTaintAnalysis/FlowFunctions/BranchSwitchInstFlowFunction.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/IFDSFieldSensTaintAnalysis/FlowFunctions/BranchSwitchInstFlowFunction.cpp @@ -36,7 +36,7 @@ BranchSwitchInstFlowFunction::computeTargetsExt(ExtendedValue &Fact) { if (IsConditionTainted) { const auto *const StartBasicBlock = CurrentInst->getParent(); - const auto StartBasicBlockLabel = StartBasicBlock->getName(); + // const auto StartBasicBlockLabel = StartBasicBlock->getName(); LOG_DEBUG("Searching end of block label for: " << StartBasicBlockLabel); diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp index d3a11d09c..ef6999038 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/ExtendedTaintAnalysis/AbstractMemoryLocationFactory.cpp @@ -354,8 +354,9 @@ AbstractMemoryLocationFactoryBase::withOffsetsImpl( AML->offsets().end()); OffsCpy.back() += Offs.front(); +#ifdef XTAINT_DIAGNOSTICS bool IsOverApproximating = false; - +#endif if (NwLifetime < Offs.size() - 1) { Offs = Offs.slice(0, NwLifetime + 1); } diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysis.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysis.cpp index 02c08a309..d3dd8fd76 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEExtendedTaintAnalysis.cpp @@ -695,7 +695,7 @@ auto IDEExtendedTaintAnalysis::getSummaryEdgeFunction(n_t Curr, d_t CurrNode, d_t SuccNode) -> EdgeFunctionType { - const auto *Call = llvm::cast(Curr); + // const auto *Call = llvm::cast(Curr); if (isZeroValue(CurrNode) && !isZeroValue(SuccNode)) { return GenEdgeFunction{nullptr}; diff --git a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt index 9c11f2066..7c7d00bf9 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt @@ -1,33 +1,17 @@ file(GLOB_RECURSE MONO_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_config - phasar_utils - phasar_llvm_utils - phasar_llvm_controlflow - phasar_db - phasar_taintconfig -) - -set(LLVM_LINK_COMPONENTS - Core - Support -) +add_phasar_library(phasar_mono + ${MONO_SRC} -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_mono - SHARED - ${MONO_SRC} - ) -else() - add_phasar_library(phasar_mono - STATIC - ${MONO_SRC} - ) -endif() + LINKS + phasar_config + phasar_utils + phasar_llvm_utils + phasar_llvm_controlflow + phasar_db + phasar_taintconfig -set_target_properties(phasar_mono - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LLVM_LINK_COMPONENTS + Core + Support ) diff --git a/lib/PhasarLLVM/Passes/CMakeLists.txt b/lib/PhasarLLVM/Passes/CMakeLists.txt index f40831353..10c71117e 100644 --- a/lib/PhasarLLVM/Passes/CMakeLists.txt +++ b/lib/PhasarLLVM/Passes/CMakeLists.txt @@ -1,34 +1,14 @@ file(GLOB_RECURSE PASSES_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils -) - -set(LLVM_LINK_COMPONENTS - Core - Support - Analysis - Demangle -) +add_phasar_library(phasar_passes + ${PASSES_SRC} -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_passes - SHARED - ${PASSES_SRC} - ) -else() - add_phasar_library(phasar_passes - STATIC - ${PASSES_SRC} - ) -endif() - -target_link_libraries(phasar_passes - LINK_PUBLIC -) + LINKS + phasar_utils -set_target_properties(phasar_passes - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LLVM_LINK_COMPONENTS + Core + Support + Analysis + Demangle ) diff --git a/lib/PhasarLLVM/Pointer/CMakeLists.txt b/lib/PhasarLLVM/Pointer/CMakeLists.txt index b01e8274d..c189f6153 100644 --- a/lib/PhasarLLVM/Pointer/CMakeLists.txt +++ b/lib/PhasarLLVM/Pointer/CMakeLists.txt @@ -1,42 +1,22 @@ file(GLOB_RECURSE POINTER_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils - phasar_db - phasar_pointer - phasar_llvm_utils - phasar_llvm_db -) - -set(LLVM_LINK_COMPONENTS - Core - Support - Analysis - Passes - Demangle -) +add_phasar_library(phasar_llvm_pointer + ${POINTER_SRC} -# Handle the library files -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_pointer - SHARED - ${POINTER_SRC} - ) -else() - add_phasar_library(phasar_llvm_pointer - STATIC - ${POINTER_SRC} - ) -endif() + LINKS + phasar_utils + phasar_db + phasar_pointer + phasar_llvm_utils + phasar_llvm_db -find_package(Boost COMPONENTS graph REQUIRED) -target_link_libraries(phasar_llvm_pointer - LINK_PUBLIC - ${Boost_LIBRARIES} -) + LLVM_LINK_COMPONENTS + Core + Support + Analysis + Passes + Demangle -set_target_properties(phasar_llvm_pointer - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LINK_PRIVATE + ${Boost_LIBRARIES} ) diff --git a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt index 81d9ad6a8..1a801938f 100644 --- a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt +++ b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt @@ -1,38 +1,19 @@ file(GLOB_RECURSE TAINTCONFIG_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils - phasar_db - phasar_llvm_db - phasar_llvm_utils - phasar_controlflow - phasar_llvm_controlflow -) - -set(LLVM_LINK_COMPONENTS - Core - Support -) +add_phasar_library(phasar_taintconfig + ${TAINTCONFIG_SRC} -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_taintconfig - SHARED - ${TAINTCONFIG_SRC} - ) -else() - add_phasar_library(phasar_taintconfig - STATIC - ${TAINTCONFIG_SRC} - ) -endif() + LINKS + phasar_utils + phasar_db + phasar_llvm_db + phasar_llvm_utils + phasar_controlflow + phasar_llvm_controlflow -target_link_libraries(phasar_taintconfig - LINK_PUBLIC - nlohmann_json_schema_validator -) + nlohmann_json_schema_validator -set_target_properties(phasar_taintconfig - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LLVM_LINK_COMPONENTS + Core + Support ) diff --git a/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt b/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt index 1094db186..3c3d86078 100644 --- a/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt +++ b/lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt @@ -1,37 +1,18 @@ file(GLOB_RECURSE TYPEHIERARCHY_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils -) - -set(LLVM_LINK_COMPONENTS - Core - Demangle - Support - Analysis -) - # Handle the library files -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_typehierarchy - SHARED - ${TYPEHIERARCHY_SRC} - ) -else() - add_phasar_library(phasar_llvm_typehierarchy - STATIC - ${TYPEHIERARCHY_SRC} - ) -endif() +add_phasar_library(phasar_llvm_typehierarchy + ${TYPEHIERARCHY_SRC} -find_package(Boost COMPONENTS graph REQUIRED) -target_link_libraries(phasar_llvm_typehierarchy - LINK_PUBLIC - ${Boost_LIBRARIES} -) + LINKS + phasar_utils + + LLVM_LINK_COMPONENTS + Core + Demangle + Support + Analysis -set_target_properties(phasar_llvm_typehierarchy - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LINK_PRIVATE + ${Boost_LIBRARIES} ) diff --git a/lib/PhasarLLVM/Utils/CMakeLists.txt b/lib/PhasarLLVM/Utils/CMakeLists.txt index 6c05a4112..b88ee9d75 100644 --- a/lib/PhasarLLVM/Utils/CMakeLists.txt +++ b/lib/PhasarLLVM/Utils/CMakeLists.txt @@ -1,36 +1,15 @@ file(GLOB_RECURSE UTILS_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_config - phasar_utils -) - -set(LLVM_LINK_COMPONENTS - Core - Support - BitWriter - Demangle -) - -# Handle the library files -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_llvm_utils - SHARED - ${UTILS_SRC} - ) -else() - add_phasar_library(phasar_llvm_utils - STATIC - ${UTILS_SRC} - ) -endif() - -target_link_libraries(phasar_llvm_utils - LINK_PUBLIC -) - -set_target_properties(phasar_llvm_utils - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" +add_phasar_library(phasar_llvm_utils + ${UTILS_SRC} + + LINKS + phasar_config + phasar_utils + + LLVM_LINK_COMPONENTS + Core + Support + BitWriter + Demangle ) diff --git a/lib/PhasarPass/CMakeLists.txt b/lib/PhasarPass/CMakeLists.txt index cec9dc7b5..dd4dff3cb 100644 --- a/lib/PhasarPass/CMakeLists.txt +++ b/lib/PhasarPass/CMakeLists.txt @@ -1,48 +1,28 @@ file(GLOB_RECURSE PHASARPASS_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_config - phasar_llvm_controlflow - phasar_llvm_db - phasar_llvm_ifdside - phasar_mono - phasar_passes - phasar_llvm_utils - phasar_llvm_pointer - phasar_llvm_typehierarchy - phasar_utils -) +# We specifically link internal phasar libs into phasar_pass so on that the +# llvm user side only has to specify one library. -set(LLVM_LINK_COMPONENTS - Core - Support -) +add_phasar_library(phasar_pass + ${PHASARPASS_SRC} -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_pass - SHARED - ${PHASARPASS_SRC} - ) -else() - add_phasar_library(phasar_pass - STATIC - ${PHASARPASS_SRC} - ) -endif() + LINKS + phasar_config + phasar_llvm_controlflow + phasar_llvm_db + phasar_llvm_ifdside + phasar_mono + phasar_passes + phasar_llvm_utils + phasar_llvm_pointer + phasar_llvm_typehierarchy + phasar_utils -# We specifically link internal phasar libs into phasar_pass so on that the -# llvm user side only has to specify one library. + LLVM_LINK_COMPONENTS + Core + Support -find_package(Boost COMPONENTS graph REQUIRED) -target_link_libraries(phasar_pass LINK_PUBLIC - ${CMAKE_THREAD_LIBS_INIT} - ${PHASAR_LINK_LIBS} - ${Boost_LIBRARIES} -) - -set_target_properties(phasar_pass - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + ${CMAKE_THREAD_LIBS_INIT} + ${Boost_LIBRARIES} ) diff --git a/lib/PhasarPass/PhasarPass.cpp b/lib/PhasarPass/PhasarPass.cpp index dc90da2f9..d16a1fb78 100644 --- a/lib/PhasarPass/PhasarPass.cpp +++ b/lib/PhasarPass/PhasarPass.cpp @@ -64,7 +64,7 @@ bool PhasarPass::runOnModule(llvm::Module &M) { CallGraphAnalysisType CGTy = toCallGraphAnalysisType(CallGraphAnalysis); LLVMTypeHierarchy H(DB); LLVMAliasSet PT(&DB); - LLVMBasedCFG CFG; + // LLVMBasedCFG CFG; LLVMBasedICFG I(&DB, CGTy, EntryPoints, &H, &PT); if (DataFlowAnalysis == "ifds-solvertest") { IFDSSolverTest IFDSTest(&DB, EntryPoints); diff --git a/lib/Pointer/CMakeLists.txt b/lib/Pointer/CMakeLists.txt index 791168961..5c2f8d43e 100644 --- a/lib/Pointer/CMakeLists.txt +++ b/lib/Pointer/CMakeLists.txt @@ -1,29 +1,13 @@ file(GLOB_RECURSE POINTER_SRC *.h *.cpp) -set(PHASAR_LINK_LIBS - phasar_utils - phasar_db -) - -set(LLVM_LINK_COMPONENTS - Support -) - # Handle the library files -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_pointer - SHARED - ${POINTER_SRC} - ) -else() - add_phasar_library(phasar_pointer - STATIC - ${POINTER_SRC} - ) -endif() +add_phasar_library(phasar_pointer + ${POINTER_SRC} + + LINKS + phasar_utils + phasar_db -set_target_properties(phasar_pointer - PROPERTIES - LINKER_LANGUAGE CXX - PREFIX "lib" + LLVM_LINK_COMPONENTS + Support ) diff --git a/lib/Pointer/PointsToInfo.cpp b/lib/Pointer/PointsToInfo.cpp index 3f7678e0b..b690be3c0 100644 --- a/lib/Pointer/PointsToInfo.cpp +++ b/lib/Pointer/PointsToInfo.cpp @@ -137,12 +137,14 @@ class DummyFieldSensitivePointsToAnalysis [[maybe_unused]] void testTypeErasure() { DummyFieldInsensitivePointsToAnalysis PTA1; - PointsToInfoRef> + [[maybe_unused]] PointsToInfoRef< + PointsToTraits> TEPTA1 = &PTA1; DummyFieldSensitivePointsToAnalysis PTA2; - PointsToInfoRef> TEPTA2 = - &PTA2; + [[maybe_unused]] PointsToInfoRef< + PointsToTraits> + TEPTA2 = &PTA2; PointsToInfo> TEPTA3( std::in_place_type); diff --git a/lib/Utils/CMakeLists.txt b/lib/Utils/CMakeLists.txt index e8d429fc8..c10569663 100644 --- a/lib/Utils/CMakeLists.txt +++ b/lib/Utils/CMakeLists.txt @@ -6,35 +6,19 @@ if(PHASAR_ENABLE_PAMM STREQUAL "Off" AND NOT PHASAR_BUILD_UNITTESTS) list(REMOVE_ITEM UTILS_SRC ${pamm_src}) endif() -set(PHASAR_LINK_LIBS -) - -set(LLVM_LINK_COMPONENTS - Core - Support - BitWriter - Demangle -) - -if(BUILD_SHARED_LIBS) - add_phasar_library(phasar_utils - SHARED - ${UTILS_SRC} - ) -else() - add_phasar_library(phasar_utils - STATIC - ${UTILS_SRC} - ) -endif() +add_phasar_library(phasar_utils + ${UTILS_SRC} -target_include_directories(phasar_utils PUBLIC ${LLVM_INCLUDE_DIRS}) + LLVM_LINK_COMPONENTS + Core + Support + BitWriter + Demangle -target_link_libraries(phasar_utils + LINK_PRIVATE + ${PHASAR_STD_FILESYSTEM} LINK_PUBLIC - ${CMAKE_DL_LIBS} - ${Boost_LIBRARIES} - ${PHASAR_STD_FILESYSTEM} + nlohmann_json::nlohmann_json ) set_target_properties(phasar_utils diff --git a/tools/example-tool/CMakeLists.txt b/tools/example-tool/CMakeLists.txt index aab2a9a7d..e4d397e70 100644 --- a/tools/example-tool/CMakeLists.txt +++ b/tools/example-tool/CMakeLists.txt @@ -12,14 +12,11 @@ else() endif() target_link_libraries(myphasartool - LINK_PUBLIC - phasar - LINK_PRIVATE - ${PHASAR_STD_FILESYSTEM} + PRIVATE + phasar + ${PHASAR_STD_FILESYSTEM} ) install(TARGETS myphasartool RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib ) diff --git a/tools/phasar-cli/CMakeLists.txt b/tools/phasar-cli/CMakeLists.txt index f696adea4..a20a7d6a8 100644 --- a/tools/phasar-cli/CMakeLists.txt +++ b/tools/phasar-cli/CMakeLists.txt @@ -23,26 +23,22 @@ endif() # Warning! There is a another listing of libraries inside cmake/phasar_macros.cmake. # If this list is altered the other one should be altered accordingly. target_link_libraries(phasar-cli - LINK_PUBLIC - phasar_config - phasar_controller - phasar_llvm_controlflow - phasar_llvm_utils - phasar_analysis_strategy - phasar_llvm_ifdside - phasar_utils - phasar_mono - phasar_llvm_db - phasar_passes - phasar_llvm_pointer - phasar_llvm - phasar_llvm_typehierarchy - ${SQLITE3_LIBRARY} - ${Boost_LIBRARIES} - ${CMAKE_DL_LIBS} - ${CMAKE_THREAD_LIBS_INIT} - LINK_PRIVATE - ${PHASAR_STD_FILESYSTEM} + PRIVATE + phasar_config + phasar_controller + phasar_llvm_controlflow + phasar_llvm_utils + phasar_analysis_strategy + phasar_llvm_ifdside + phasar_utils + phasar_mono + phasar_llvm_db + phasar_passes + phasar_llvm_pointer + phasar_llvm + phasar_llvm_typehierarchy + + ${PHASAR_STD_FILESYSTEM} ) if (NOT PHASAR_IN_TREE) diff --git a/tools/phasar-cli/phasar-cli.cpp b/tools/phasar-cli/phasar-cli.cpp index ef221b8cd..c9c20f629 100644 --- a/tools/phasar-cli/phasar-cli.cpp +++ b/tools/phasar-cli/phasar-cli.cpp @@ -366,7 +366,7 @@ int main(int Argc, const char **Argv) { validateParamAnalysisConfig(); validatePTAJsonFile(); - auto &PConfig = PhasarConfig::getPhasarConfig(); + [[maybe_unused]] auto &PConfig = PhasarConfig::getPhasarConfig(); // setup the emitter options to display the computed analysis results auto EmitterOptions = AnalysisControllerEmitterOptions::None; diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index b30f77c73..931faf8a9 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -23,6 +23,8 @@ endfunction() include_directories(TestUtils) add_subdirectory(DB) -add_subdirectory(PhasarClang) add_subdirectory(PhasarLLVM) add_subdirectory(Utils) +if(BUILD_PHASAR_CLANG) + add_subdirectory(PhasarClang) +endif() diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/CMakeLists.txt b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/CMakeLists.txt index 23d61519b..708ce3bcb 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/CMakeLists.txt +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/CMakeLists.txt @@ -1,33 +1,4 @@ -if(PHASAR_BUILD_OPENSSL_TS_UNITTESTS) - set(IfdsIdeProblemSources - IFDSConstAnalysisTest.cpp - IFDSTaintAnalysisTest.cpp - IDEInstInteractionAnalysisTest.cpp - IDELinearConstantAnalysisTest.cpp - IDELinearConstantAnalysis_DotTest.cpp - IDETSAnalysisFileIOTest.cpp - IDETSAnalysisOpenSSLEVPKDFTest.cpp - IDETSAnalysisOpenSSLSecureHeapTest.cpp - IDETSAnalysisOpenSSLSecureMemoryTest.cpp - IFDSUninitializedVariablesTest.cpp - IDEExtendedTaintAnalysisTest.cpp - IDEGeneralizedLCATest.cpp - ) -elseif(BUILD_SWIFT_TESTS) - set(IfdsIdeProblemSources - IFDSConstAnalysisTest.cpp - IFDSTaintAnalysisTest.cpp - IDEInstInteractionAnalysisTest.cpp - IDELinearConstantAnalysisTest.cpp - IDELinearConstantAnalysis_DotTest.cpp - IFDSUninitializedVariablesTest.cpp - IDEGeneralizedLCATest.cpp - IDEExtendedTaintAnalysisTest.cpp - IDETSAnalysisFileIOTest.cpp - IDELinearConstantAnalysisSwiftTest.cpp - ) - else() - set(IfdsIdeProblemSources +set(IfdsIdeProblemSources IFDSConstAnalysisTest.cpp IFDSTaintAnalysisTest.cpp IDEInstInteractionAnalysisTest.cpp @@ -37,8 +8,21 @@ elseif(BUILD_SWIFT_TESTS) IDEGeneralizedLCATest.cpp IDEExtendedTaintAnalysisTest.cpp IDETSAnalysisFileIOTest.cpp - ) -endif(PHASAR_BUILD_OPENSSL_TS_UNITTESTS) +) + +if(PHASAR_BUILD_OPENSSL_TS_UNITTESTS) + list(APPEND IfdsIdeProblemSources + IDETSAnalysisOpenSSLEVPKDFTest.cpp + IDETSAnalysisOpenSSLSecureHeapTest.cpp + IDETSAnalysisOpenSSLSecureMemoryTest.cpp + ) +endif() + +if(BUILD_SWIFT_TESTS) + list(APPEND IfdsIdeProblemSources + IDELinearConstantAnalysisSwiftTest.cpp + ) +endif() test_require_config_file("DOTGraphConfig.json") diff --git a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp index 61a7912d4..8f14daced 100644 --- a/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp +++ b/unittests/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp @@ -9,7 +9,6 @@ #include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h" #include "TestConfig.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" #include diff --git a/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp b/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp index 3cac284a2..b6144d68b 100644 --- a/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp +++ b/unittests/PhasarLLVM/Pointer/LLVMAliasSetTest.cpp @@ -21,7 +21,7 @@ TEST(LLVMAliasSet, Intra_01) { const auto *Main = IRDB.getFunctionDefinition("main"); for (const auto &BB : *Main) { for (const auto &I : BB) { - auto S = PTS.getAliasSet(&I); // NOLINT + std::ignore = PTS.getAliasSet(&I); // NOLINT } } PTS.print(llvm::outs()); @@ -37,7 +37,7 @@ TEST(LLVMAliasSet, Inter_01) { const auto *Main = IRDB.getFunctionDefinition("main"); for (const auto &BB : *Main) { for (const auto &I : BB) { - auto S = PTS.getAliasSet(&I); // NOLINT + std::ignore = PTS.getAliasSet(&I); // NOLINT } } PTS.print(llvm::outs()); @@ -53,11 +53,11 @@ TEST(LLVMAliasSet, Global_01) { LLVMBasedICFG ICF(&IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PTS); const auto *Main = IRDB.getFunctionDefinition("main"); for (const auto &G : Main->getParent()->globals()) { - auto S = PTS.getAliasSet(&G); // NOLINT + std::ignore = PTS.getAliasSet(&G); // NOLINT } for (const auto &BB : *Main) { for (const auto &I : BB) { - auto S = PTS.getAliasSet(&I); // NOLINT + std::ignore = PTS.getAliasSet(&I); // NOLINT } } PTS.print(llvm::outs()); diff --git a/unittests/TestUtils/TestConfig.h b/unittests/TestUtils/TestConfig.h index a58bc45ae..e162b619b 100644 --- a/unittests/TestUtils/TestConfig.h +++ b/unittests/TestUtils/TestConfig.h @@ -1,7 +1,9 @@ #ifndef UNITTEST_TESTUTILS_TESTCONFIG_H_ #define UNITTEST_TESTUTILS_TESTCONFIG_H_ -#include "phasar/Config/Configuration.h" +#include "phasar/Config/phasar-config.h" + +#include "llvm/ADT/StringRef.h" #include "gtest/gtest.h" @@ -10,19 +12,19 @@ namespace psr::unittest { static constexpr llvm::StringLiteral PathToLLTestFiles = - PHASAR_DIR "/build/test/llvm_test_code/"; + PHASAR_BUILD_DIR "/test/llvm_test_code/"; static constexpr llvm::StringLiteral PathToTxtTestFiles = - PHASAR_DIR "/build/test/text_test_code/"; + PHASAR_BUILD_DIR "/test/text_test_code/"; static constexpr llvm::StringLiteral PathToJSONTestFiles = - PHASAR_DIR "/test/json_test_code/"; + PHASAR_SRC_DIR "/test/json_test_code/"; #define PHASAR_BUILD_SWIFT_SUBFOLDER(SUB) \ - llvm::StringLiteral(PHASAR_DIR "/build/test/llvm_swift_test_code/" SUB) + llvm::StringLiteral(PHASAR_BUILD_DIR "/test/llvm_swift_test_code/" SUB) #define PHASAR_BUILD_SUBFOLDER(SUB) \ - llvm::StringLiteral(PHASAR_DIR "/build/test/llvm_test_code/" SUB) + llvm::StringLiteral(PHASAR_BUILD_DIR "/test/llvm_test_code/" SUB) // Remove wrapped tests in case GTEST_SKIP is not available. This is needed as // LLVM currently ships with an older version of gtest (<1.10.0) that does not diff --git a/unittests/Utils/EquivalenceClassMapTest.cpp b/unittests/Utils/EquivalenceClassMapTest.cpp index c712615ad..04c641324 100644 --- a/unittests/Utils/EquivalenceClassMapTest.cpp +++ b/unittests/Utils/EquivalenceClassMapTest.cpp @@ -59,7 +59,7 @@ TEST(EquivalenceClassMap, insertKeyRef) { int Key = 42; const MapTy::key_type &KeyRef = Key; - M.insert(42, "foo"); + M.insert(KeyRef, "foo"); EXPECT_EQ(M.findValue(42), "foo"); } diff --git a/utils/InstallAptDependencies.sh b/utils/InstallAptDependencies.sh index 496c879f4..37bc530c6 100755 --- a/utils/InstallAptDependencies.sh +++ b/utils/InstallAptDependencies.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -sudo apt update -sudo apt install git -y -sudo apt install zlib1g-dev sqlite3 libsqlite3-dev bear python3 doxygen graphviz python3-pip libxml2 libxml2-dev libncurses5-dev libncursesw5-dev swig build-essential g++ libz3-dev libedit-dev python3-sphinx libomp-dev libcurl4-openssl-dev ninja-build -y +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 diff --git a/utils/install-llvm.sh b/utils/install-llvm.sh index 943b3c211..aff717a8b 100755 --- a/utils/install-llvm.sh +++ b/utils/install-llvm.sh @@ -15,7 +15,7 @@ readonly dest_dir="${3}" readonly llvm_release="${4}" if [ "$#" -ne 4 ] || ! [[ "$num_cores" =~ ${re_number} ]] || ! [ -d "${build_dir}" ] || ! [[ "${llvm_release}" =~ ${re_llvm_release} ]]; then - echo "usage: <# cores> " >&2 + echo "usage: <# cores> " >&2 exit 1 fi @@ -50,7 +50,7 @@ safe_cd "${build_dir}"/llvm-project/ git checkout "${llvm_release}" mkdir -p build safe_cd build -cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;libcxx;libcxxabi;libunwind;lld;compiler-rt' -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_ENABLE_DUMP=ON -DLLVM_BUILD_EXAMPLES=Off -DLLVM_INCLUDE_EXAMPLES=Off -DLLVM_BUILD_TESTS=Off -DLLVM_INCLUDE_TESTS=Off -DPYTHON_EXECUTABLE="$(which python3)" ../llvm +cmake -G "Ninja" -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind' -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld;compiler-rt' -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_ENABLE_DUMP=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF ../llvm cmake --build . echo "Installing LLVM to ${dest_dir}"