Skip to content

Commit

Permalink
Fix DebugLibDeps (#699)
Browse files Browse the repository at this point in the history
* Fix the option PHASAR_DEBUG_LIBDEPS to show unresolved functions in libraries

* Silencing some warnings

* Enable DEBUG_LIBDEPS for libphasar as well + don't include PhasarClang if BUILD_PHASAR_CLANG is OFF

* Get rid of "extra semicolon" warning due to empty FRIEND_TEST macro

* minor

* Workaround incompatibility of DEBUG_LIBDEPS and ASAN

* Update checkout version in CI to avoid deprecation warning

* revert the swap

---------

Co-authored-by: Martin Mory <[email protected]>
  • Loading branch information
fabianbs96 and MMory authored Feb 29, 2024
1 parent 1d1be21 commit fec44a5
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 151 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
- build: Debug
flags: -DPHASAR_BUILD_DYNLIB=ON -DPHASAR_ENABLE_SANITIZERS=ON
- build: Release
flags: -DPHASAR_ENABLE_DYNAMIC_LOG=OFF
flags: -DPHASAR_ENABLE_DYNAMIC_LOG=OFF -DPHASAR_DEBUG_LIBDEPS=ON -DBUILD_SHARED_LIBS=ON

continue-on-error: false
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
Expand Down Expand Up @@ -64,7 +64,6 @@ jobs:
cmake .. \
-DCMAKE_BUILD_TYPE=${{ matrix.build }} \
-DBUILD_SWIFT_TESTS=ON \
-DPHASAR_DEBUG_LIBDEPS=ON \
-DPHASAR_USE_Z3=ON \
${{ matrix.flags }} \
-G Ninja
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,23 @@ option(PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD "Run clang-tidy during build (defau

option(PHASAR_BUILD_DOC "Build documentation" OFF)

option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)

#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)

if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS")
endif()

option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
if (PHASAR_DEBUG_LIBDEPS)
if (NOT BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
message("PHASAR_DEBUG_LIBDEPS only works for shared libraries, so set BUILD_SHARED_LIBS=ON")
endif()
if (PHASAR_ENABLE_SANITIZERS)
message(FATAL_ERROR "PHASAR_DEBUG_LIBDEPS is incompatible with ASAN (see https://clang.llvm.org/docs/AddressSanitizer.html#usage)")
endif()
endif ()

option(PHASAR_ENABLE_PIC "Build Position-Independed Code" ON)
if (PHASAR_ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down
6 changes: 2 additions & 4 deletions cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ function(add_phasar_library name)
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
endif(LLVM_COMMON_DEPENDS)

target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINKS} phasar_interface ${PHASAR_LIB_LINK_PUBLIC})
if(PHASAR_DEBUG_LIBDEPS)
target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINKS})
else()
target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINKS})
target_link_libraries(${name} PRIVATE -Wl,-z,defs)
endif()

target_link_libraries(${name} PUBLIC phasar_interface ${PHASAR_LIB_LINK_PUBLIC})
target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINK_PRIVATE})

phasar_link_llvm(${name} ${PHASAR_LIB_LLVM_LINK_COMPONENTS})
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
#cmakedefine PAMM_FULL

#cmakedefine DYNAMIC_LOG
#cmakedefine BUILD_PHASAR_CLANG

#endif /* PHASAR_CONFIG_CONFIG_H */
5 changes: 4 additions & 1 deletion include/phasar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
#include "phasar/DB.h"
#include "phasar/DataFlow.h"
#include "phasar/Domain.h"
#include "phasar/PhasarClang.h"
#include "phasar/PhasarLLVM.h"
#include "phasar/PhasarPass.h"
#include "phasar/Pointer.h"
#include "phasar/TypeHierarchy.h"
#include "phasar/Utils.h"

#ifdef BUILD_PHASAR_CLANG
#include "phasar/PhasarClang.h"
#endif

#endif // PHASAR_H
2 changes: 1 addition & 1 deletion include/phasar/DataFlow/IfdsIde/FlowFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Container makeContainer(Range &&Rng) {
}
return C;
}
};
}
} // namespace detail

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions include/phasar/DataFlow/IfdsIde/IDETabulationProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct HasNoConfigurationType;

