Skip to content

Commit 5549802

Browse files
committed
hp77 | Add options to include build without libbpf and fix errors
1 parent b4e37a2 commit 5549802

File tree

14 files changed

+101
-33
lines changed

14 files changed

+101
-33
lines changed

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
109109
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
110110
endif()
111111

112-
include(cmake/libbpf.cmake)
113-
112+
if(${BPFTIME_BUILD_WITH_LIBBPF})
113+
include(cmake/libbpf.cmake)
114+
endif()
114115
# install frida
115116
include(cmake/frida.cmake)
116117

@@ -196,4 +197,8 @@ add_subdirectory(benchmark)
196197

197198
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
198199

199-
install(TARGETS bpftime-agent bpftime_text_segment_transformer bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ~/.bpftime)
200+
if(${BPFTIME_BUILD_WITH_LIBBPF})
201+
install(TARGETS bpftime-agent bpftime_text_segment_transformer bpftime-syscall-server CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ~/.bpftime)
202+
else()
203+
install(TARGETS bpftime-agent CONFIGURATIONS Release Debug RelWithDebInfo DESTINATION ~/.bpftime)
204+
endif()

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ build-iouring: ## build the package with iouring extension
5454
cmake -Bbuild -DBPFTIME_ENABLE_IOURING_EXT=1 -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
5555
cmake --build build --config RelWithDebInfo -j$(JOBS)
5656

57+
build-wo-libbpf: ## build the package with iouring extension
58+
cmake -Bbuild -DBPFTIME_ENABLE_IOURING_EXT=1 -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DBPFTIME_BUILD_WITH_LIBBPF=OFF
59+
cmake --build build --config RelWithDebInfo -j$(JOBS)
60+
5761
release: ## build the release version
5862
cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo \
5963
-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO

attach/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
55
endif()
66
add_subdirectory(base_attach_impl)
77
add_subdirectory(frida_uprobe_attach_impl)
8-
add_subdirectory(syscall_trace_attach_impl)
9-
add_subdirectory(text_segment_transformer)
8+
if(${BPFTIME_BUILD_WITH_LIBBPF})
9+
add_subdirectory(syscall_trace_attach_impl)
10+
add_subdirectory(text_segment_transformer)
11+
endif()

attach/frida_uprobe_attach_impl/src/frida_attach_utils.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33
#include <filesystem>
44
#include <spdlog/spdlog.h>
55
#include <frida-gum.h>
6+
#include <unistd.h>
7+
#if __APPLE__
8+
#include <libproc.h>
9+
#endif
610
static std::string get_executable_path()
711
{
812
char exec_path[PATH_MAX] = { 0 };
9-
ssize_t len =
10-
readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
11-
if (len != -1) {
12-
exec_path[len] = '\0'; // Null-terminate the string
13-
SPDLOG_INFO("Executable path: {}", exec_path);
14-
} else {
15-
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
16-
}
13+
14+
#if __linux__
15+
ssize_t len =
16+
readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
17+
if (len != -1) {
18+
exec_path[len] = '\0'; // Null-terminate the string
19+
SPDLOG_INFO("Executable path: {}", exec_path);
20+
} else {
21+
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
22+
}
23+
#elif __APPLE__
24+
pid_t pid = getpid();
25+
if (proc_pidpath(pid, exec_path, sizeof(exec_path)) > 0) {
26+
SPDLOG_INFO("Executable path: {}", exec_path);
27+
} else {
28+
SPDLOG_ERROR("Error retrieving executable path: {}", errno);
29+
}
30+
#endif
1731
return exec_path;
1832
}
1933
namespace bpftime

