From: Gregory Bell on gitlab.com Merge Request: https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3956
BPF selftests build fails b/c some compiler and linker options (namely -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 and -specs=/usr/lib/rpm/redhat/redhat-hardened-ld) are not passed to sub-makes for bpftool and libbpf. This, for instance, causes that libbpf.a is not build as PIE and other binaries cannot link against it.
Fix the problem by passing the default compiler/linker options via EXTRA_CFLAGS/EXTRA_LDFLAGS to the selftests build. They are then correctly propagated to sub-makes.
Signed-off-by: Gregory Bell grbell@redhat.com
--- redhat/kernel.spec.template | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)
From: Gregory Bell grbell@redhat.com
redhat/spec: Fix BPF selftests build with PIE
BPF selftests build fails b/c some compiler and linker options (namely -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 and -specs=/usr/lib/rpm/redhat/redhat-hardened-ld) are not passed to sub-makes for bpftool and libbpf. This, for instance, causes that libbpf.a is not build as PIE and other binaries cannot link against it.
Fix the problem by passing the default compiler/linker options via EXTRA_CFLAGS/EXTRA_LDFLAGS to the selftests build. They are then correctly propagated to sub-makes.
Signed-off-by: Gregory Bell grbell@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3254,7 +3254,7 @@ pushd tools/testing/selftests %endif
%{log_msg "main selftests compile"} -%{make} %{?_smp_mflags} ARCH=$Arch V=1 TARGETS="bpf cgroup kmod mm net net/forwarding net/mptcp net/netfilter net/packetdrill tc-testing memfd drivers/net/bonding iommu cachestat pid_namespace rlimits timens pidfd" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install +%{make} %{?_smp_mflags} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" EXTRA_LDFLAGS="%{__global_ldflags}" ARCH=$Arch V=1 TARGETS="bpf cgroup mm net net/forwarding net/mptcp netfilter tc-testing memfd drivers/net/bonding iommu cachestat" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install
%ifarch %{klptestarches} # kernel livepatching selftest test_modules will build against
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3956
From: Gregory Bell grbell@redhat.com
redhat/spec: Do not use source fortification for selftests
Some selftests (e.g. BPF) fail to build with the _FORTIFY_SOURCE option defined. Since selftests are not shipped, disable source fortification for them. This is done by undefining the %{_fortify_level} RPM macro and resetting CFLAGS to %{build_flags}.
Similarly, we reset the source fortification after selftests are built.
Signed-off-by: Gregory Bell grbell@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3254,8 +3254,20 @@ pushd tools/testing/selftests %endif
%{log_msg "main selftests compile"} + +# Some selftests (especially bpf) do not build with source fortification. +# Since selftests are not shipped, disable source fortification for them. +%global _fortify_level_bak %{_fortify_level} +%undefine _fortify_level +export CFLAGS="%{build_cflags}" + %{make} %{?_smp_mflags} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_CXXFLAGS="${RPM_OPT_FLAGS}" EXTRA_LDFLAGS="%{__global_ldflags}" ARCH=$Arch V=1 TARGETS="bpf cgroup mm net net/forwarding net/mptcp netfilter tc-testing memfd drivers/net/bonding iommu cachestat" SKIP_TARGETS="" $force_targets INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" install
+ +# Restore the original level of source fortification +%define _fortify_level %{_fortify_level_bak} +export CFLAGS="%{build_cflags}" + %ifarch %{klptestarches} # kernel livepatching selftest test_modules will build against # /lib/modules/$(shell uname -r)/build tree unless KDIR is set
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3956
From: Gregory Bell grbell@redhat.com
redhat/spec: Add libxml2-devel dependency for selftests build
The BPF selftests build requires libxml2.
Signed-off-by: Gregory Bell grbell@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -802,7 +802,7 @@ BuildRequires: clang llvm-devel fuse-devel zlib-devel binutils-devel python3-doc %ifarch x86_64 riscv64 BuildRequires: lld %endif -BuildRequires: libcap-devel libcap-ng-devel rsync libmnl-devel +BuildRequires: libcap-devel libcap-ng-devel rsync libmnl-devel libxml2-devel BuildRequires: numactl-devel %endif BuildConflicts: rhbuildsys(DiskFree) < 500Mb
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3956
From: Gregory Bell grbell@redhat.com
redhat/spec: Bypass check-rpaths for kselftests/bpf/urandom_read
The urandom_read binary doesn't pass the check-rpaths check and upstream refuses to fix it. So, we save it to buildroot_unstripped and delete it so it will be hidden from check-rpaths and will automatically get restored later.
Signed-off-by: Gregory Bell grbell@redhat.com
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template index blahblah..blahblah 100644 --- a/redhat/kernel.spec.template +++ b/redhat/kernel.spec.template @@ -3292,6 +3292,15 @@ for dir in bpf bpf/no_alu32 bpf/progs; do done %buildroot_save_unstripped "usr/libexec/kselftests/bpf/test_progs" %buildroot_save_unstripped "usr/libexec/kselftests/bpf/test_progs-no_alu32" + +# The urandom_read binary doesn't pass the check-rpaths check and upstream +# refuses to fix it. So, we save it to buildroot_unstripped and delete it so it +# will be hidden from check-rpaths and will automatically get restored later. +%buildroot_save_unstripped "usr/libexec/kselftests/bpf/urandom_read" +%buildroot_save_unstripped "usr/libexec/kselftests/bpf/no_alu32/urandom_read" +rm -f %{buildroot}/usr/libexec/kselftests/bpf/urandom_read +rm -f %{buildroot}/usr/libexec/kselftests/bpf/no_alu32/urandom_read + popd %{log_msg "end build selftests"} %endif
-- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3956
kernel@lists.fedoraproject.org