From: Viktor Malik <vma...@redhat.com>

redhat/spec: Do not use source fortification for selftests

JIRA: https://issues.redhat.com/browse/RHEL-48593

Upstream status: RHEL-only

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: Viktor Malik <vma...@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,19 @@ 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 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
 
+# 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/3958

-- 
_______________________________________________
kernel mailing list -- kernel@lists.fedoraproject.org
To unsubscribe send an email to kernel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/kernel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to