]> git.proxmox.com Git - mirror_edk2.git/commit
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)
commit70bd69912ad2fb6e99271b418f87b98ebb36e0d8
treefe23c92ac59412aa84f60cb23e6ec6d8f96c9655
parent099bff5def30b277157b2387d5d910e2ad14f84e
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:

  <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