Skip to content

Commit

Permalink
kernel-image: build a btf file
Browse files Browse the repository at this point in the history
Older kernels (e.g., 4.19) do not support /sys/kernel/btf/, so just
generate and add the btf file  into the kernel images.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Aug 4, 2022
1 parent e83dfbd commit 809ab25
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dockerfiles/kernel-image
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN lvh kernels --dir . fetch 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . configure 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . build 2>&1 ${KERNEL_VER}

COPY scripts/generate-btf.sh /tmp/
RUN /tmp/generate-btf.sh /data/kernels/${KERNEL_VER}/tar-install

FROM busybox
ARG KERNEL_VER=bpf-next
COPY --from=builder /data/kernels/${KERNEL_VER}/tar-install /data/kernels/${KERNEL_VER}
3 changes: 3 additions & 0 deletions dockerfiles/kernel-image-4.19
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN lvh kernels --dir . fetch 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . configure 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . build 2>&1 ${KERNEL_VER}

COPY scripts/generate-btf.sh /tmp/
RUN /tmp/generate-btf.sh /data/kernels/${KERNEL_VER}/tar-install

FROM busybox
ARG KERNEL_VER=4.19
COPY --from=builder /data/kernels/${KERNEL_VER}/tar-install /data/kernels/${KERNEL_VER}
3 changes: 3 additions & 0 deletions dockerfiles/kernel-image-5.10
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN lvh kernels --dir . fetch 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . configure 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . build 2>&1 ${KERNEL_VER}

COPY scripts/generate-btf.sh /tmp/
RUN /tmp/generate-btf.sh /data/kernels/${KERNEL_VER}/tar-install

FROM busybox
ARG KERNEL_VER=5.10
COPY --from=builder /data/kernels/${KERNEL_VER}/tar-install /data/kernels/${KERNEL_VER}
3 changes: 3 additions & 0 deletions dockerfiles/kernel-image-5.4
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN lvh kernels --dir . fetch 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . configure 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . build 2>&1 ${KERNEL_VER}

COPY scripts/generate-btf.sh /tmp/
RUN /tmp/generate-btf.sh /data/kernels/${KERNEL_VER}/tar-install

FROM busybox
ARG KERNEL_VER=5.4
COPY --from=builder /data/kernels/${KERNEL_VER}/tar-install /data/kernels/${KERNEL_VER}
3 changes: 3 additions & 0 deletions dockerfiles/kernel-image-bpf-next
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN lvh kernels --dir . fetch 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . configure 2>&1 ${KERNEL_VER}
RUN lvh kernels --dir . build 2>&1 ${KERNEL_VER}

COPY scripts/generate-btf.sh /tmp/
RUN /tmp/generate-btf.sh /data/kernels/${KERNEL_VER}/tar-install

FROM busybox
ARG KERNEL_VER=bpf-next
COPY --from=builder /data/kernels/${KERNEL_VER}/tar-install /data/kernels/${KERNEL_VER}
20 changes: 20 additions & 0 deletions scripts/generate-btf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -e

if [ -z $1 ]; then
echo "Usage: $0 <kernel_install_dir>"
exit 1
fi

dir="$1"
bootdir="$dir/boot"

for fname in $bootdir/vmlinux-*; do
kernel=$(basename $fname)
ver=$(echo $kernel | sed -e 's/vmlinux-//')
outfile="$bootdir/kernel-${ver}.btf"
rm -f $outfile
pahole --btf_encode_detached=$outfile $fname
echo "Generated $outfile"
done

0 comments on commit 809ab25

Please sign in to comment.