Open hhoffstaette opened 2 months ago
Had a few spare cycles to look into this since it didn't seem too difficult.
The mismatched typedefs are a completely valid C++ complaint and easily fixed:
diff --git a/examples/cpp/pyperf/PyPerfUtil.cc b/examples/cpp/pyperf/PyPerfUtil.cc
index 312d0181..329dcf88 100644
--- a/examples/cpp/pyperf/PyPerfUtil.cc
+++ b/examples/cpp/pyperf/PyPerfUtil.cc
@@ -25,8 +25,8 @@
namespace ebpf {
namespace pyperf {
-extern OffsetConfig kPy36OffsetConfig;
-extern std::string PYPERF_BPF_PROGRAM;
+extern const OffsetConfig kPy36OffsetConfig;
+extern const std::string PYPERF_BPF_PROGRAM;
const static int kPerfBufSizePages = 32;
"extern const" might seem a bit weird at first but works correctly, provided that the symbol is eventually defined once - which is the case here.
The last warning turns out to be a problem with cmake generating a likely mismatching compat/linux/bpf.h
even when the build is explicitly told to use an external libbpf and accompanying headers. This seems helpful at first, but is unexpectedly wrong: when I tell the build to use an external libbpf/uapi, I really mean it and don't want random mystery meat from the vendored libbpf snapshot. The generated header contains a symbol that is not in any released libbpf as of today, hence the mismatch.
Removing the section in src/cc/CMakeLists.txt
fixes it:
diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
index 104eff0e..486bedcb 100644
--- a/src/cc/CMakeLists.txt
+++ b/src/cc/CMakeLists.txt
@@ -18,12 +18,6 @@ endif (LIBDEBUGINFOD_FOUND AND ENABLE_LIBDEBUGINFOD)
# todo: if check for kernel version
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
include_directories(${LIBBPF_INCLUDE_DIRS})
- # create up-to-date linux/bpf.h from virtual_bpf.h (remove string wrapper);
- # when libbpf is built as a submodule we use its version of linux/bpf.h
- # so this does similar for the libbpf package, removing reliance on the
- # system uapi header which can be out of date.
- execute_process(COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/compat/linux && grep -ve '\\*\\*\\*\\*' virtual_bpf.h > bpf.h")
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat)
else()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
With these changes the PyPerf example builds perfectly fine against an external libbpf using LTO.
Gentoo found a problem when building with LTO + -Werror=odr, see here for the bug.
I have reproduced this with 0.31.0 and despite the fact that PyPerf is "only" an example, I am reporting it since it often indicates header confusion/mixups.