template <typename AnalysisDomainTy, typename = void> class AllTopFnProvider {
public:
virtual ~AllTopFnProvider() = default;
/// Returns an edge function that represents the top element of the analysis.
virtual EdgeFunction<typename AnalysisDomainTy::l_t> allTopFunction() = 0;
};
Expand All @@ -49,6 +50,7 @@ class AllTopFnProvider<
AnalysisDomainTy,
std::enable_if_t<HasJoinLatticeTraits<typename AnalysisDomainTy::l_t>>> {
public:
virtual ~AllTopFnProvider() = default;
/// Returns an edge function that represents the top element of the analysis.
virtual EdgeFunction<typename AnalysisDomainTy::l_t> allTopFunction() {
return AllTop<typename AnalysisDomainTy::l_t>{};
Expand Down
9 changes: 6 additions & 3 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"

#include "nlohmann/json.hpp"

namespace llvm {
class Function;
} // namespace llvm
Expand All @@ -28,6 +26,9 @@ namespace psr {
class LLVMBasedCFG;
class LLVMBasedBackwardCFG;

// Forward-declaration to avoid including LLVMShorthands.h here
bool isHeapAllocatingFunction(const llvm::Function *F) noexcept;

template <> struct CFGTraits<LLVMBasedCFG> {
using n_t = const llvm::Instruction *;
using f_t = const llvm::Function *;
Expand Down Expand Up @@ -78,7 +79,9 @@ template <typename Derived> class LLVMBasedCFGImpl : public CFGBase<Derived> {
[[nodiscard]] bool isFallThroughSuccessorImpl(n_t Inst,
n_t Succ) const noexcept;
[[nodiscard]] bool isBranchTargetImpl(n_t Inst, n_t Succ) const noexcept;
[[nodiscard]] bool isHeapAllocatingFunctionImpl(f_t Fun) const;
[[nodiscard]] bool isHeapAllocatingFunctionImpl(f_t Fun) const {
return psr::isHeapAllocatingFunction(Fun);
}
[[nodiscard]] bool isSpecialMemberFunctionImpl(f_t Fun) const {
return this->getSpecialMemberFunctionType(Fun) !=
SpecialMemberFunctionType{};
Expand Down
3 changes: 0 additions & 3 deletions include/phasar/PhasarLLVM/Pointer/LLVMPointsToUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOUTILS_H_
#define PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOUTILS_H_

#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Value.h"

Expand All @@ -29,8 +28,6 @@ namespace psr {
!llvm::isa<llvm::ConstantPointerNull>(V);
}

[[nodiscard]] bool isHeapAllocatingFunction(const llvm::Function *Fun);

} // namespace psr

#endif
18 changes: 9 additions & 9 deletions include/phasar/PhasarLLVM/Pointer/TypeGraphs/CachedTypeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <string>
#include <unordered_map>

#ifndef FRIEND_TEST
#define FRIEND_TEST(TEST, CLASS)
#ifndef PSR_FRIEND_TEST
#define PSR_FRIEND_TEST(TEST, CLASS)
#endif

namespace llvm {
Expand Down Expand Up @@ -75,13 +75,13 @@ class CachedTypeGraph : public TypeGraph<CachedTypeGraph> {
graph_t G;
bool AlreadyVisited = false;

FRIEND_TEST(TypeGraphTest, AddType);
FRIEND_TEST(TypeGraphTest, AddLinkSimple);
FRIEND_TEST(TypeGraphTest, AddLinkWithSubs);
FRIEND_TEST(TypeGraphTest, AddLinkWithRecursion);
FRIEND_TEST(TypeGraphTest, ReverseTypePropagation);
FRIEND_TEST(TypeGraphTest, TypeAggregation);
FRIEND_TEST(TypeGraphTest, Merging);
PSR_FRIEND_TEST(TypeGraphTest, AddType)
PSR_FRIEND_TEST(TypeGraphTest, AddLinkSimple)
PSR_FRIEND_TEST(TypeGraphTest, AddLinkWithSubs)
PSR_FRIEND_TEST(TypeGraphTest, AddLinkWithRecursion)
PSR_FRIEND_TEST(TypeGraphTest, ReverseTypePropagation)
PSR_FRIEND_TEST(TypeGraphTest, TypeAggregation)
PSR_FRIEND_TEST(TypeGraphTest, Merging)

vertex_t addType(const llvm::StructType *NewType);
void reverseTypePropagation(const llvm::StructType *BaseStruct);
Expand Down
8 changes: 0 additions & 8 deletions include/phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/graph_traits.hpp"
#include "nlohmann/json.hpp"

#include <optional>
#include <set>
Expand All @@ -33,10 +32,6 @@
#include <unordered_set>
#include <vector>

#ifndef FRIEND_TEST
#define FRIEND_TEST(TEST, CLASS)
#endif

namespace llvm {
class Module;
class StructType;
Expand Down Expand Up @@ -135,9 +130,6 @@ class LLVMTypeHierarchy
std::vector<const llvm::Function *>
getVirtualFunctions(const llvm::Module &M, const llvm::StructType &Type);

FRIEND_TEST(LTHTest, GraphConstruction);
FRIEND_TEST(LTHTest, HandleLoadAndPrintOfNonEmptyGraph);

protected:
void buildLLVMTypeHierarchy(const llvm::Module &M);

Expand Down
1 change: 1 addition & 0 deletions include/phasar/PhasarLLVM/Utils/LLVMShorthands.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool isIntegerLikeType(const llvm::Type *T) noexcept;
* heap allocation function, e.g. new, new[], malloc, realloc or calloc.
*/
bool isAllocaInstOrHeapAllocaFunction(const llvm::Value *V) noexcept;
bool isHeapAllocatingFunction(const llvm::Function *F) noexcept;

// TODO add description
bool matchesSignature(const llvm::Function *F, const llvm::FunctionType *FType,
Expand Down
9 changes: 3 additions & 6 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ add_subdirectory(Controller)
add_subdirectory(Pointer)
add_subdirectory(ControlFlow)
if(BUILD_PHASAR_CLANG)
if(PHASAR_IN_TREE)
add_dependencies(phasar_interface intrinsics_gen)
endif()
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(PHASAR_BUILD_DYNLIB)
set(PHASAR_DYNLIB_KIND SHARED)
endif()
Expand Down Expand Up @@ -52,5 +51,3 @@ add_phasar_library(phasar ${PHASAR_DYNLIB_KIND}
Passes
Demangle
)

set(PHASAR_DEBUG_LIBDEPS ${PHASAR_DEBUG_LIBDEPS_SAVE})
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/ControlFlow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ add_phasar_library(phasar_llvm_controlflow
LINKS
phasar_llvm_pointer
phasar_llvm_typehierarchy
phasar_llvm_utils
phasar_db
phasar_utils
phasar_controlflow

LLVM_LINK_COMPONENTS
Expand Down
8 changes: 0 additions & 8 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ bool detail::LLVMBasedCFGImpl<Derived>::isBranchTargetImpl(
return false;
}

template <typename Derived>
bool detail::LLVMBasedCFGImpl<Derived>::isHeapAllocatingFunctionImpl(
f_t Fun) const {
return llvm::StringSwitch<bool>(Fun->getName())
.Cases("_Znwm", "_Znam", "malloc", "calloc", "realloc", true)
.Default(false);
}

template <typename Derived>
SpecialMemberFunctionType
detail::LLVMBasedCFGImpl<Derived>::getSpecialMemberFunctionTypeImpl(
Expand Down
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_phasar_library(phasar_passes
${PASSES_SRC}

LINKS
phasar_utils
phasar_llvm_utils

LLVM_LINK_COMPONENTS
Core
Expand Down
4 changes: 1 addition & 3 deletions lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h"

#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/NlohmannLogging.h"
Expand Down Expand Up @@ -68,7 +67,6 @@ static void collectAllocatedTypes(const llvm::CallBase *CallSite, Set &Into) {
llvm::AnalysisKey GeneralStatisticsAnalysis::Key; // NOLINT
GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
PHASAR_LOG_LEVEL(INFO, "Running GeneralStatisticsAnalysis");
LLVMBasedCFG CFG;
Stats.ModuleName = M.getName().str();
for (auto &F : M) {
++Stats.Functions;
Expand Down Expand Up @@ -182,7 +180,7 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
++Stats.NumInlineAsm;
} else if (const auto *CalleeFun =
llvm::dyn_cast<llvm::Function>(CalledOp)) {
if (CFG.isHeapAllocatingFunction(CalleeFun)) {
if (isHeapAllocatingFunction(CalleeFun)) {
// do not add allocas from llvm internal functions
Stats.AllocaInstructions.insert(&I);
++Stats.AllocationSites;
Expand Down
20 changes: 0 additions & 20 deletions lib/PhasarLLVM/Pointer/LLVMPointsToUtils.cpp

This file was deleted.

Loading

0 comments on commit fec44a5

Please sign in to comment.