0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-27 06:10:43 +00:00

Fix handling of vendored eBPF code in CMake. ()

* Fix logic error in CMake code for kernel version detection.

* Force legacy libbpf for CentOS 7 and AL 2 package builds.

* Check target kernel version instead of host kernel version.

This should help when building in containers.

* Fix up handling for older versions of CMake.

* Use CMake C compiler for libbpf builds.

* Fix selection of legacy eBPF code in static builds.

* Explicitly pull in kernel headers on CentOS.

* Fix typo in FORCE_LEGACY_LIBBPF option.

* Only enable eBPF by default on x86.

* Fix detection of static builds.

* Fix libc detection logic.

* Fix handling of static builds.

* Fix musl libc detection.

* Fix check messages for libc detection.
This commit is contained in:
Austin S. Hemmelgarn 2024-05-06 07:05:34 -04:00 committed by GitHub
parent 1456cac4af
commit 90552bd501
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 88 additions and 23 deletions

View file

@ -171,7 +171,7 @@ mark_as_advanced(ENABLE_SENTRY)
option(BUILD_FOR_PACKAGING "Include component files for native packages" False) option(BUILD_FOR_PACKAGING "Include component files for native packages" False)
mark_as_advanced(BUILD_FOR_PACKAGING) mark_as_advanced(BUILD_FOR_PACKAGING)
cmake_dependent_option(FORCE_LEGACY_LIBBPF "Force usage of libbpf 0.0.9 instead of the latest version." False "ENABLE_PLUGIN_LIBBPF" False) cmake_dependent_option(FORCE_LEGACY_LIBBPF "Force usage of libbpf 0.0.9 instead of the latest version." False "ENABLE_PLUGIN_EBPF" False)
mark_as_advanced(FORCE_LEGACY_LIBBPF) mark_as_advanced(FORCE_LEGACY_LIBBPF)
if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE) if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)

View file

@ -246,7 +246,9 @@ HEREDOC
} }
if [ "$(uname -s)" = "Linux" ]; then if [ "$(uname -s)" = "Linux" ]; then
ENABLE_EBPF=1 case "$(uname -m)" in
x86_64|i?86) ENABLE_EBPF=1 ;;
esac
fi fi
DONOTSTART=0 DONOTSTART=0

View file

@ -332,6 +332,11 @@ happened, on your systems and applications.
%endif %endif
%if %{_have_ebpf} %if %{_have_ebpf}
-DENABLE_PLUGIN_EBPF=On \ -DENABLE_PLUGIN_EBPF=On \
%if 0%{?centos_ver:1}
%if 0%{?centos_ver} < 8
-DFORCE_LEGACY_LIBBPF=On \
%endif
%endif
%else %else
-DENABLE_PLUGIN_EBPF=Off \ -DENABLE_PLUGIN_EBPF=Off \
%endif %endif

View file

@ -13,7 +13,16 @@ set(ebpf-legacy_BUILD_DIR "${CMAKE_BINARY_DIR}/ebpf-legacy-build")
function(netdata_fetch_legacy_ebpf_code) function(netdata_fetch_legacy_ebpf_code)
netdata_identify_libc(_libc) netdata_identify_libc(_libc)
if(_libc STREQUAL "glibc") if(DEFINED BUILD_SHARED_LIBS)
if(NOT BUILD_SHARED_LIBS)
set(need_static TRUE)
endif()
endif()
if(need_static)
set(_hash 302714979470e300b81a64a4ebef9fac1f3488488482cf30c926fa98f73cabc1)
set(_libc "static")
elseif(_libc STREQUAL "glibc")
set(_hash 7013753ef85c2d3681bdcfdd7544705cdaf5b640b70734ca223f43cc5adcdc53) set(_hash 7013753ef85c2d3681bdcfdd7544705cdaf5b640b70734ca223f43cc5adcdc53)
elseif(_libc STREQUAL "musl") elseif(_libc STREQUAL "musl")
set(_hash b524d1fcbd67c82cdfc9f46d55f67c0c0c0412c3356c85b38c03ce03f6068747) set(_hash b524d1fcbd67c82cdfc9f46d55f67c0c0c0412c3356c85b38c03ce03f6068747)

View file

@ -34,12 +34,20 @@ function(netdata_bundle_libbpf)
set(_libbpf_tag b981a3a138e3a30024e4e143d62cff2dc307121e) # v1.4.0p_netdata set(_libbpf_tag b981a3a138e3a30024e4e143d62cff2dc307121e) # v1.4.0p_netdata
endif() endif()
netdata_identify_libc(_libc) if(DEFINED BUILD_SHARED_LIBS)
if(NOT BUILD_SHARED_LIBS)
set(need_static TRUE)
endif()
endif()
string(REGEX MATCH "glibc|musl" _libc_supported "${_libc}") if(NOT need_static)
netdata_identify_libc(_libc)
if(NOT _libc_supported) string(REGEX MATCH "glibc|musl" _libc_supported "${_libc}")
message(FATAL_ERROR "This systems libc (detected: ${_libc}) is not not supported by the eBPF plugin.")
if(NOT _libc_supported)
message(FATAL_ERROR "This systems libc (detected: ${_libc}) is not not supported by the eBPF plugin.")
endif()
endif() endif()
find_program(MAKE_COMMAND make) find_program(MAKE_COMMAND make)
@ -65,7 +73,7 @@ function(netdata_bundle_libbpf)
GIT_TAG ${_libbpf_tag} GIT_TAG ${_libbpf_tag}
SOURCE_DIR "${libbpf_SOURCE_DIR}" SOURCE_DIR "${libbpf_SOURCE_DIR}"
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND ${MAKE_COMMAND} -C src BUILD_STATIC_ONLY=1 OBJDIR=build/ DESTDIR=../ install BUILD_COMMAND ${MAKE_COMMAND} -C src CC=${CMAKE_C_COMPILER} BUILD_STATIC_ONLY=1 OBJDIR=build/ DESTDIR=../ install
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS "${_libbpf_library}" BUILD_BYPRODUCTS "${_libbpf_library}"
INSTALL_COMMAND "" INSTALL_COMMAND ""

View file

