Fix for tasks example to compile when using kernal5_8 feature
When attempting to compile examples with Kernel v5.13, I was getting the following error
Compiling example-probes v0.1.0 (/Work/fly-io-coding-challenge/36800/redbpf/examples/example-probes)
warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
warning: ignoring --out-dir flag due to -o flag
error[E0609]: no field `__bindgen_anon_1` on type `bpf_iter_meta`
--> examples/example-probes/src/tasks/main.rs:12:31
|
12 | let seq_ptr = (*meta_ptr).__bindgen_anon_1.seq;
| ^^^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `_address`
For more information about this error, try `rustc --explain E0609`.
warning: `example-probes` (bin "tasks") generated 2 warnings
error: could not compile `example-probes` due to previous error; 2 warnings emitted
I was using the command:
cargo build --no-default-features --features llvm13,kernel5_8 --examples
This change allowed the tasks example to compile and execute for me -- although there may be a more appropriate fix?
@murrayh
what distro do you use? I wonder why struct bpf_iter_meta does not have the union field.
And #undef bpf_iter_meta does not work since bpf_iter_meta is not a macro defined constant.
My host operating system is Pop OS
Linux pop-os 5.13.0-7620-generic #20~1634827117~21.04~874b071-Ubuntu SMP Fri Oct 29 15:06:55 UTC x86_64 x86_64 x86_64 GNU/Linux
My docker container is Ubuntu 21
#
# docker build -f Dockerfile.muz-devenv -t muz-devenv --build-arg kernel_version=$(uname -r) .
#
FROM ubuntu:21.04
ARG kernel_version
# Essential setup
ENV DEBIAN_FRONTEND=noninteractive
RUN ln -fs /usr/share/zoneinfo/Australia/Melbourne /etc/localtime
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gpg \
gpg-agent \
tzdata \
wget \
;
# Rust with LLVM 13
RUN echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" > /etc/apt/sources.list.d/llvm-toolchain.list
RUN echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" >> /etc/apt/sources.list.d/llvm-toolchain.list
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libclang-13-dev \
libllvm13 \
llvm-13 \
llvm-13-dev \
llvm-13-runtime \
;
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf > rustup.sh \
&& sh rustup.sh -y \
--default-toolchain stable \
--profile minimal \
--no-modify-path \
&& rustup component add rustfmt \
&& rustup --version \
&& cargo --version \
&& rustc --version \
&& cargo install bindgen \
&& chmod a+w -R $CARGO_HOME \
&& rm -f rustup.sh
# Dependencies required to build redBPF
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bc \
bison \
clang-13 \
flex \
libelf-dev \
libssl-dev \
zlib1g-dev \
;
RUN /bin/bash -c " \
set -e ; \
KV=$kernel_version ; \
KV=\${KV%%-*} ; \
KV=\${KV%.0} ; \
wget -O ./linux-\${KV}.tar.gz https://www.kernel.org/pub/linux/kernel/v5.x/linux-\${KV}.tar.gz ; \
tar -xzf ./linux-\${KV}.tar.gz -C /usr/src/ ; \
ls -l /usr/src/linux-\${KV}/ ; \
rm ./linux-\${KV}.tar.gz ; \
"
RUN make -C /usr/src/linux-* defconfig
RUN make -C /usr/src/linux-* prepare
# Handy developer utilities
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ethtool \
gitk \
lsb-release \
net-tools \
sudo \
vim \
;
RUN wget https://github.com/watchexec/watchexec/releases/download/cli-v1.17.1/watchexec-1.17.1-x86_64-unknown-linux-gnu.deb \
&& dpkg -i ./watchexec-1.17.1-x86_64-unknown-linux-gnu.deb \
&& rm ./watchexec-1.17.1-x86_64-unknown-linux-gnu.deb
RUN wget https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb \
&& dpkg -i ./ripgrep_13.0.0_amd64.deb \
&& rm ./ripgrep_13.0.0_amd64.deb
I don't know why the bindings for struct bpf_iter_meta are generated incorrectly. I might be able to debug it, but I won't have time for that work for some weeks.
One thing I noticed is that gen_bindings.rs has probably 20 or 30 structs defined that only have the _address field as the only member -- they look obviously incorrect.
I'm glad to see you use Pop!_OS. I had been a Pop!_OS user until two months ago. The distro was pre-installed on my System76 oryx pro laptop.
Anyway, did you build RedBPF in your ubuntu 21 docker container?
And you probably specify KERNEL_SOURCE environment variable to the /usr/src/linux-${KV} when running the cargo build?
Perhaps the ${KV} is different from the host's kernel version 5.13.0-7620-generic?
Yes, ${KV} is 5.13.0 -- the original kernel source code which is different to Pop!_OS 5.13.0-7620-generic.
Intuitively though I would not expect this to impact the generation of bindings. Sure, if I try and link in the bindings and execute the application it might crash or do undefined things. But generating the rust <-> c bindings -- the running kernel shouldn't matter? Although If the kernel does expose some API introspection capabilities that would be some cool tech I would like to look into