]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools GCC: prevent unaligned memory accesses on ARM GCC 4.6
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 17 Aug 2015 12:02:50 +0000 (12:02 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Mon, 17 Aug 2015 12:02:50 +0000 (12:02 +0000)
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:

  <command-line>:0:0: error: "__ARM_FEATURE_UNALIGNED" redefined [-Werror]
  <built-in>: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 <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18228 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Conf/tools_def.template

index 859fbe14ad597803634e0b33a409629b77c4d5ae..dd44de033519e26115fb47d2b8a522536589b160 100644 (file)
@@ -4255,8 +4255,8 @@ DEFINE GCC49_AARCH64_ASLDLINK_FLAGS  = DEF(GCC48_AARCH64_ASLDLINK_FLAGS)
 *_GCC46_ARM_RC_FLAGS             = DEF(GCC_ARM_RC_FLAGS)\r
 *_GCC46_ARM_VFRPP_FLAGS          = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS)\r
 \r
-  DEBUG_GCC46_ARM_CC_FLAGS       = DEF(GCC46_ARM_CC_FLAGS) -O0\r
-RELEASE_GCC46_ARM_CC_FLAGS       = DEF(GCC46_ARM_CC_FLAGS) -Wno-unused-but-set-variable\r
+  DEBUG_GCC46_ARM_CC_FLAGS       = DEF(GCC46_ARM_CC_FLAGS) -D__ARM_FEATURE_UNALIGNED=0 -O0\r
+RELEASE_GCC46_ARM_CC_FLAGS       = DEF(GCC46_ARM_CC_FLAGS) -D__ARM_FEATURE_UNALIGNED=0 -Wno-unused-but-set-variable\r
 \r
 ####################################################################################\r
 #\r