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.
This patch is back-ported from the following one:
Lustre-commit:
5270583ae6e436e9e7ae0199312e7f50365744af
Lustre-change: https://review.whamcloud.com/34882
Signed-off-by: Ben Menadue <ben.menadue@anu.edu.au>
Change-Id: I9b4ba830bf63838fd88ef1bae5dd10dff2109a1d
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/35161
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
# 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
%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
# 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