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

2013-12-11 Thread Masahiro Yamada
Hi.

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

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


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

2013-10-15 Thread Masahiro Yamada
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 yamad...@jp.panasonic.com
Cc: Tom Rini tr...@ti.com
Cc: Michal Simek mon...@monstr.eu
Cc: Jeroen Hofstee jer...@myspectrum.nl
Cc: Albert ARIBAUD albert.u.b...@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

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) \
 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)%=%))
 
diff --git a/scripts/gcc-stack-usage.sh b/scripts/gcc-stack-usage.sh
new file mode 100644
index 000..53eb10a
--- /dev/null
+++ b/scripts/gcc-stack-usage.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Test for gcc '-fstack-usage' support
+# Copyright (C) 2013, Masahiro Yamada yamad...@jp.panasonic.com
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+TMP=${OBJTREE}/$$
+
+cat  END | $@ -Werror -fstack-usage -x c - -c -o $TMP /dev/null 21 \
+echo y
+int main(void)
+{
+   return 0;
+}
+END
+
+rm -f $TMP $TMP.su
-- 
1.8.1.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot