diff mbox

[U-Boot] cmd_test: fix a compile error on Blackfin

Message ID 1384830117-25345-1-git-send-email-yamada.m@jp.panasonic.com
State Rejected
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Nov. 19, 2013, 3:01 a.m. UTC
Before this commit, common/cmd_test.c defined
_STDBOOL_H in order to avoid including <stdbool.h>.
But this work-around is not a good idea.

Blackfin header file
arch/blackfin/include/asm/blackfin_local.h
uses bool type here:
  extern bool bfin_os_log_check(void);

This means Blackfin boards which define CONFIG_SYS_HUSH_PARSER
always failed in compiling.

This commit fixes this issue by undefining true and false macro.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

For example, when I try to compile bct-brettl2 board,
I got an error like follows at compiling common/cmd_test.c.

 bfin-uclinux-gcc  -g  -Os   -ffixed-P3 -fomit-frame-pointer -mno-fdpic
 -ffunction-sections -fdata-sections -mcpu=bf536-0.3 -D__KERNEL__
 -I/home/yamada/u-boot/include -I/home/yamada/u-boot/arch/blackfin/include
 -fno-builtin -ffreestanding -nostdinc
 -isystem /opt/gcc-4.6.3-nolibc/bfin-uclinux/bin/../lib/gcc/bfin-uclinux/4.6.3/include
 -pipe  -DCONFIG_BLACKFIN -Wall -Wstrict-prototypes -fno-stack-protector
 -Wno-format-nonliteral -Wno-format-security     -o cmd_test.o cmd_test.c -c
 In file included from /home/yamada/u-boot/arch/blackfin/include/asm/blackfin.h:13:0,
                 from /home/yamada/u-boot/include/common.h:92,
                 from cmd_test.c:17:
 /home/yamada/u-boot/arch/blackfin/include/asm/blackfin_local.h:54:1: error: unknown type name 'bool'
 make[2]: *** [cmd_test.o] Error 1
 make[2]: Leaving directory `/home/yamada/u-boot/common'
 make[1]: *** [common/built-in.o] Error 2
 make[1]: Leaving directory `/home/yamada/u-boot'
 make: *** [bct-brettl2] Error 2

This is not a compiler problem.
It looks like this behavior is common for all blackfin compilers.


 common/cmd_test.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Masahiro Yamada Nov. 19, 2013, 3:15 a.m. UTC | #1
FYI:

This patch is related with the discussion in the thread:
http://patchwork.ozlabs.org/patch/292011/

Best Regards
Masahiro Yamada
Måns Rullgård Nov. 19, 2013, 3:51 p.m. UTC | #2
Masahiro Yamada <yamada.m@jp.panasonic.com> writes:

> Before this commit, common/cmd_test.c defined
> _STDBOOL_H in order to avoid including <stdbool.h>.
> But this work-around is not a good idea.
>
> Blackfin header file
> arch/blackfin/include/asm/blackfin_local.h
> uses bool type here:
>   extern bool bfin_os_log_check(void);
>
> This means Blackfin boards which define CONFIG_SYS_HUSH_PARSER
> always failed in compiling.
>
> This commit fixes this issue by undefining true and false macro.

[...]

> +/*
> + * Undef true and false here to avoid macro expansion by <stdbool.h>
> + */
> +#undef true
> +#undef false

This won't work if stdbool.h defines true/false as an enum.  Some
versions of gcc did this.  The correct fix is to change the code so it
doesn't use any of the identifiers bool, true, or false for other
purposes than those intended by stdbool.h.

I agree with Wolfgang that using "boolean" types is generally a bad idea
that only introduces problems.
Masahiro Yamada Nov. 20, 2013, 4:29 a.m. UTC | #3
Hello Mans

> > +/*
> > + * Undef true and false here to avoid macro expansion by <stdbool.h>
> > + */
> > +#undef true
> > +#undef false
> 
> This won't work if stdbool.h defines true/false as an enum.  Some
> versions of gcc did this.  The correct fix is to change the code so it

Thanks for your comments.
This patch does not work, so I'd like to retract it.

Best Regards
Masahiro Yamada
diff mbox

Patch

diff --git a/common/cmd_test.c b/common/cmd_test.c
index bacc368..1800cff 100644
--- a/common/cmd_test.c
+++ b/common/cmd_test.c
@@ -5,15 +5,6 @@ 
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
-/*
- * Define _STDBOOL_H here to avoid macro expansion of true and false.
- * If the future code requires macro true or false, remove this define
- * and undef true and false before U_BOOT_CMD. This define and comment
- * shall be removed if change to U_BOOT_CMD is made to take string
- * instead of stringifying it.
- */
-#define _STDBOOL_H
-
 #include <common.h>
 #include <command.h>
 
@@ -143,6 +134,12 @@  U_BOOT_CMD(
 	"[args..]"
 );
 
+/*
+ * Undef true and false here to avoid macro expansion by <stdbool.h>
+ */
+#undef true
+#undef false
+
 static int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	return 1;