config.mk: fix -fstack-usage support test
PATCH v4 1/1 config.mk: fix -fstack-usage support test
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,...) .
---
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 $?
1But 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 $?
0Above 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
config.mk +3 -2
@@ -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)%=%))
scripts/gcc-stack-usage.sh new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/sh +# Test for gcc '-fstack-usage' support +# Copyright (C) 2013, Masahiro Yamada <[email protected]> +# +# 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
Signature · 1 line
1.8.1.2
PATCH v4 1/1 config.mk: fix -fstack-usage support test
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