From patchwork Tue Oct 15 12:11:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 283619 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id DC5702C00AC for ; Tue, 15 Oct 2013 23:12:19 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BD7424A0A9; Tue, 15 Oct 2013 14:12:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gv5DnZZRnIA4; Tue, 15 Oct 2013 14:12:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1B0A34A09B; Tue, 15 Oct 2013 14:12:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B84FB4A09D for ; Tue, 15 Oct 2013 14:11:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6puAQIEVDnSD for ; Tue, 15 Oct 2013 14:11:46 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by theia.denx.de (Postfix) with ESMTP id 824414A099 for ; Tue, 15 Oct 2013 14:11:37 +0200 (CEST) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile12) with ESMTP id r9FCBMIM022134; Tue, 15 Oct 2013 21:11:22 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili13) with ESMTP id r9FCBMJ22024; Tue, 15 Oct 2013 21:11:22 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi13) id r9FCBMh7018142; Tue, 15 Oct 2013 21:11:22 +0900 Received: from poodle by lomi13.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r9FCBMn7018130; Tue, 15 Oct 2013 21:11:22 +0900 Received: from beagle.diag.org (beagle.diag.org [10.184.179.16]) by poodle (Postfix) with ESMTP id 8AFD82743A5C; Tue, 15 Oct 2013 21:11:22 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Tue, 15 Oct 2013 21:11:05 +0900 Message-Id: <1381839065-26035-1-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.8.1.2 Cc: Tom Rini , Jeroen Hofstee Subject: [U-Boot] [PATCH v4] config.mk: fix -fstack-usage support test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Cc: Tom Rini Cc: Michal Simek Cc: Jeroen Hofstee Cc: Albert ARIBAUD --- 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 0000000..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 +# +# 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