@ -16,17 +16,55 @@ function(netdata_detect_host_kernel_version)
message(CHECK_START "Determining host kernel version") message(CHECK_START "Determining host kernel version")
execute_process(COMMAND uname -r if(NOT CMAKE_CROSSCOMPILING)
RESULT_VARIABLE _uname_result include(CheckIncludeFile)
OUTPUT_VARIABLE _uname_output)
if(NOT _uname_result) check_include_file("linux/version.h" CAN_USE_VERSION_H)
message(CHECK_FAIL "unknown")
set(HOST_KERNEL_VERSION "0.0.0" CACHE STRING "Detected host kernel version") if(CAN_USE_VERSION_H)
return() message(CHECK_START "Checking version using linux/version.h")
file(WRITE "${CMAKE_BINARY_DIR}/kversion-test.c" "
#include <stdio.h>
#include <linux/version.h>
int main() {
printf(\"%i.%i.%i\", LINUX_VERSION_MAJOR, LINUX_VERSION_PATCHLEVEL, LINUX_VERSION_SUBLEVEL);
}
")
try_run(_run_success _compile_success
${CMAKE_BINARY_DIR}
SOURCES ${CMAKE_BINARY_DIR}/kversion-test.c
RUN_OUTPUT_VARIABLE _kversion_output)
if(_compile_success AND _run_success EQUAL 0)
message(CHECK_PASS "success")
set(_kversion_value "${_kversion_output}")
else()
message(CHECK_FAIL "failed")
endif()
endif()
endif() endif()
string(REGEX REPLACE "-.+$" "" _kversion "${_uname_output}") if(NOT DEFINED _kversion_value)
message(CHECK_START "Checking version using uname")
execute_process(COMMAND uname -r
RESULT_VARIABLE _uname_result
OUTPUT_VARIABLE _uname_output)
if(NOT _uname_result EQUAL 0)
message(CHECK_FAIL "failed")
message(CHECK_FAIL "unknown")
set(HOST_KERNEL_VERSION "0.0.0" CACHE STRING "Detected host kernel version")
return()
else()
message(CHECK_PASS "success")
endif()
set(_kversion_value "${_uname_output}")
endif()
string(REGEX REPLACE "-.+$" "" _kversion "${_kversion_value}")
message(CHECK_PASS "${_kversion}") message(CHECK_PASS "${_kversion}")
set(HOST_KERNEL_VERSION "${_kversion}" CACHE STRING "Detected host kernel version") set(HOST_KERNEL_VERSION "${_kversion}" CACHE STRING "Detected host kernel version")
endfunction() endfunction()
@ -36,34 +74,36 @@ endfunction()
# Sets the specified variable to the name of the libc or "unknown" # Sets the specified variable to the name of the libc or "unknown"
function(netdata_identify_libc _libc_name) function(netdata_identify_libc _libc_name)
if(NOT DEFINED _ND_DETECTED_LIBC) if(NOT DEFINED _ND_DETECTED_LIBC)
message(INFO "Detecting libc implementation") message(CHECK_START "Detecting libc implementation")
execute_process(COMMAND ldd --version execute_process(COMMAND ldd --version
COMMAND grep -q -i -E "glibc|gnu libc" COMMAND grep -q -i -E "glibc|gnu libc"
RESULT_VARIABLE LDD_IS_GLIBC RESULT_VARIABLE LDD_RESULT
OUTPUT_VARIABLE LDD_OUTPUT OUTPUT_VARIABLE LDD_OUTPUT
ERROR_VARIABLE LDD_OUTPUT) ERROR_VARIABLE LDD_OUTPUT)
if(LDD_IS_GLIBC) if(NOT LDD_RESULT)
set(${_libc_name} glibc PARENT_SCOPE) set(${_libc_name} glibc PARENT_SCOPE)
set(_ND_DETECTED_LIBC glibc CACHE INTERNAL "") set(_ND_DETECTED_LIBC glibc CACHE INTERNAL "")
message(CHECK_PASS "glibc")
return() return()
endif() endif()
execute_process(COMMAND ldd --version execute_process(COMMAND sh -c "ldd --version 2>&1 | grep -q -i 'musl'"
COMMAND grep -q -i -E "musl" RESULT_VARIABLE LDD_RESULT
RESULT_VARIABLE LDD_IS_MUSL
OUTPUT_VARIABLE LDD_OUTPUT OUTPUT_VARIABLE LDD_OUTPUT
ERROR_VARIABLE LDD_OUTPUT) ERROR_VARIABLE LDD_OUTPUT)
if(LDD_IS_MUSL) if(NOT LDD_RESULT)
set(${_libc_name} musl PARENT_SCOPE) set(${_libc_name} musl PARENT_SCOPE)
set(_ND_DETECTED_LIBC musl CACHE INTERNAL "") set(_ND_DETECTED_LIBC musl CACHE INTERNAL "")
message(CHECK_PASS "musl")
return() return()
endif() endif()
set(${_libc_name} unknown PARENT_SCOPE) set(${_libc_name} unknown PARENT_SCOPE)
set(_ND_DETECTED_LIBC unknown CACHE INTERNAL "") set(_ND_DETECTED_LIBC unknown CACHE INTERNAL "")
message(CHECK_FAIL "unknown")
else() else()
set(${_libc_name} ${_ND_DETECTED_LIBC} PARENT_SCOPE) set(${_libc_name} ${_ND_DETECTED_LIBC} PARENT_SCOPE)
endif() endif()

View file

@ -623,6 +623,7 @@ declare -A pkg_find=(
declare -A pkg_distro_sdk=( declare -A pkg_distro_sdk=(
['alpine']="alpine-sdk" ['alpine']="alpine-sdk"
['centos']="kernel-headers"
['default']="NOTREQUIRED" ['default']="NOTREQUIRED"
) )