From 70bd69912ad2fb6e99271b418f87b98ebb36e0d8 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Mon, 17 Aug 2015 12:02:50 +0000 Subject: BaseTools GCC: prevent unaligned memory accesses on ARM GCC 4.6 In GCC 4.7, a feature was added to the ARM backend that allows unaligned loads and stores to be emitted. Since it is enabled by default on ARMv6 and later CPUs, and since such code is not suitable in our case (i.e., bare metal code), we must disable it by passing the -mno-unaligned-access option if we are using GCC 4.7 or later. However, this particular feature and its enabling by default have been backported to version 4.6 by Linaro. Since the Linaro toolchains are widely used for ARM development, and also shipped by distros such as Ubuntu, we should disable the feature on version 4.6 as well. Unfortunately, since the upstream version does not support the feature, it also does not understand the -mno-unaligned-access option. Since GCC sets the builtin #define __ARM_FEATURE_UNALIGNED to 1 when -munaligned-access is in effect, we can force the build to fail in this case by passing -D__ARM_FEATURE_UNALIGNED=0 on the GCC command line. This will produce the following error message: :0:0: error: "__ARM_FEATURE_UNALIGNED" redefined [-Werror] :0:0: note: this is the location of the previous definition and terminate the build. This patch may cause some existing builds to fail, but they will be builds that were previously at risk of unexpected runtime exceptions. Those builds can also easily be switched to the GCC47 profile instead, generating safe binaries. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18228 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Conf/tools_def.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BaseTools') diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 859fbe14ad..dd44de0335 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -4255,8 +4255,8 @@ DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS) *_GCC46_ARM_RC_FLAGS = DEF(GCC_ARM_RC_FLAGS) *_GCC46_ARM_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS) - DEBUG_GCC46_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -O0 -RELEASE_GCC46_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -Wno-unused-but-set-variable + DEBUG_GCC46_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -D__ARM_FEATURE_UNALIGNED=0 -O0 +RELEASE_GCC46_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -D__ARM_FEATURE_UNALIGNED=0 -Wno-unused-but-set-variable #################################################################################### # -- cgit v1.2.3