Add basic support for locales in order to C++ streams to build and work for simple cases (POSIX / C locale).

Fix build with C++ GCC toolchain
This commit is contained in:
Philippe Leduc 2024-04-24 17:01:11 +02:00 committed by Xiang Xiao
parent 88fa598ea2
commit 3dc6b4c9bd
31 changed files with 164 additions and 46 deletions

View File

@ -187,8 +187,6 @@ set(ARCHCFLAGS "-Wstrict-prototypes")
if(NOT CONFIG_LIBCXXTOOLCHAIN)
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -nostdinc++")
else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(NOT CONFIG_CXX_EXCEPTION)

View File

@ -301,8 +301,6 @@ ARCHCXXFLAGS += -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)

View File

@ -109,8 +109,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)

View File

@ -127,8 +127,6 @@ set(ARCHCXXFLAGS
if(NOT CONFIG_LIBCXXTOOLCHAIN)
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -nostdinc++")
else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(NOT ${CONFIG_ARCH_TOOLCHAIN_CLANG})

View File

@ -106,8 +106,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -46,15 +46,13 @@ else
endif
ARCHCFLAGS += -fno-common
ARCHCXXFLAGS += -fno-common
ARCHCXXFLAGS += -fno-common
ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -72,8 +72,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ARCHCPUFLAGS = -mrtl-version-$(RTL_VERSION) -Wa,-rtl$(RTL_VERSION)

View File

@ -72,8 +72,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ARCHCPUFLAGS = -mrtl-version-$(RTL_VERSION) -Wa,-rtl$(RTL_VERSION)

View File

@ -267,8 +267,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -79,8 +79,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -67,8 +67,6 @@ EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifeq ($(CONFIG_LIBM_TOOLCHAIN),y)

View File

@ -62,8 +62,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -158,8 +158,6 @@ set(ARCHCXXFLAGS
if(NOT CONFIG_LIBCXXTOOLCHAIN)
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -nostdinc++")
else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(NOT ${CONFIG_ARCH_TOOLCHAIN_CLANG})

View File

@ -95,8 +95,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)

View File

@ -102,8 +102,6 @@ set(ARCHCFLAGS "-Wstrict-prototypes")
if(NOT CONFIG_LIBCXXTOOLCHAIN)
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -nostdinc++")
else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(NOT CONFIG_CXX_EXCEPTION)

View File

@ -84,8 +84,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -93,8 +93,6 @@ set(ARCHCXXFLAGS
if(NOT CONFIG_LIBCXXTOOLCHAIN)
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -nostdinc++")
else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(NOT CONFIG_CXX_EXCEPTION)

View File

@ -113,8 +113,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)

View File

@ -117,8 +117,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y)

View File

@ -122,8 +122,6 @@ ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas
ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y)
ARCHCXXFLAGS += -nostdinc++
else
ARCHCXXFLAGS += -D_STDLIB_H_
endif
ifneq ($(CONFIG_CXX_STANDARD),)

View File

@ -33,6 +33,23 @@
#include <nuttx/compiler.h>
#include <langinfo.h>
/****************************************************************************
* Macro Definitions
****************************************************************************/
/* GNU libstdc++ is expecting ctype.h to define a few macros for
* locale related functions like C++ streams.
*/
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
/****************************************************************************
* Inline Functions
****************************************************************************/

View File

@ -34,4 +34,5 @@ target_sources(
lib_isupper.c
lib_isxdigit.c
lib_tolower.c
lib_toupper.c)
lib_toupper.c
lib_ctype.c)

View File

@ -23,7 +23,7 @@
CSRCS += lib_isalnum.c lib_isalpha.c lib_isascii.c lib_isblank.c
CSRCS += lib_iscntrl.c lib_isdigit.c lib_isgraph.c lib_islower.c
CSRCS += lib_isprint.c lib_ispunct.c lib_isspace.c lib_isupper.c
CSRCS += lib_isxdigit.c lib_tolower.c lib_toupper.c
CSRCS += lib_isxdigit.c lib_tolower.c lib_toupper.c lib_ctype.c
DEPPATH += --dep-path ctype
VPATH += :ctype

View File

@ -0,0 +1,77 @@
/****************************************************************************
* libs/libc/ctype/lib_ctype.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <ctype.h>
/****************************************************************************
* Private Types
****************************************************************************/
/* GNU libstdc++ is expecting an array _ctype_ to be defined. This array
* is usually defined in GNU libc or newlib.
* Here the system support only basic ASCII locale.
*/
const char _ctype_[] =
{
0,
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C | _S, _C | _S, _C | _S, _C | _S, _C | _S, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_C, _C, _C, _C, _C, _C, _C, _C, \
_S | _B, _P, _P, _P, _P, _P, _P, _P, \
_P, _P, _P, _P, _P, _P, _P, _P, \
_N, _N, _N, _N, _N, _N, _N, _N, \
_N, _N, _P, _P, _P, _P, _P, _P, \
_P, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _U, _U, _U, _U, _U, \
_U, _U, _U, _P, _P, _P, _P, _P, \
_P, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _L, _L, _L, _L, _L, \
_L, _L, _L, _P, _P, _P, _P, _C, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0
};
/****************************************************************************
* Private Functions
****************************************************************************/

