From 49a8de7ae377674f28b6caf649a56c997a3c780b Mon Sep 17 00:00:00 2001 From: Patrice Buriez Date: Sun, 9 Apr 2017 02:44:48 +0200 Subject: [PATCH] build: use -O2 instead of -Os for ARC with SDK 0.9 This is intended as a temporary fix for ZEP-1882. Investigation for this bug has shown that the current SDK 0.9 compiler for ARC generates incorrect code under -Os optimization level. Kuo-Lang Tseng found out that SDK 0.8.2 does not have this issue, and that lowering optimization level to -O2 fixes the issue with SDK 0.9. Juro Bystricky is working on an updated SDK with ARC GCC 6.3.0, but there are still problems with it, so he also suggested to use -O2 in the meantime. Instead of blindly setting -O2 for all toolchains and architectures, let Makefile.toolchain.zephyr make the decision for ARC and 0.9 only. Tested with hello_world, CONFIG_ADC=y and BOARD=arduino_101_sss. Jira: ZEP-1882 Change-Id: Ifde2e3950c9d93eed8982149805acfda9d13a94f Signed-off-by: Patrice Buriez --- Makefile | 7 +++++-- scripts/Makefile.toolchain.zephyr | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 98081009cd0..954bd7d4287 100644 --- a/Makefile +++ b/Makefile @@ -599,9 +599,9 @@ ARCH = $(subst $(DQUOTE),,$(CONFIG_ARCH)) export ARCH ifeq ($(CONFIG_DEBUG),y) -KBUILD_CFLAGS += -Og +KBUILD_CFLAGS_OPTIMIZE := -Og else -KBUILD_CFLAGS += -Os +KBUILD_CFLAGS_OPTIMIZE := -Os endif ifdef ZEPHYR_GCC_VARIANT @@ -613,6 +613,9 @@ $(if $(CROSS_COMPILE),, \ endif endif +# Let Makefile.toolchain adjust optimization level +KBUILD_CFLAGS += $(KBUILD_CFLAGS_OPTIMIZE) + -include $(srctree)/ext/Makefile -include $(srctree)/lib/Makefile diff --git a/scripts/Makefile.toolchain.zephyr b/scripts/Makefile.toolchain.zephyr index faea0b1a5d2..8aa81ddae25 100644 --- a/scripts/Makefile.toolchain.zephyr +++ b/scripts/Makefile.toolchain.zephyr @@ -36,6 +36,16 @@ ifeq ($(SDK_VERSION),0.8.2) TOOLCHAIN_ARCH := i686 endif +# TODO remove once we have a replacement for 0.9 that fixes ZEP-1882 +# See https://jira.zephyrproject.org/browse/ZEP-1882 +ifeq ($(SDK_VERSION),0.9) +ifeq ($(ARCH),arc) +ifneq ($(CONFIG_DEBUG),y) +KBUILD_CFLAGS_OPTIMIZE := -O2 +endif +endif +endif + ifeq ($(HOST_OS),MINGW) TOOLCHAIN_HOME = ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/i686-pokysdk-mingw32 else