xen: pass compiler flags via Xen-provided variables

Fix the method of passing compiler flags into the Xen build, which is
needed to fix compilation of hvmloader, a 32-bit firmware binary that is
required for Xen to be able to run HVM-mode guest VMs. It must not be
compiled with SSE compiler options enabled, so the Xen build clears
CFLAGS, which is a problem with _FORTIFY_SOURCE present in CC because
it must be paired with a compiler optimization flag that was in CFLAGS.
This change fixes the compilation failure that stated
 "_FORTIFY_SOURCE requires compiling with optimization (-O)".

32-bit ARM needs the TUNE_CCARGS to be retained as passed via CC
to ensure that configure is able to generate binaries for the
correct ABI, so is handled as a separate case.

Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
This commit is contained in:
Christopher Clark 2020-02-25 16:15:48 -08:00 committed by Bruce Ashfield
parent 7c4e062505
commit 64eb6f5595

View File

@ -867,15 +867,27 @@ export CROSS_COMPILE="${TARGET_PREFIX}"
# overide LDFLAGS to allow xen to build without: "x86_64-oe-linux-ld: unrecognized option '-Wl,-O1'"
export LDFLAGS=""
# Yocto injects -mfpmath=sse for some machine types into the CFLAGS which
# conflicts with -mno-sse so instead we strip -mfpmath=sse instead of
# patching the build to be ok with this
TUNE_CCARGS := "${@oe.utils.str_filter_out('-mfpmath=sse', '${TUNE_CCARGS}', d)}"
TUNE_CCARGS := "${@oe.utils.str_filter_out('-msse4.2', '${TUNE_CCARGS}', d)}"
# Pass through the Yocto distro compiler flags via the Xen-provided variables.
# Special handling:
# - Yocto supplies the _FORTIFY_SOURCE flag via CC/CPP/CXX but then passes the
# optimization -O via C*FLAGS which is problematic when the CFLAGS are cleared
# within the build because compilation fails with the compiler stating
# "_FORTIFY_SOURCE requires compiling with optimization (-O)".
# - Move HOST_CC_ARCH into the Xen-provided CFLAGS variables and keep
# TOOLCHAIN_OPTIONS set via CC: this enables hvmloader to be built correctly.
# It must not be compiled with SSE compiler options enabled and the Xen build
# explicitly clears CFLAGS to ensure that, so such options must not be passed
# in via the tool variable. hvmloader is required to run HVM-mode guest VMs.
CC="${CCACHE}${HOST_PREFIX}gcc ${TOOLCHAIN_OPTIONS}"
EXTRA_CFLAGS_XEN_CORE="${HOST_CC_ARCH} ${CFLAGS}"
EXTRA_CFLAGS_XEN_TOOLS="${HOST_CC_ARCH} ${CFLAGS}"
# 32-bit ARM needs the TUNE_CCARGS component of HOST_CC_ARCH to be passed
# in CC to ensure that configure can compile binaries for the right arch.
CC_arm="${CCACHE}${HOST_PREFIX}gcc ${TUNE_CCARGS} ${TOOLCHAIN_OPTIONS}"
EXTRA_CFLAGS_XEN_CORE_arm="${SECURITY_CFLAGS} ${CFLAGS}"
EXTRA_CFLAGS_XEN_TOOLS_arm="${SECURITY_CFLAGS} ${CFLAGS}"
# Supply the full set of compiler flags via the tool variables
# Yocto supplys _FORTIFY_SOURCE via CC/CPP/CXX but optimization -O via C*FLAGS
CC_append = " ${CFLAGS}"
# There are no Xen-provided variables for C++, so append to the tool variables:
CPP_append = " ${CPPFLAGS}"
CXX_append = " ${CXXFLAGS}"
@ -996,8 +1008,11 @@ do_configure() {
bbfatal "Unable to copy defconfig to .config"
fi
unset CFLAGS
# do configure
oe_runconf
oe_runconf EXTRA_CFLAGS_XEN_CORE="${EXTRA_CFLAGS_XEN_CORE}" \
EXTRA_CFLAGS_XEN_TOOLS="${EXTRA_CFLAGS_XEN_TOOLS}"
if [ ! -e ${STAGING_INCDIR}/bits/long-double-32.h ]; then
cp ${STAGING_INCDIR}/bits/long-double-64.h ${STAGING_INCDIR}/bits/long-double-32.h
fi