149 lines
5.6 KiB
Diff
149 lines
5.6 KiB
Diff
From c7dbab451484b96178da1a8c43330154ce4c9d7a Mon Sep 17 00:00:00 2001
|
|
From: Daniel Xu <dxu@dxuuu.xyz>
|
|
Date: Wed, 14 Oct 2020 17:09:46 -0700
|
|
Subject: [PATCH] Detect 7 arg bpf_attach_uprobe() API
|
|
|
|
The 7th arg allows us to specify the usdt semaphore location.
|
|
---
|
|
cmake/FindLibBcc.cmake | 11 +++++++++++
|
|
src/CMakeLists.txt | 3 +++
|
|
src/attached_probe.cpp | 42 ++++++++++++++++++++++++++++++++++--------
|
|
src/main.cpp | 6 ++++++
|
|
tests/CMakeLists.txt | 3 +++
|
|
5 files changed, 57 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/cmake/FindLibBcc.cmake b/cmake/FindLibBcc.cmake
|
|
index 4c09a8ca2..92cedab5e 100644
|
|
--- a/cmake/FindLibBcc.cmake
|
|
+++ b/cmake/FindLibBcc.cmake
|
|
@@ -7,6 +7,8 @@
|
|
# LIBBCC_DEFINITIONS - Compiler switches required for using libbcc
|
|
# LIBBCC_BPF_LIBRARY_STATIC - libbpf static library (for static compilation)
|
|
# LIBBCC_LOADER_LIBRARY_STATIC - libbcc helper static library (for static compilation)
|
|
+# LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE
|
|
+# LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
#
|
|
# Note that the shared libbcc binary has libbpf and bcc_loader already compiled in but
|
|
# the static doesn't. So when creating a static build those have to be included too.
|
|
@@ -94,6 +96,15 @@ int main(void) {
|
|
return 0;
|
|
}
|
|
" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
+
|
|
+CHECK_CXX_SOURCE_COMPILES("
|
|
+#include <bcc/libbpf.h>
|
|
+
|
|
+int main(void) {
|
|
+ bpf_attach_uprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0, 0);
|
|
+ return 0;
|
|
+}
|
|
+" LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
SET(CMAKE_REQUIRED_LIBRARIES)
|
|
SET(CMAKE_REQUIRED_INCLUDES)
|
|
endif()
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index 9162356e3..cef94d144 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -88,6 +88,9 @@ endif(HAVE_BFD_DISASM)
|
|
if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
target_compile_definitions(bpftrace PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
+if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
+ target_compile_definitions(bpftrace PRIVATE LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
+endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
|
|
if (ALLOW_UNSAFE_PROBE)
|
|
target_compile_definitions(bpftrace PRIVATE HAVE_UNSAFE_PROBE)
|
|
diff --git a/src/attached_probe.cpp b/src/attached_probe.cpp
|
|
index 93fbfa876..a5d8bc56d 100644
|
|
--- a/src/attached_probe.cpp
|
|
+++ b/src/attached_probe.cpp
|
|
@@ -698,12 +698,23 @@ void AttachedProbe::attach_uprobe(bool safe_mode)
|
|
{
|
|
resolve_offset_uprobe(safe_mode);
|
|
|
|
- int perf_event_fd = bpf_attach_uprobe(progfd_,
|
|
- attachtype(probe_.type),
|
|
- eventname().c_str(),
|
|
- probe_.path.c_str(),
|
|
- offset_,
|
|
- probe_.pid);
|
|
+ int perf_event_fd =
|
|
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
+ bpf_attach_uprobe(progfd_,
|
|
+ attachtype(probe_.type),
|
|
+ eventname().c_str(),
|
|
+ probe_.path.c_str(),
|
|
+ offset_,
|
|
+ probe_.pid,
|
|
+ 0);
|
|
+#else
|
|
+ bpf_attach_uprobe(progfd_,
|
|
+ attachtype(probe_.type),
|
|
+ eventname().c_str(),
|
|
+ probe_.path.c_str(),
|
|
+ offset_,
|
|
+ probe_.pid);
|
|
+#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
|
|
if (perf_event_fd < 0)
|
|
throw std::runtime_error("Error attaching probe: " + probe_.name);
|
|
@@ -812,8 +823,23 @@ void AttachedProbe::attach_usdt(int pid)
|
|
|
|
offset_ = resolve_offset(probe_.path, probe_.attach_point, probe_.loc);
|
|
|
|
- int perf_event_fd = bpf_attach_uprobe(progfd_, attachtype(probe_.type),
|
|
- eventname().c_str(), probe_.path.c_str(), offset_, pid == 0 ? -1 : pid);
|
|
+ int perf_event_fd =
|
|
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
+ bpf_attach_uprobe(progfd_,
|
|
+ attachtype(probe_.type),
|
|
+ eventname().c_str(),
|
|
+ probe_.path.c_str(),
|
|
+ offset_,
|
|
+ pid == 0 ? -1 : pid,
|
|
+ 0);
|
|
+#else
|
|
+ bpf_attach_uprobe(progfd_,
|
|
+ attachtype(probe_.type),
|
|
+ eventname().c_str(),
|
|
+ probe_.path.c_str(),
|
|
+ offset_,
|
|
+ pid == 0 ? -1 : pid);
|
|
+#endif // LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
|
|
if (perf_event_fd < 0)
|
|
{
|
|
diff --git a/src/main.cpp b/src/main.cpp
|
|
index 48fcf5aa0..09f4d9677 100644
|
|
--- a/src/main.cpp
|
|
+++ b/src/main.cpp
|
|
@@ -162,6 +162,12 @@ static int info()
|
|
<< "yes" << std::endl;
|
|
#else
|
|
<< "no" << std::endl;
|
|
+#endif
|
|
+ std::cerr << " bcc bpf_attach_uprobe refcount: "
|
|
+#ifdef LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE
|
|
+ << "yes" << std::endl;
|
|
+#else
|
|
+ << "no" << std::endl;
|
|
#endif
|
|
std::cerr << " libbpf: "
|
|
#ifdef HAVE_LIBBPF
|
|
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
|
|
index ace5ff106..332eba2b5 100644
|
|
--- a/tests/CMakeLists.txt
|
|
+++ b/tests/CMakeLists.txt
|
|
@@ -116,6 +116,9 @@ endif(HAVE_BFD_DISASM)
|
|
if(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
target_compile_definitions(bpftrace_test PRIVATE LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
endif(LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
|
|
+if(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
+ target_compile_definitions(bpftrace_test PRIVATE LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
+endif(LIBBCC_ATTACH_UPROBE_SEVEN_ARGS_SIGNATURE)
|
|
|
|
target_link_libraries(bpftrace_test arch ast parser resources)
|
|
|