Whamcloud - gitweb
LU-12269 build: fix hardened builds in rpm spec file 82/34882/6
authorBen Menadue <ben.menadue@anu.edu.au>
Thu, 16 May 2019 04:42:37 +0000 (14:42 +1000)
committerOleg Drokin <green@whamcloud.com>
Wed, 29 May 2019 04:25:11 +0000 (04:25 +0000)
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 <ben.menadue@anu.edu.au>
Change-Id: I9b4ba830bf63838fd88ef1bae5dd10dff2109a1d
Reviewed-on: https://review.whamcloud.com/34882
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/Makefile.am
lustre.spec.in
lustre/utils/Makefile.am

index 97c52d8..fdd0918 100644 (file)
@@ -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
 
index 8782a91..8df403b 100644 (file)
@@ -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
index e795970..7726f27 100644 (file)
@@ -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