Skip to content

Commit fec44a5

Browse files
fabianbs96MMory
andauthored
Fix DebugLibDeps (#699)
* 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 <mmo@mail.upb.de>
1 parent 1d1be21 commit fec44a5

21 files changed

Lines changed: 102 additions & 151 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
- build: Debug
1919
flags: -DPHASAR_BUILD_DYNLIB=ON -DPHASAR_ENABLE_SANITIZERS=ON
2020
- build: Release
21-
flags: -DPHASAR_ENABLE_DYNAMIC_LOG=OFF
21+
flags: -DPHASAR_ENABLE_DYNAMIC_LOG=OFF -DPHASAR_DEBUG_LIBDEPS=ON -DBUILD_SHARED_LIBS=ON
2222

2323
continue-on-error: false
2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
2727
with:
2828
fetch-depth: 0
2929
submodules: recursive
@@ -64,7 +64,6 @@ jobs:
6464
cmake .. \
6565
-DCMAKE_BUILD_TYPE=${{ matrix.build }} \
6666
-DBUILD_SWIFT_TESTS=ON \
67-
-DPHASAR_DEBUG_LIBDEPS=ON \
6867
-DPHASAR_USE_Z3=ON \
6968
${{ matrix.flags }} \
7069
-G Ninja

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,23 @@ option(PHASAR_ENABLE_CLANG_TIDY_DURING_BUILD "Run clang-tidy during build (defau
158158

159159
option(PHASAR_BUILD_DOC "Build documentation" OFF)
160160

161-
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
162-
163-
#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
164161
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)
165162

166163
if(PHASAR_BUILD_DYNLIB AND BUILD_SHARED_LIBS)
167164
message(FATAL_ERROR "PHASAR_BUILD_DYNLIB is incompatible with BUILD_SHARED_LIBS")
168165
endif()
169166

167+
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
168+
if (PHASAR_DEBUG_LIBDEPS)
169+
if (NOT BUILD_SHARED_LIBS)
170+
set(BUILD_SHARED_LIBS ON)
171+
message("PHASAR_DEBUG_LIBDEPS only works for shared libraries, so set BUILD_SHARED_LIBS=ON")
172+
endif()
173+
if (PHASAR_ENABLE_SANITIZERS)
174+
message(FATAL_ERROR "PHASAR_DEBUG_LIBDEPS is incompatible with ASAN (see https://clang.llvm.org/docs/AddressSanitizer.html#usage)")
175+
endif()
176+
endif ()
177+
170178
option(PHASAR_ENABLE_PIC "Build Position-Independed Code" ON)
171179
if (PHASAR_ENABLE_PIC)
172180
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

cmake/phasar_macros.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,11 @@ function(add_phasar_library name)
192192
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
193193
endif(LLVM_COMMON_DEPENDS)
194194

195+
target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINKS} phasar_interface ${PHASAR_LIB_LINK_PUBLIC})
195196
if(PHASAR_DEBUG_LIBDEPS)
196-
target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINKS})
197-
else()
198-
target_link_libraries(${name} PUBLIC ${PHASAR_LIB_LINKS})
197+
target_link_libraries(${name} PRIVATE -Wl,-z,defs)
199198
endif()
200199

201-
target_link_libraries(${name} PUBLIC phasar_interface ${PHASAR_LIB_LINK_PUBLIC})
202200
target_link_libraries(${name} PRIVATE ${PHASAR_LIB_LINK_PRIVATE})
203201

204202
phasar_link_llvm(${name} ${PHASAR_LIB_LLVM_LINK_COMPONENTS})

config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
#cmakedefine PAMM_FULL
88

99
#cmakedefine DYNAMIC_LOG
10+
#cmakedefine BUILD_PHASAR_CLANG
1011

1112
#endif /* PHASAR_CONFIG_CONFIG_H */

include/phasar.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#include "phasar/DB.h"
1818
#include "phasar/DataFlow.h"
1919
#include "phasar/Domain.h"
20-
#include "phasar/PhasarClang.h"
2120
#include "phasar/PhasarLLVM.h"
2221
#include "phasar/PhasarPass.h"
2322
#include "phasar/Pointer.h"
2423
#include "phasar/TypeHierarchy.h"
2524
#include "phasar/Utils.h"
2625

26+
#ifdef BUILD_PHASAR_CLANG
27+
#include "phasar/PhasarClang.h"
28+
#endif
29+
2730
#endif // PHASAR_H

include/phasar/DataFlow/IfdsIde/FlowFunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Container makeContainer(Range &&Rng) {
135135
}
136136
return C;
137137
}
138-
};
138+
}
139139
} // namespace detail
140140

141141
//===----------------------------------------------------------------------===//

include/phasar/DataFlow/IfdsIde/IDETabulationProblem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct HasNoConfigurationType;
4040

