Blame SOURCES/bcc-0.25.0-bcc-support-building-with-external-libbpf-package-an.patch

818e97
From 2e14fbaf9105e0b504f243ffc6d7d5a16e13a2a7 Mon Sep 17 00:00:00 2001
818e97
From: Alan Maguire <alan.maguire@oracle.com>
818e97
Date: Fri, 14 Oct 2022 13:01:58 +0000
818e97
Subject: [PATCH] bcc: support building with external libbpf package and older
818e97
 uapi linux/bpf.h
818e97
818e97
When building bcc with a relatively new packaged libbpf (0.8.1)
818e97
and -DCMAKE_USE_LIBBPF_PACKAGE:BOOL=TRUE, multiple compilation
818e97
failures are encountered due the fact the system uapi header
818e97
in /usr/include/linux/bpf.h is not very recent (this is often
818e97
the case for distros, which sync it via a kernel headers
818e97
package quite conservatively due to use by glibc).
818e97
818e97
With libbpf built via git submodule, the uapi header included in
818e97
the libbpf package is used, so here a similar approach is proposed
818e97
for the external package build.  Instead of having to sync
818e97
another file the already present compat/linux/virtual_bpf.h
818e97
is used; we copy it to compat/linux/bpf.h (eliminating the
818e97
string prefix/suffix on first/last lines).
818e97
818e97
From there, we ensure that places that assume the presence of
818e97
the libbpf git submodule point at compat/ as a location to
818e97
find the uapi header.
818e97
818e97
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
818e97
---
818e97
 examples/cpp/CMakeLists.txt  | 4 ++++
818e97
 introspection/CMakeLists.txt | 4 ++++
818e97
 src/cc/CMakeLists.txt        | 6 ++++++
818e97
 tests/cc/CMakeLists.txt      | 4 ++++
818e97
 4 files changed, 18 insertions(+)
818e97
818e97
diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
818e97
index 801e6bad..8d09ae11 100644
818e97
--- a/examples/cpp/CMakeLists.txt
818e97
+++ b/examples/cpp/CMakeLists.txt
818e97
@@ -4,7 +4,11 @@
818e97
 include_directories(${PROJECT_BINARY_DIR}/src/cc)
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc)
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
818e97
+if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
818e97
+include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
818e97
+else()
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
818e97
+endif()
818e97
 
818e97
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
818e97
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
818e97
diff --git a/introspection/CMakeLists.txt b/introspection/CMakeLists.txt
818e97
index dcbe69a3..ce2d03dc 100644
818e97
--- a/introspection/CMakeLists.txt
818e97
+++ b/introspection/CMakeLists.txt
818e97
@@ -3,7 +3,11 @@
818e97
 
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc)
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
818e97
+if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
818e97
+include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
818e97
+else()
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
818e97
+endif()
818e97
 
818e97
 option(INSTALL_INTROSPECTION "Install BPF introspection tools" ON)
818e97
 option(BPS_LINK_RT "Pass -lrt to linker when linking bps tool" ON)
818e97
diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
818e97
index ffe8feec..c7f53530 100644
818e97
--- a/src/cc/CMakeLists.txt
818e97
+++ b/src/cc/CMakeLists.txt
818e97
@@ -15,6 +15,12 @@ endif (LIBDEBUGINFOD_FOUND)
818e97
 # todo: if check for kernel version
818e97
 if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
818e97
   include_directories(${LIBBPF_INCLUDE_DIRS})
818e97
+  # create up-to-date linux/bpf.h from virtual_bpf.h (remove string wrapper);
818e97
+  # when libbpf is built as a submodule we use its version of linux/bpf.h
818e97
+  # so this does similar for the libbpf package, removing reliance on the
818e97
+  # system uapi header which can be out of date.
818e97
+  execute_process(COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/compat/linux && grep -ve '\\*\\*\\*\\*' virtual_bpf.h > bpf.h")
818e97
+  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat)
818e97
 else()
818e97
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
818e97
   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
818e97
diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt
818e97
index 677867d7..47056455 100644
818e97
--- a/tests/cc/CMakeLists.txt
818e97
+++ b/tests/cc/CMakeLists.txt
818e97
@@ -3,7 +3,11 @@
818e97
 
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc)
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
818e97
+if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
818e97
+include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
818e97
+else()
818e97
 include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
818e97
+endif()
818e97
 include_directories(${PROJECT_SOURCE_DIR}/tests/python/include)
818e97
 
818e97
 add_executable(test_static test_static.c)
818e97
-- 
818e97
2.37.3
818e97