From 3fc06ff2d145adc0fc3e46306e3a9886fa436ed8 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 22 Oct 2020 10:47:08 +0900 Subject: [PATCH] sim: Specify -fshort-wchar as NuttX wchar_t is 16-bit * For C, wchar_t is provided by the OS. On NuttX, it's uint16_t. (Except wide character literals, which uses the compiler built-in knowledge of wchar_t.) * For C++, wchar_t is a built-in type. It's provided by the compiler. * The compilers built-in wchar depends on the compiler configuration. For the sim, the compilers are usually configured with wchar_t == int, which is 32-bit. * wchar_t should be compatible between C and C++. This commit fixes the mismatches by telling the compiler to use 16-bit wchar_t. An alternative is to make NuttX use 32-bit wchar_t if the compiler is configured with 32-bit wchar_t. It can increase the runtime footprint. While it might be ok for the sim, it might be a problem for real devices. --- boards/sim/sim/sim/scripts/Make.defs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index e865f0c7a5..22c4835d68 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -93,11 +93,16 @@ NM = $(CROSSDEV)nm OBJCOPY = $(CROSSDEV)objcopy OBJDUMP = $(CROSSDEV)objdump +# Note: -fshort-wchar for the case where NuttX and the host OS have +# differnt wchar_t. On Nuttx, it's uint16_t. On macOS, it's 32-bit. CFLAGS := $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \ - $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe + $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe \ + -fshort-wchar CXXFLAGS := $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \ - $(ARCHCPUFLAGSXX) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe -CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) + $(ARCHCPUFLAGSXX) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe \ + -fshort-wchar +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) \ + -fshort-wchar AFLAGS := $(CFLAGS) -D__ASSEMBLY__ ifeq ($(CONFIG_LIBCXX),y)