Skip to content

Commit e4bb4f3

Browse files
alan-maguireyonghong-song
authored andcommitted
bcc: support building with external libbpf package and older uapi linux/bpf.h
When building bcc with a relatively new packaged libbpf (0.8.1) and -DCMAKE_USE_LIBBPF_PACKAGE:BOOL=TRUE, multiple compilation failures are encountered due the fact the system uapi header in /usr/include/linux/bpf.h is not very recent (this is often the case for distros, which sync it via a kernel headers package quite conservatively due to use by glibc). With libbpf built via git submodule, the uapi header included in the libbpf package is used, so here a similar approach is proposed for the external package build. Instead of having to sync another file the already present compat/linux/virtual_bpf.h is used; we copy it to compat/linux/bpf.h (eliminating the string prefix/suffix on first/last lines). From there, we ensure that places that assume the presence of the libbpf git submodule point at compat/ as a location to find the uapi header. Signed-off-by: Alan Maguire <[email protected]>
1 parent 981a947 commit e4bb4f3

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

examples/cpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
include_directories(${PROJECT_BINARY_DIR}/src/cc)
55
include_directories(${PROJECT_SOURCE_DIR}/src/cc)
66
include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
7+
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
8+
include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
9+
else()
710
include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
11+
endif()
812

913
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
1014
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

introspection/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
include_directories(${PROJECT_SOURCE_DIR}/src/cc)
55
include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
6+
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
7+
include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
8+
else()
69
include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
10+
endif()
711

812
option(INSTALL_INTROSPECTION "Install BPF introspection tools" ON)
913
option(BPS_LINK_RT "Pass -lrt to linker when linking bps tool" ON)

src/cc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ endif (LIBDEBUGINFOD_FOUND)
1515
# todo: if check for kernel version
1616
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
1717
include_directories(${LIBBPF_INCLUDE_DIRS})
18+
# create up-to-date linux/bpf.h from virtual_bpf.h (remove string wrapper);
19+
# when libbpf is built as a submodule we use its version of linux/bpf.h
20+
# so this does similar for the libbpf package, removing reliance on the
21+
# system uapi header which can be out of date.
22+
execute_process(COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/compat/linux && grep -ve '\\*\\*\\*\\*' virtual_bpf.h > bpf.h")
23+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat)
1824
else()
1925
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
2026
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)

tests/cc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
include_directories(${PROJECT_SOURCE_DIR}/src/cc)
55
include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
6+
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
7+
include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
8+
else()
69
include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
10+
endif()
711
include_directories(${PROJECT_SOURCE_DIR}/tests/python/include)
812

913
add_executable(test_static test_static.c)

0 commit comments

Comments
 (0)