View File

@ -19,6 +19,13 @@
# ##############################################################################
if(CONFIG_LIBC_LOCALE)
target_sources(c PRIVATE lib_duplocale.c lib_freelocale.c lib_localeconv.c
lib_newlocale.c lib_setlocale.c lib_uselocale.c)
target_sources(
c
PRIVATE lib_duplocale.c
lib_freelocale.c
lib_localeconv.c
lib_newlocale.c
lib_setlocale.c
lib_uselocale.c
lib_maxlocale.c)
endif()

View File

@ -25,6 +25,7 @@ ifeq ($(CONFIG_LIBC_LOCALE),y)
CSRCS += lib_duplocale.c lib_freelocale.c lib_localeconv.c
CSRCS += lib_newlocale.c lib_setlocale.c lib_uselocale.c
CSRCS += lib_catalog.c lib_gettext.c lib_langinfo.c lib_iconv.c
CSRCS += lib_maxlocale.c
# Add the locale directory to the build

View File

@ -0,0 +1,45 @@
/****************************************************************************
* libs/libc/locale/lib_maxlocale.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Private Functions
****************************************************************************/
/* GNU libstdc++ is expecting some functions to be defined.
*/
/* Shall return the max number of bytes of a multibyte character */
int __locale_mb_cur_max(void)
{
return MB_CUR_MAX;
}
#endif

View File

@ -28,6 +28,8 @@ choice
config LIBCXXTOOLCHAIN
bool "Toolchain C++ support"
select HAVE_CXXINITIALIZE
select LIBC_LOCALE
---help---
Use Standard C++ library from toolchain.

View File

@ -99,6 +99,11 @@ ifdef CONFIG_BUILD_PROTECTED
endif
ifdef CONFIG_BUILD_KERNEL
@echo "NUTTX_BUILD=\"kernel\"" >> $(EXPORTDIR)/makeinfo.sh
endif
ifdef CONFIG_LIBCXX
@echo "NUTTX_CXX=\"libcxx\"" >> $(EXPORTDIR)/makeinfo.sh
else
@echo "NUTTX_CXX=\"cxx\"" >> $(EXPORTDIR)/makeinfo.sh
endif
$(Q) chmod 755 $(EXPORTDIR)/makeinfo.sh

View File

@ -266,6 +266,7 @@ echo "NUTTX_ARCH = ${NUTTX_ARCH}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NUTTX_ARCH_CHIP = ${NUTTX_ARCH_CHIP}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NUTTX_BOARD = ${NUTTX_BOARD}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NUTTX_BUILD = ${NUTTX_BUILD}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "NUTTX_CXX = ${NUTTX_CXX}" >>"${EXPORTDIR}/scripts/Make.defs"
echo "set(ARCHCFLAGS \"${ARCHCFLAGS}\")" > "${EXPORTDIR}/scripts/target.cmake"
echo "set(ARCHCPUFLAGS \"${ARCHCPUFLAGS}\")" >>"${EXPORTDIR}/scripts/target.cmake"
@ -296,6 +297,7 @@ echo "set(NUTTX_ARCH \"${NUTTX_ARCH}\")" >>"${EXPORTDIR}/scripts/
echo "set(NUTTX_ARCH_CHIP \"${NUTTX_ARCH_CHIP}\")" >>"${EXPORTDIR}/scripts/target.cmake"
echo "set(NUTTX_BOARD \"${NUTTX_BOARD}\")" >>"${EXPORTDIR}/scripts/target.cmake"
echo "set(NUTTX_BUILD \"${NUTTX_BUILD}\")" >>"${EXPORTDIR}/scripts/target.cmake"
echo "set(NUTTX_CXX \"${NUTTX_CXX}\")" >>"${EXPORTDIR}/scripts/target.cmake"
# Additional compilation options when the kernel is built

View File

@ -16,7 +16,8 @@ set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_PATH}/include
${NUTTX_PATH}/arch/chip)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${NUTTX_PATH}/include/libcxx ${NUTTX_PATH}/include ${NUTTX_PATH}/arch/chip)
${NUTTX_PATH}/include/${NUTTX_CXX} ${NUTTX_PATH}/include
${NUTTX_PATH}/arch/chip)
file(GLOB STARTUP_OBJS ${NUTTX_PATH}/startup/*)