bcc
bcc copied to clipboard
arithmetic on a pointer to an incomplete type 'ebpf::USDT'
Summary:
When including bcc/BPF.h
there's a compilation error regarding arithmetic on a pointer to an incomplete type 'ebpf::USDT'.
Upon inspection of the bcc/BPF.h
source file, I verified that it indeed forward declares class USDT
then creates a std::vector
of it somewhere inside class BPF
. The class definition for USDT
only comes later in the file. The implementation of std::vector
itself is the one responsible for the pointer arithmetic.
The fix for this issue seems straightforward: swap the order of the class declarations in the bcc/BPF.h
file, after which things compile successfully.
bcc
version
This has been observed in bcc
v0.25.0
.
Environment:
Clang 14.0.6
with libstdc++-12-dev
version 12.1.0-8
under Debian Sid. Linux kernel version: Linux bst 5.18.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.5-1 (2022-06-16) x86_64 GNU/Linux
.
Error message:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/functional:62:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/vector:64:
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:367:35: error: arithmetic on a pointer to an incomplete type 'ebpf::USDT'
_M_impl._M_end_of_storage - _M_impl._M_start);
~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:526:7: note: in instantiation of member function 'std::_Vector_base<ebpf::USDT, std::allocator<ebpf::USDT>>::~_Vector_base' requested here
vector() = default;
^
/usr/local/include/bcc/BPF.h:59:50: note: in defaulted default constructor for 'std::vector<ebpf::USDT>' first required here
const std::vector<USDT>& usdt = {});
^
/usr/local/include/bcc/BPF.h:43:7: note: forward declaration of 'ebpf::USDT'
class USDT;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Compiler flags
/usr/bin/c++ -I/src -I/src/out -D__STRICT_ANSI__ -std=c++2b -static -Wall -Werror -Wno-bitwise-instead-of-logical -Wno-comment -Wno-gnu-string-literal-operator-template -Wno-overlength-strings -Wno-pointer-bool-conversion -Wshadow-field-in-constructor -Wshadow-field-in-constructor-modified -Wshadow-ivar -Wshadow-uncaptured-local -Wundef -x c++ -save-temps=obj -ggdb3 -O1 -Wno-unused-const-variable -Wno-unused-local-typedef -Wno-unused-private-field -ferror-limit=1 -o kprobe.cpp.o -c kprobe.cpp
Compiler version:
$ /usr/bin/c++ --version
clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin