mirror of
https://github.com/apache/nuttx.git
synced 2026-05-10 07:18:49 +08:00
build/cmake/stdlib: guard include/cxx by LIBMINIABI, fix div_t conflict
include/cxx contains NuttX's mini C++ ABI shims and must only be added to the include path when CONFIG_LIBMINIABI is selected. tools/Config.mk was adding it unconditionally for every non-LIBCXX/non-UCLIBCXX build, and the platform.cmake files for arm, arm64, risc-v, x86_64 and tricore were adding it inside the CONFIG_LIBCXXTOOLCHAIN block. With an unpatched downloaded ARM GNU Toolchain, <cstdlib> uses newlib's stdlib.h, defining div_t as an anonymous struct. A later inclusion of NuttX's stdlib.h via <cstdio>->stdio.h->kmalloc.h then redefines div_t with struct tag div_s, causing a conflicting declaration error. Guard the div_t/ldiv_t/lldiv_t definitions in stdlib.h with redefinitions when a toolchain stdlib.h was already processed. Also fix lldiv_s members typed as long instead of long long. Signed-off-by: trns1997 <trns1997@gmail.com>
This commit is contained in:
@@ -87,6 +87,9 @@ endif()
|
||||
|
||||
if(CONFIG_LIBCXXTOOLCHAIN)
|
||||
nuttx_find_toolchain_lib(libstdc++.a)
|
||||
endif()
|
||||
|
||||
if(CONFIG_LIBMINIABI)
|
||||
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ endif()
|
||||
|
||||
if(CONFIG_LIBCXXTOOLCHAIN)
|
||||
nuttx_find_toolchain_lib(libstdc++.a)
|
||||
endif()
|
||||
|
||||
if(CONFIG_LIBMINIABI)
|
||||
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ endif()
|
||||
|
||||
if(CONFIG_LIBCXXTOOLCHAIN)
|
||||
nuttx_find_toolchain_lib(libstdc++.a)
|
||||
endif()
|
||||
|
||||
if(CONFIG_LIBMINIABI)
|
||||
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ if(CONFIG_TRICORE_TOOLCHAIN_GNU)
|
||||
endif()
|
||||
if(CONFIG_LIBCXXTOOLCHAIN)
|
||||
nuttx_find_toolchain_lib(libstdc++.a)
|
||||
endif()
|
||||
if(CONFIG_LIBMINIABI)
|
||||
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
|
||||
endif()
|
||||
if(CONFIG_COVERAGE_TOOLCHAIN)
|
||||
|
||||
@@ -49,6 +49,9 @@ endif()
|
||||
|
||||
if(CONFIG_LIBCXXTOOLCHAIN)
|
||||
nuttx_find_toolchain_lib(libstdc++.a)
|
||||
endif()
|
||||
|
||||
if(CONFIG_LIBMINIABI)
|
||||
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
|
||||
endif()
|
||||
|
||||
|
||||
+19
-3
@@ -87,8 +87,23 @@
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Structure type returned by the div() function. */
|
||||
/* Structure type returned by the div() function.
|
||||
*
|
||||
* When CONFIG_LIBCXXTOOLCHAIN is active the toolchain's <cstdlib> uses
|
||||
* #include_next <stdlib.h> which bypasses this file and lands on the
|
||||
* toolchain's own stdlib.h (e.g. newlib's _STDLIB_H_ guard). That file
|
||||
* defines div_t/ldiv_t/lldiv_t with an anonymous struct that GCC internally
|
||||
* names struct div_t. A subsequent inclusion of this file (through the
|
||||
* cstdio -> stdio.h -> kmalloc.h chain) would then attempt to redefine the
|
||||
* same typedef with a different struct tag, causing a "conflicting
|
||||
* declaration" error. Guard against that by skipping our own struct/typedef
|
||||
* definitions when a toolchain stdlib.h has already been included.
|
||||
*
|
||||
* _STDLIB_H_ - newlib (ARM GNU Toolchain, picolibc, avr-libc, ...)
|
||||
* _STDLIB_H - glibc / musl (native host toolchains)
|
||||
*/
|
||||
|
||||
#if !defined(_STDLIB_H_) && !defined(_STDLIB_H)
|
||||
struct div_s
|
||||
{
|
||||
int quot; /* Quotient */
|
||||
@@ -111,11 +126,12 @@ typedef struct ldiv_s ldiv_t;
|
||||
|
||||
struct lldiv_s
|
||||
{
|
||||
long quot; /* Quotient */
|
||||
long rem; /* Remainder */
|
||||
long long quot; /* Quotient */
|
||||
long long rem; /* Remainder */
|
||||
};
|
||||
|
||||
typedef struct lldiv_s lldiv_t;
|
||||
#endif /* !defined(_STDLIB_H_) && !defined(_STDLIB_H) */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
|
||||
+3
-1
@@ -746,7 +746,9 @@ ifeq ($(CONFIG_LIBCXX),y)
|
||||
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)libcxx
|
||||
else ifeq ($(CONFIG_UCLIBCXX),y)
|
||||
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)uClibc++
|
||||
else
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBMINIABI),y)
|
||||
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)cxx
|
||||
ifeq ($(CONFIG_ETL),y)
|
||||
ARCHXXINCLUDES += ${INCSYSDIR_PREFIX}$(TOPDIR)$(DELIM)include$(DELIM)etl
|
||||
|
||||
Reference in New Issue
Block a user