4141
template <typename AnalysisDomainTy, typename = void> class AllTopFnProvider {
4242
public:
43+
virtual ~AllTopFnProvider() = default;
4344
/// Returns an edge function that represents the top element of the analysis.
4445
virtual EdgeFunction<typename AnalysisDomainTy::l_t> allTopFunction() = 0;
4546
};
@@ -49,6 +50,7 @@ class AllTopFnProvider<
4950
AnalysisDomainTy,
5051
std::enable_if_t<HasJoinLatticeTraits<typename AnalysisDomainTy::l_t>>> {
5152
public:
53+
virtual ~AllTopFnProvider() = default;
5254
/// Returns an edge function that represents the top element of the analysis.
5355
virtual EdgeFunction<typename AnalysisDomainTy::l_t> allTopFunction() {
5456
return AllTop<typename AnalysisDomainTy::l_t>{};

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "llvm/IR/InstrTypes.h"
1919
#include "llvm/IR/Instructions.h"
2020

21-
#include "nlohmann/json.hpp"
22-
2321
namespace llvm {
2422
class Function;
2523
} // namespace llvm
@@ -28,6 +26,9 @@ namespace psr {
2826
class LLVMBasedCFG;
2927
class LLVMBasedBackwardCFG;
3028

29+
// Forward-declaration to avoid including LLVMShorthands.h here
30+
bool isHeapAllocatingFunction(const llvm::Function *F) noexcept;
31+
3132
template <> struct CFGTraits<LLVMBasedCFG> {
3233
using n_t = const llvm::Instruction *;
3334
using f_t = const llvm::Function *;
@@ -78,7 +79,9 @@ template <typename Derived> class LLVMBasedCFGImpl : public CFGBase<Derived> {
7879
[[nodiscard]] bool isFallThroughSuccessorImpl(n_t Inst,
7980
n_t Succ) const noexcept;
8081
[[nodiscard]] bool isBranchTargetImpl(n_t Inst, n_t Succ) const noexcept;
81-
[[nodiscard]] bool isHeapAllocatingFunctionImpl(f_t Fun) const;
82+
[[nodiscard]] bool isHeapAllocatingFunctionImpl(f_t Fun) const {
83+
return psr::isHeapAllocatingFunction(Fun);
84+
}
8285
[[nodiscard]] bool isSpecialMemberFunctionImpl(f_t Fun) const {
8386
return this->getSpecialMemberFunctionType(Fun) !=
8487
SpecialMemberFunctionType{};

include/phasar/PhasarLLVM/Pointer/LLVMPointsToUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#ifndef PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOUTILS_H_
1111
#define PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOUTILS_H_
1212

13-
#include "llvm/ADT/StringRef.h"
1413
#include "llvm/IR/Constants.h"
1514
#include "llvm/IR/Value.h"
1615

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

32-
[[nodiscard]] bool isHeapAllocatingFunction(const llvm::Function *Fun);
33-
3431
} // namespace psr
3532

3633
#endif

include/phasar/PhasarLLVM/Pointer/TypeGraphs/CachedTypeGraph.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <string>
2828
#include <unordered_map>
2929

30-
#ifndef FRIEND_TEST
31-
#define FRIEND_TEST(TEST, CLASS)
30+
#ifndef PSR_FRIEND_TEST
31+
#define PSR_FRIEND_TEST(TEST, CLASS)
3232
#endif
3333

3434
namespace llvm {
@@ -75,13 +75,13 @@ class CachedTypeGraph : public TypeGraph<CachedTypeGraph> {
7575
graph_t G;
7676
bool AlreadyVisited = false;
7777

78-
FRIEND_TEST(TypeGraphTest, AddType);
79-
FRIEND_TEST(TypeGraphTest, AddLinkSimple);
80-
FRIEND_TEST(TypeGraphTest, AddLinkWithSubs);
81-
FRIEND_TEST(TypeGraphTest, AddLinkWithRecursion);
82-
FRIEND_TEST(TypeGraphTest, ReverseTypePropagation);
83-
FRIEND_TEST(TypeGraphTest, TypeAggregation);
84-
FRIEND_TEST(TypeGraphTest, Merging);
78+
PSR_FRIEND_TEST(TypeGraphTest, AddType)
79+
PSR_FRIEND_TEST(TypeGraphTest, AddLinkSimple)
80+
PSR_FRIEND_TEST(TypeGraphTest, AddLinkWithSubs)
81+
PSR_FRIEND_TEST(TypeGraphTest, AddLinkWithRecursion)
82+
PSR_FRIEND_TEST(TypeGraphTest, ReverseTypePropagation)
83+
PSR_FRIEND_TEST(TypeGraphTest, TypeAggregation)
84+
PSR_FRIEND_TEST(TypeGraphTest, Merging)
8585

8686
vertex_t addType(const llvm::StructType *NewType);
8787
void reverseTypePropagation(const llvm::StructType *BaseStruct);

0 commit comments

Comments
 (0)