Skip to content

Commit a19ed07

Browse files
committed
samples/bpf: fix build
JIRA: https://issues.redhat.com/browse/RHEL-70466 Upstream Status: RHEL Only commit 9ea5b2d945e7d5fe6daffd766520dfb1fb6b5974 Author: Gregory Bell <grbell@redhat.com> Date: Wed Apr 2 12:21:58 2025 -0400 samples/bpf: fix build Moving bootstrap bpftool build into a function then pass bootstrap bpftool to samples/bpf Makefile instead of rebuilding during the samples/bpf make process. If bpftool is not already built then build right before samples/bpf build and pass to samples/bpf. Always pass vmlinux.h to samples/bpf by setting RPM_VMLINUX_H variable depending on current build. If the kernel is built with debuginfo it is located at RPM_BUILD_ROOT/DevelDir/vmlinux.h. In the case of tools only build it is at DevelDir/vmlinux.h Signed-off-by: Gregory Bell <grbell@redhat.com> Signed-off-by: Gregory Bell <grbell@redhat.com>
1 parent 554dcad commit a19ed07

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

redhat/kernel.spec.template

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,13 @@ InitBuildVars() {
22202220
fi
22212221
}
22222222

2223+
#Build bootstrap bpftool
2224+
BuildBpftool(){
2225+
export BPFBOOTSTRAP_CFLAGS=$(echo "%{__global_compiler_flags}" | sed -r "s/\-specs=[^\ ]+\/redhat-annobin-cc1//")
2226+
export BPFBOOTSTRAP_LDFLAGS=$(echo "%{__global_ldflags}" | sed -r "s/\-specs=[^\ ]+\/redhat-annobin-cc1//")
2227+
CFLAGS="" LDFLAGS="" make EXTRA_CFLAGS="${BPFBOOTSTRAP_CFLAGS}" EXTRA_CXXFLAGS="${BPFBOOTSTRAP_CFLAGS}" EXTRA_LDFLAGS="${BPFBOOTSTRAP_LDFLAGS}" %{?make_opts} %{?clang_make_opts} V=1 -C tools/bpf/bpftool bootstrap
2228+
}
2229+
22232230
BuildKernel() {
22242231
%{log_msg "BuildKernel for $4"}
22252232
MakeTarget=$1
@@ -2953,10 +2960,7 @@ BuildKernel() {
29532960
if [ "$Variant" != "zfcpdump" ]; then
29542961
%{log_msg "Build the bootstrap bpftool to generate vmlinux.h"}
29552962
# Build the bootstrap bpftool to generate vmlinux.h
2956-
export BPFBOOTSTRAP_CFLAGS=$(echo "%{__global_compiler_flags}" | sed -r "s/\-specs=[^\ ]+\/redhat-annobin-cc1//")
2957-
export BPFBOOTSTRAP_LDFLAGS=$(echo "%{__global_ldflags}" | sed -r "s/\-specs=[^\ ]+\/redhat-annobin-cc1//")
2958-
CFLAGS="" LDFLAGS="" make EXTRA_CFLAGS="${BPFBOOTSTRAP_CFLAGS}" EXTRA_CXXFLAGS="${BPFBOOTSTRAP_CFLAGS}" EXTRA_LDFLAGS="${BPFBOOTSTRAP_LDFLAGS}" %{?make_opts} %{?clang_make_opts} V=1 -C tools/bpf/bpftool bootstrap
2959-
2963+
BuildBpftool
29602964
tools/bpf/bpftool/bootstrap/bpftool btf dump file vmlinux format c > $RPM_BUILD_ROOT/$DevelDir/vmlinux.h
29612965
fi
29622966
%endif
@@ -3201,7 +3205,10 @@ pushd tools/tracing/rtla
32013205
popd
32023206
%endif
32033207

3204-
if [ -f $DevelDir/vmlinux.h ]; then
3208+
#set RPM_VMLINUX_H
3209+
if [ -f $RPM_BUILD_ROOT/$DevelDir/vmlinux.h ]; then
3210+
RPM_VMLINUX_H=$RPM_BUILD_ROOT/$DevelDir/vmlinux.h
3211+
elif [ -f $DevelDir/vmlinux.h ]; then
32053212
RPM_VMLINUX_H=$DevelDir/vmlinux.h
32063213
fi
32073214
echo "${RPM_VMLINUX_H}" > ../vmlinux_h_path
@@ -3222,8 +3229,13 @@ if [ ! -f include/generated/autoconf.h ]; then
32223229
%{make} %{?_smp_mflags} modules_prepare
32233230
fi
32243231

3232+
# Build BPFtool for samples/bpf
3233+
if [ ! -f tools/bpf/bpftool/bootstrap/bpftool ]; then
3234+
BuildBpftool
3235+
fi
3236+
32253237
%{log_msg "build samples/bpf"}
3226-
%{make} %{?_smp_mflags} EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" ARCH=$Arch V=1 M=samples/bpf/ VMLINUX_H="${RPM_VMLINUX_H}" || true
3238+
%{make} %{?_smp_mflags} EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" ARCH=$Arch BPFTOOL=$(pwd)/tools/bpf/bpftool/bootstrap/bpftool V=1 M=samples/bpf/ VMLINUX_H="${RPM_VMLINUX_H}" || true
32273239

32283240
pushd tools/testing/selftests
32293241
# We need to install here because we need to call make with ARCH set which

0 commit comments

Comments
 (0)