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