Skip to content

Commit

Permalink
bpftrace v0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fbs committed May 1, 2021
1 parent b844532 commit 325da6d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 56 deletions.
113 changes: 85 additions & 28 deletions bpftrace/0001-Do-not-require-libbpf-for-static-build.patch
Original file line number Diff line number Diff line change
@@ -1,51 +1,108 @@
From a2cffdecd0ae3952f36917710307ed60bd1acbad Mon Sep 17 00:00:00 2001
From bbef8fe662571abed5d538e6ba819d345de10978 Mon Sep 17 00:00:00 2001
From: bas smit <[email protected]>
Date: Thu, 25 Jun 2020 17:22:54 +0200
Date: Sat, 1 May 2021 13:04:44 +0200
Subject: [PATCH] Do not require libbpf for static build

---
CMakeLists.txt | 2 +-
src/CMakeLists.txt | 1 -
tests/CMakeLists.txt | 1 -
3 files changed, 1 insertion(+), 3 deletions(-)
CMakeLists.txt | 2 +-
cmake/FindLibBcc.cmake | 56 +++++++++++++++++++++---------------------
src/CMakeLists.txt | 1 -
3 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c739585..af7493ff 100644
index a2f7c6b..64704e6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,7 +103,7 @@ if(POLICY CMP0075)
@@ -111,7 +111,7 @@ if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
if(STATIC_LINKING)
- set(CMAKE_REQUIRED_LIBRARIES bcc bcc_bpf bpf elf z)
+ set(CMAKE_REQUIRED_LIBRARIES bcc bcc_bpf elf z)
else()
set(CMAKE_REQUIRED_LIBRARIES bcc)
endif(STATIC_LINKING)
set(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES})
if (LIBBPF_FOUND)
diff --git a/cmake/FindLibBcc.cmake b/cmake/FindLibBcc.cmake
index 61d1f5e..79326c5 100644
--- a/cmake/FindLibBcc.cmake
+++ b/cmake/FindLibBcc.cmake
@@ -78,36 +78,36 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBcc "Please install the bcc library package

# Check bpf_attach_kprobe signature
if(${LIBBCC_FOUND})
-if(STATIC_LINKING)
- # libbcc.a is not statically linked with libbpf.a, libelf.a, and libz.a.
- # If we do a static bpftrace build, we must link them in.
- find_package(LibBpf)
- find_package(LibElf)
- find_package(LibZ)
- SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_BPF_LIBRARY_STATIC} ${LIBBPF_LIBRARIES} ${LIBELF_LIBRARIES} ${LIBZ_LIBRARIES})
-else()
- SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES} ${LIBBPF_LIBRARIES})
-endif()
+ if(STATIC_LINKING)
+ # libbcc.a is not statically linked with libbpf.a, libelf.a, and libz.a.
+ # If we do a static bpftrace build, we must link them in.
+ find_package(LibBpf)
+ find_package(LibElf)
+ find_package(LibZ)
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_BPF_LIBRARY_STATIC} ${LIBELF_LIBRARIES} ${LIBZ_LIBRARIES})
+ else()
+ SET(CMAKE_REQUIRED_LIBRARIES ${LIBBCC_LIBRARIES} )
+ endif()