attach/syscall_trace_attach_impl/src/syscall_trace_attach_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ int64_t syscall_trace_attach_impl::dispatch_syscall(int64_t sys_nr,
1616
int64_t arg3, int64_t arg4,
1717
int64_t arg5, int64_t arg6)
1818
{
19+
#if __linux__
1920
if (sys_nr == __NR_exit_group || sys_nr == __NR_exit)
2021
return orig_syscall(sys_nr, arg1, arg2, arg3, arg4, arg5, arg6);
22+
#endif
2123
SPDLOG_DEBUG("Syscall callback {} {} {} {} {} {} {}", sys_nr, arg1,
2224
arg2, arg3, arg4, arg5, arg6);
2325
// Indicate whether the return value is overridden

attach/text_segment_transformer/agent-transformer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ extern "C" void bpftime_agent_main(const gchar *data, gboolean *stay_resident)
7373
cs_arch_register_x86();
7474
bpftime::setup_syscall_tracer();
7575
SPDLOG_DEBUG("Loading dynamic library..");
76-
auto next_handle =
76+
#if __linux__
77+
auto next_handle =
7778
dlmopen(LM_ID_NEWLM, agent_so, RTLD_NOW | RTLD_LOCAL);
79+
#elif __APPLE__
80+
auto next_handle = dlopen(agent_so, RTLD_NOW | RTLD_LOCAL);
81+
#endif
7882
if (next_handle == nullptr) {
7983
SPDLOG_ERROR("Failed to open agent: {}", dlerror());
8084
exit(1);

benchmark/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
add_executable(simple-benchmark-with-embed-ebpf-calling test_embed.c)
22

3-
add_dependencies(simple-benchmark-with-embed-ebpf-calling bpftime_vm libbpf)
3+
if(${BPFTIME_BUILD_WITH_LIBBPF})
4+
add_dependencies(simple-benchmark-with-embed-ebpf-calling bpftime_vm libbpf)
5+
else()
6+
add_dependencies(simple-benchmark-with-embed-ebpf-calling bpftime_vm)
7+
endif()
48
target_compile_definitions(simple-benchmark-with-embed-ebpf-calling
59
PRIVATE
610
)

cmake/StandardSettings.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ option(BUILD_BPFTIME_DAEMON "Whether to build the bpftime daemon" ON)
8484
option(BPFTIME_BUILD_KERNEL_BPF "Whether to build with bpf share maps" ON)
8585

8686
# whether to build single static library
87-
option(BPFTIME_BUILD_STATIC_LIB "Whether to build a single static library for different archive files" OFF)
87+
option(BPFTIME_BUILD_STATIC_LIB "Whether to build a single static library for different archive files" OFF)
88+
89+
# whether to build bpftime with libbpf and other linux headers
90+
option(BPFTIME_BUILD_WITH_LIBBPF "Whether to build with libbpf and other linux headers" ON)

cmake/frida.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ elseif(${FRIDA_OS_ARCH} MATCHES "linux-arm.*")
2727
# Frida only has armhf builds..
2828
set(FRIDA_OS_ARCH "linux-armhf")
2929
elseif(${FRIDA_OS_ARCH} MATCHES "darwin-arm.*")
30-
set(FRIDA_CORE_DEVKIT_SHA256 "50aea2d5dfff000ed1f1dc1fdb2db67a02e4c4f44e782fa311f8afa31df327b6")
31-
set(FRIDA_GUM_DEVKIT_SHA256 "b40c08bebd6958d41d91b7819171a457448cccad5faf417c9b4901be54b6c633")
30+
set(FRIDA_CORE_DEVKIT_SHA256 "7811e516e6b7bbc0153d30095560e0b1133f154060c5542764100d3e0eb2ab2b")
31+
set(FRIDA_GUM_DEVKIT_SHA256 "03f6085ae5330cf38e0a498784500675fc5bd7361bb551a9097ba5fe397aceda")
3232
# for macos-arm m* chip series
33-
set(FRIDA_OS_ARCH "macos-arm64e")
33+
set(FRIDA_OS_ARCH "macos-arm64")
3434
else()
3535
message(FATAL_ERROR "Unsupported frida arch ${FRIDA_OS_ARCH}")
3636
endif()

daemon/CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Create a target that builds the ebpf program
2-
add_ebpf_program_target(bpftime_daemon_ebpf_target ${CMAKE_CURRENT_SOURCE_DIR}/kernel/bpf_tracer.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.bpf.o)
1+
if(${BPFTIME_BUILD_WITH_LIBBPF})
2+
# Create a target that builds the ebpf program
3+
add_ebpf_program_target(bpftime_daemon_ebpf_target ${CMAKE_CURRENT_SOURCE_DIR}/kernel/bpf_tracer.bpf.c ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.bpf.o)
34

4-
# Create a target that generated the bpf skeleton
5-
add_bpf_skel_generating_target(bpftime_daemon_ebpf_skel ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.bpf.o ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.skel.h)
5+
# Create a target that generated the bpf skeleton
6+
add_bpf_skel_generating_target(bpftime_daemon_ebpf_skel ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.bpf.o ${CMAKE_CURRENT_BINARY_DIR}/bpf_tracer.skel.h)
67

7-
add_dependencies(bpftime_daemon_ebpf_skel bpftime_daemon_ebpf_target)
8+
add_dependencies(bpftime_daemon_ebpf_skel bpftime_daemon_ebpf_target)
9+
endif()
810

911
add_executable(embedfile ${CMAKE_CURRENT_SOURCE_DIR}/assets/embedfile.c)
1012

@@ -27,12 +29,19 @@ add_executable(bpftime_daemon
2729
user/main.cpp
2830
)
2931

30-
add_dependencies(libbpftime_daemon
31-
bpftime_daemon_ebpf_skel
32-
libbpf
33-
spdlog::spdlog
34-
runtime
35-
)
32+
if(${BPFTIME_BUILD_WITH_LIBBPF})
33+
add_dependencies(libbpftime_daemon
34+
bpftime_daemon_ebpf_skel
35+
libbpf
36+
spdlog::spdlog
37+
runtime
38+
)
39+
else()
40+
add_dependencies(libbpftime_daemon
41+
spdlog::spdlog
42+
runtime
43+
)
44+
endif()
3645

3746
target_include_directories(libbpftime_daemon PRIVATE
3847
${CMAKE_CURRENT_BINARY_DIR}

runtime/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ endif()
4444
#
4545
find_package(Boost REQUIRED)
4646

47+
if(Boost_FOUND)
48+
include_directories(${Boost_INCLUDE_DIRS})
49+
message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}")
50+
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
51+
else()
52+
message(FATAL_ERROR "Boost not found. Please install Boost and set BOOST_ROOT if necessary.")
53+
endif()
4754
# Find all headers and implementation files
4855
if(NOT DEFINED ARCH)
4956
set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
@@ -130,7 +137,11 @@ target_link_libraries(${PROJECT_NAME}
130137
spdlog::spdlog
131138
bpftime_base_attach_impl
132139
)
133-
add_dependencies(${PROJECT_NAME} bpftime_vm FridaGum spdlog::spdlog libbpf bpftime_base_attach_impl)
140+
if(${BPFTIME_BUILD_WITH_LIBBPF})
141+
add_dependencies(${PROJECT_NAME} bpftime_vm FridaGum spdlog::spdlog libbpf bpftime_base_attach_impl)
142+
else()
143+
add_dependencies(${PROJECT_NAME} bpftime_vm FridaGum spdlog::spdlog bpftime_base_attach_impl)
144+
endif()
134145

135146
if(BPFTIME_ENABLE_IOURING_EXT)
136147
target_link_libraries(${PROJECT_NAME}

runtime/agent/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
add_library(bpftime-agent SHARED
22
agent.cpp
33
)
4-
add_dependencies(bpftime-agent FridaGum spdlog::spdlog bpftime_frida_uprobe_attach_impl bpftime_syscall_trace_attach_impl)
4+
if(${BPFTIME_BUILD_WITH_LIBBPF})
5+
add_dependencies(bpftime-agent FridaGum spdlog::spdlog bpftime_frida_uprobe_attach_impl bpftime_syscall_trace_attach_impl)
6+
else()
7+
add_dependencies(bpftime-agent FridaGum spdlog::spdlog bpftime_frida_uprobe_attach_impl)
8+
endif()
59
set_property(TARGET bpftime-agent PROPERTY CXX_STANDARD 20)
610
target_include_directories(bpftime-agent
711
PRIVATE

runtime/include/bpftime_shm.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include <boost/interprocess/containers/string.hpp>
1212
#include <cstdint>
1313
#include <ebpf-vm.h>
14+
#if __linux__
1415
#include <sys/epoll.h>
16+
#endif
1517

1618
namespace bpftime
1719
{

runtime/object/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ add_library(bpftime-object OBJECT
33
bpf_object.cpp
44
)
55

6-
add_dependencies(bpftime-object copy_headers libbpf spdlog::spdlog bpftime_vm)
6+
if(${BPFTIME_BUILD_WITH_LIBBPF})
7+
add_dependencies(bpftime-object copy_headers libbpf spdlog::spdlog bpftime_vm)
8+
else()
9+
add_dependencies(bpftime-object spdlog::spdlog bpftime_vm)
10+
endif()
711

812
target_link_libraries(bpftime-object
913
PUBLIC

0 commit comments

Comments
 (0)