From: Ben Menadue Date: Thu, 16 May 2019 04:42:37 +0000 (+1000) Subject: LU-12269 build: fix hardened builds in rpm spec file X-Git-Tag: 2.12.54~37 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=5270583ae6e436e9e7ae0199312e7f50365744af LU-12269 build: fix hardened builds in rpm spec file The hardened build configure on RHEL8 has a quoted string with spaces in it, and this breaks the construction of %eval_configure on lustre.spec.in - the quotes end up in the wrong place. Moreover, the hardened build flags are only for user-space code, and breaks kernel code compilation on RHEL 8.0 (it adds -fPIE, which isn't valid for kernel code. This patch stores the %build_cflags and %build_ldflags from rpmbuild as environment variables before turning hardened build off to allow the kernel code to build. These environment variables are used in the lnet/utils and lustre/utils Makefiles so that the user-space code there gets the benefit of any system-specific RPM build flag (such as hardened builds). For RHEL7 on PPC64 we then also need to define the C macro __SANE_USERSPACE_TYPES__ so that __s64 and __u64 are long long instead of the default long - otherwise the build will fail with a format string error on this platform because Lustre uses %ll when printing/scanning __s64/__u64. The environment variables (UTILS_CFLAGS and UTILS_LDFLAGS) could also be used for a standalone, non-RPM build to pass flags to the user-space code, with the usual CFLAGS and LDFLAGS still used for kernel code. Signed-off-by: Ben Menadue Change-Id: I9b4ba830bf63838fd88ef1bae5dd10dff2109a1d Reviewed-on: https://review.whamcloud.com/34882 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Minh Diep Reviewed-by: Jian Yu Reviewed-by: Li Dongyang Reviewed-by: Oleg Drokin --- diff --git a/lnet/utils/Makefile.am b/lnet/utils/Makefile.am index 97c52d8..fdd0918 100644 --- a/lnet/utils/Makefile.am +++ b/lnet/utils/Makefile.am @@ -32,8 +32,8 @@ # Lustre is a trademark of Sun Microsystems, Inc. # -AM_CFLAGS := -fPIC -D_GNU_SOURCE -AM_LDFLAGS := -L. +AM_CFLAGS := -fPIC -D_GNU_SOURCE $(UTILS_CFLAGS) +AM_LDFLAGS := -L. $(UTILS_LDFLAGS) SUBDIRS = lnetconfig diff --git a/lustre.spec.in b/lustre.spec.in index 8782a91..8df403b 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -310,9 +310,30 @@ ln lnet/ChangeLog ChangeLog-lnet %build # Set an explicit path to our Linux tree, if we can. cd $RPM_BUILD_DIR/lustre-%{version} -# override %optflags so that the vendor's overzealous flags don't create -# build failures + +# Store the CFLAGS and LDFLAGS that would normally be used in the UTILS_CFLAGS +# and UTILS_LDFLAGS environment variables so that we use can them when compiling +# the user-space code in lustre/utils and lnet/utils. As of RHEL 8.0, the +# __global_* variants are deprecated in favour of build_cflags, etc. If neither +# style is available (e.g. on SLES), then these just end up as empty strings. +export UTILS_CFLAGS="%{?build_cflags:%{build_cflags}}%{!?build_cflags:%{?__global_cflags:%{__global_cflags}}}" +export UTILS_LDFLAGS="%{?build_ldflags:%{build_ldflags}}%{!?build_ldflags:%{?__global_ldflags:%{__global_ldflags}}}" + +# RHEL7 on PPC64 needs __SANE_USERSPACE_TYPES__ defined so that __s64 and __u64 +# are presented to user-land as long long instead of long long. Without this it +# will fail the format check whenever such a variable is printed. +%if 0%{?rhel} +%ifarch ppc64 +export UTILS_CFLAGS="${UTILS_CFLAGS} -D__SANE_USERSPACE_TYPES__=1" +%endif +%endif + +# Disable any hardening or annotation since this doesn't make sense for +# kernel code, and reset %optflags so that the vendor's overzealous flags don't +# create build failures. %define optflags -g -O2 -Werror +%undefine _annotated_build +%undefine _hardened_build CONFIGURE_ARGS="%{?configure_args}" if [ -n "$CONFIGURE_ARGS" ]; then diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index e795970..7726f27 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -1,7 +1,8 @@ # Administration utilities Makefile AM_CFLAGS := -fPIC -D_GNU_SOURCE \ - -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLUSTRE_UTILS=1 + -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLUSTRE_UTILS=1 $(UTILS_CFLAGS) +AM_LDFLAGS := $(UTILS_LDFLAGS) if TESTS EXTRA_PROGRAMS = wirecheck