From 8a4c3d2eaafc1870c000071ef682e31853690558 Mon Sep 17 00:00:00 2001 From: Grzegorz Nosek Date: Wed, 5 Jul 2023 16:24:23 +0200 Subject: [PATCH] cleanup(build): self-contained BPF probe build The BPF build now no longer touches the source directory and does not depend on any files outside the (generated) source directory. Signed-off-by: Grzegorz Nosek --- driver/bpf/CMakeLists.txt | 46 ++++++++++++++++++++-------- driver/bpf/{Makefile => Makefile.in} | 11 +------ driver/bpf/filler_helpers.h | 2 +- driver/bpf/fillers.h | 6 ++-- driver/bpf/probe.c | 4 +-- 5 files changed, 41 insertions(+), 28 deletions(-) rename driver/bpf/{Makefile => Makefile.in} (86%) diff --git a/driver/bpf/CMakeLists.txt b/driver/bpf/CMakeLists.txt index b3e4a06e0b1..3a1128b1c7a 100644 --- a/driver/bpf/CMakeLists.txt +++ b/driver/bpf/CMakeLists.txt @@ -9,6 +9,32 @@ configure_file(../driver_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/../driver_confi option(BUILD_BPF "Build the BPF driver on Linux" OFF) +# Note: probe.c *must* be the first entry to generate a proper Makefile +set(BPF_SOURCES + probe.c + bpf_helpers.h + builtins.h + filler_helpers.h + fillers.h + maps.h + missing_definitions.h + plumbing_helpers.h + quirks.h + ring_helpers.h + types.h + ${CMAKE_CURRENT_SOURCE_DIR}/../driver_config.h + ../ppm_api_version.h + ../ppm_events_public.h + ../feature_gates.h + ../ppm_version.h + ../ppm_fillers.h + ../ppm_flag_helpers.h + ../ppm.h + ../ppm_consumer.h + ../capture_macro.h + ../systype_compat.h + ) + if(BUILD_BPF) # Check minimum kernel version set(bpf_min_kver_map_x86_64 4.14) @@ -18,25 +44,21 @@ if(BUILD_BPF) message(WARNING "[BPF] To run this driver you need a Linux kernel version >= ${bpf_min_kver_map_${TARGET_ARCH}} but actual kernel version is: ${UNAME_RESULT}") endif() + foreach(FILENAME IN LISTS BPF_SOURCES) + get_filename_component(BASENAME ${FILENAME} NAME) + configure_file(${FILENAME} src/${BASENAME} COPYONLY) + string(APPEND BPF_DEPENDENCIES "$(src)/${BASENAME} ") + endforeach() + add_custom_target(bpf ALL COMMAND make COMMAND "${CMAKE_COMMAND}" -E copy_if_different probe.o "${CMAKE_CURRENT_BINARY_DIR}" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src" VERBATIM) endif() install(FILES - bpf_helpers.h - builtins.h - filler_helpers.h - fillers.h + ${BPF_SOURCES} Makefile - maps.h - plumbing_helpers.h - probe.c - quirks.h - ring_helpers.h - missing_definitions.h - types.h DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}/bpf" COMPONENT ${DRIVER_COMPONENT_NAME}) diff --git a/driver/bpf/Makefile b/driver/bpf/Makefile.in similarity index 86% rename from driver/bpf/Makefile rename to driver/bpf/Makefile.in index 48a3529f253..eae26ff30fc 100644 --- a/driver/bpf/Makefile +++ b/driver/bpf/Makefile.in @@ -41,16 +41,7 @@ clean: $(MAKE) -C $(KERNELDIR) M=$$PWD clean @rm -f *~ -$(obj)/probe.o: $(src)/probe.c \ - $(src)/bpf_helpers.h \ - $(src)/filler_helpers.h \ - $(src)/fillers.h \ - $(src)/maps.h \ - $(src)/plumbing_helpers.h \ - $(src)/quirks.h \ - $(src)/ring_helpers.h \ - $(src)/missing_definitions.h \ - $(src)/types.h +$(obj)/probe.o: @BPF_DEPENDENCIES@ $(CLANG) $(LINUXINCLUDE) \ $(KBUILD_CPPFLAGS) \ $(KBUILD_EXTRA_CPPFLAGS) \ diff --git a/driver/bpf/filler_helpers.h b/driver/bpf/filler_helpers.h index 25e8a0baa83..722fa8414ab 100644 --- a/driver/bpf/filler_helpers.h +++ b/driver/bpf/filler_helpers.h @@ -18,7 +18,7 @@ or GPL2.txt for full copies of the license. #include #include -#include "../ppm_flag_helpers.h" +#include "ppm_flag_helpers.h" #include "builtins.h" // Old kernels (like 4.14) have too strict limits on the bpf program length to support 32 path components. For the moment we decrease the limit to 16. diff --git a/driver/bpf/fillers.h b/driver/bpf/fillers.h index 2a2bef549fd..26fdbf211f2 100644 --- a/driver/bpf/fillers.h +++ b/driver/bpf/fillers.h @@ -9,9 +9,9 @@ or GPL2.txt for full copies of the license. #ifndef __FILLERS_H #define __FILLERS_H -#include "../systype_compat.h" -#include "../ppm_flag_helpers.h" -#include "../ppm_version.h" +#include "systype_compat.h" +#include "ppm_flag_helpers.h" +#include "ppm_version.h" #include "bpf_helpers.h" #include "missing_definitions.h" diff --git a/driver/bpf/probe.c b/driver/bpf/probe.c index d885ff18260..c856537a9ac 100644 --- a/driver/bpf/probe.c +++ b/driver/bpf/probe.c @@ -15,8 +15,8 @@ or GPL2.txt for full copies of the license. #endif #include -#include "../driver_config.h" -#include "../ppm_events_public.h" +#include "driver_config.h" +#include "ppm_events_public.h" #include "bpf_helpers.h" #include "types.h" #include "maps.h"