[U-Boot,v4] config.mk: fix -fstack-usage support test

Message ID 1381839065-26035-1-git-send-email-yamada.m@jp.panasonic.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Oct. 15, 2013, 12:11 p.m.
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 $?
    $ 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 $?

But I gave /dev/null as input, the compile always succeeds:

    $ bfin-uclinux-gcc -fstack-usage -S -xc /dev/null 
    $ echo $?
    $ bfin-uclinux-gcc -Werror -fstack-usage -S -xc /dev/null 
    $ echo $?

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


Masahiro Yamada Dec. 11, 2013, 11:17 a.m. | #1

Please supersed this.

I posted v5 which is rebased on Kbuild series.
("Switch over to real Kbuild", which conststs of 34 patch files)
I want to avoid a conflict with Kbuild series.

Best Regards
Masahiro Yamada


diff --git a/config.mk b/config.mk
index 3441387..8a82ab4 100644
--- a/config.mk
+++ b/config.mk
@@ -279,8 +279,9 @@  CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
 # Report stack usage if supported
-CFLAGS_STACK := $(call cc-option,-fstack-usage)
+ifeq ($(shell $(SHELL) $(SRCTREE)/scripts/gcc-stack-usage.sh $(CC)), y)
+	CFLAGS += -fstack-usage
 BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
diff --git a/scripts/gcc-stack-usage.sh b/scripts/gcc-stack-usage.sh
new file mode 100644
index 0000000..53eb10a
--- /dev/null
+++ b/scripts/gcc-stack-usage.sh
@@ -0,0 +1,18 @@ 
+# Test for gcc '-fstack-usage' support
+# Copyright (C) 2013, Masahiro Yamada <yamada.m@jp.panasonic.com>
+# SPDX-License-Identifier:	GPL-2.0+
+cat << "END" | $@ -Werror -fstack-usage -x c - -c -o $TMP >/dev/null 2>&1 \
+							&& echo "y"
+int main(void)
+	return 0;
+rm -f $TMP $TMP.su