-INCLUDE(CheckCXXSourceCompiles)
-SET(CMAKE_REQUIRED_INCLUDES ${LIBBCC_INCLUDE_DIRS})
-CHECK_CXX_SOURCE_COMPILES("
-#include <bcc/libbpf.h>
+ INCLUDE(CheckCXXSourceCompiles)
+ SET(CMAKE_REQUIRED_INCLUDES ${LIBBCC_INCLUDE_DIRS})
+ CHECK_CXX_SOURCE_COMPILES("
+ #include <bcc/libbpf.h>

-int main(void) {
- bpf_attach_kprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0);
- return 0;
-}
-" LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)
+ int main(void) {
+ bpf_attach_kprobe(0, BPF_PROBE_ENTRY, \"\", \"\", 0, 0);
+ return 0;
+ }
+ " LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE)

-CHECK_CXX_SOURCE_COMPILES("
-#include <bcc/libbpf.h>
+ 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)
+ 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 487fa9bc..d82054ae 100644
index f491a54..38dcdb8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -90,7 +90,6 @@ target_link_libraries(bpftrace ${LIBBCC_LIBRARIES})
@@ -150,7 +150,6 @@ target_link_libraries(libbpftrace ${LIBBCC_LIBRARIES})
if(STATIC_LINKING)
# These are not part of the static libbcc so have to be added separate
target_link_libraries(bpftrace ${LIBBCC_BPF_LIBRARY_STATIC})
- target_link_libraries(bpftrace ${LIBBPF_LIBRARIES})
target_link_libraries(bpftrace ${LIBBCC_LOADER_LIBRARY_STATIC})

add_library(LIBELF STATIC IMPORTED)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d660fe73..4f73c1d7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -111,7 +111,6 @@ if (STATIC_LINKING)

# These are not part of the static libbcc so have to be added separate
target_link_libraries(bpftrace_test ${LIBBCC_BPF_LIBRARY_STATIC})
- target_link_libraries(bpftrace_test ${LIBBPF_LIBRARIES})
target_link_libraries(bpftrace_test ${LIBBCC_LOADER_LIBRARY_STATIC})
target_link_libraries(libbpftrace ${LIBBCC_BPF_LIBRARY_STATIC})
- target_link_libraries(libbpftrace ${LIBBPF_LIBRARIES})
target_link_libraries(libbpftrace ${LIBBCC_LOADER_LIBRARY_STATIC})

add_library(LIBELF STATIC IMPORTED)
--
2.25.0
2.24.3 (Apple Git-128)

24 changes: 0 additions & 24 deletions bpftrace/0001-Don-t-require-libbpf-for-build.patch

This file was deleted.

38 changes: 38 additions & 0 deletions bpftrace/0001-Relink-against-libz.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From 533790bcba6fc235ad55bfda0ff049b9a66f08fd Mon Sep 17 00:00:00 2001
From: bas smit <[email protected]>
Date: Sat, 1 May 2021 13:33:00 +0200
Subject: [PATCH] Relink against libz

The ordering is messed, can't find libz for libcc. This fixes it in a
hacky way.
---
src/CMakeLists.txt | 3 +++
tests/CMakeLists.txt | 1 +
2 files changed, 4 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 38dcdb8..cb3e755 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -169,6 +169,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_VERSION}
target_link_libraries(libbpftrace "stdc++fs")
endif()

+
+target_link_libraries(libbpftrace ${LIBZ_LIBRARIES})
+
if (BUILD_ASAN)
if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
# target_link_options is supported in CMake 3.13 and newer
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8d546f9..dc14cf3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -198,3 +198,4 @@ if(ENABLE_TEST_VALIDATE_CODEGEN)
else()
message(STATUS "codegen-validator test disabled")
endif()
+target_link_libraries(bpftrace_test ${LIBZ_LIBRARIES})
--
2.24.3 (Apple Git-128)

10 changes: 6 additions & 4 deletions bpftrace/bpftrace.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
%global pkgname bpftrace
%global commitid 487dd81

# The static build is a bit of a hack and
# doesn't build th docs and tools package
Expand All @@ -12,9 +11,9 @@
%global _find_debuginfo_opts -g

Name: %{pkgname}
Version: 0.11.0
Version: 0.12.0
%if "%{?commitid}" != ""
Release: 5.%{?commitid}%{?dist}
Release: 1.%{?commitid}%{?dist}
%else
Release: 1%{?dist}
%endif
Expand All @@ -29,7 +28,7 @@ Patch2: 0001-tools-Patch-for-RHEL7.patch

Patch100: 0001-build-Force-disable-optimization.patch
Patch101: 0001-Do-not-require-libbpf-for-static-build.patch
Patch102: 0001-Don-t-require-libbpf-for-build.patch
Patch102: 0001-Relink-against-libz.patch


ExclusiveArch: x86_64
Expand Down Expand Up @@ -137,6 +136,9 @@ find %{buildroot}%{_datadir}/%{pkgname}/tools -type f -exec \
%{_datadir}/%{pkgname}/tools/doc/*.txt

%changelog
* Sat May 1 2021 bas smit - 0.12.0-1
- bpftrace 0.12.0

* Fri Nov 6 2020 bas smit - 0.11.0-5
- bpftrace 0.11 487dd81 with bcc compatiblity fix

Expand Down

0 comments on commit 325da6d

Please sign in to comment.