@@ -279,8 +279,9 @@ CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
CFLAGS += $(CFLAGS_WARN)
# Report stack usage if supported
-CFLAGS_STACK := $(call cc-option,-fstack-usage)
-CFLAGS += $(CFLAGS_STACK)
+ifeq ($(shell $(SHELL) $(SRCTREE)/scripts/gcc-stack-usage.sh $(CC)), y)
+ CFLAGS += -fstack-usage
+endif
BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
new file mode 100644
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Test for gcc '-fstack-usage' support
+# Copyright (C) 2013, Masahiro Yamada <yamada.m@jp.panasonic.com>
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+TMP=${OBJTREE}/"$$"
+
+cat << "END" | $@ -Werror -fstack-usage -x c - -c -o $TMP >/dev/null 2>&1 \
+ && echo "y"
+int main(void)
+{
+ return 0;
+}
+END
+
+rm -f $TMP $TMP.su
If -fstack-usage option is given for such architecures that do not support it, gcc displays a warning message but still exits with status 0. This commit adds a new script to test -fstack-usage support because we cannot rely on $(call cc-option,...) . Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Cc: Tom Rini <trini@ti.com> Cc: Michal Simek <monstr@monstr.eu> Cc: Jeroen Hofstee <jeroen@myspectrum.nl> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net> --- Change for v4 - Drop executable permission of scripts/gcc-stack-usage.sh - Fix commit log - Add the rationale below --- Currently gcc does not seem to support -fstack-usage option for some targets, such as blackfin, m68k etc. If -fstack-usage option is given for those targets, gcc displays a warning message as follows: warning: -fstack-usage not supported for this target [enabled by default] But it still exits with status 0. So, $(call cc-option,-fstack-usage) does not work as we expect because cc-option sees exit status to judge whether the given option is supported or not. Adding -Werror option to cc-option function does not work either because gcc always succeeds in compiling /dev/null input even if -fstack-usage is unsupported. I confirmed this like follows. If I gave a real C file as input, the compile failed: $ cat test.c int test(void) { return 0; } $ bfin-uclinux-gcc -fstack-usage -S -xc test.c test.c: In function 'test': test.c:4:1: warning: -fstack-usage not supported for this target [enabled by default] $ echo $? 0 $ bfin-uclinux-gcc -fstack-usage -Werror -S -xc test.c test.c: In function 'test': test.c:4:1: error: -fstack-usage not supported for this target [-Werror] cc1: all warnings being treated as errors $ echo $? 1 But I gave /dev/null as input, the compile always succeeds: $ bfin-uclinux-gcc -fstack-usage -S -xc /dev/null $ echo $? 0 $ bfin-uclinux-gcc -Werror -fstack-usage -S -xc /dev/null $ echo $? 0 Above means we can detect -fstack-usage support by providing -Werror and -fstack-usage option for the real C source code. But describing all of them in Makefile is not smart, I think. To keep makefile cleaner, I created a new script file 'scripts/gcc-stack-usage.sh' and pushed dirty stuff into it. This is the way Linux Kernel often uses. For example, refer - scripts/gcc-goto.sh - scritps/gcc-version.sh etc. of Linux Kernel. config.mk | 5 +++-- scripts/gcc-stack-usage.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 scripts/gcc-stack-usage.sh