-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toolchain C++ headers can be included when libstdc++ is not selected #36644
Comments
Just to make sure (I saw that you self assigned this issue) I'll just update my PR to match the appropriate C++ standard and then wait for this bug to be resolved? I don't want to accidentally duplicate work. |
@yperess As far as #36612 is concerned, I was expecting the new header files to be updated to comply with the C++ standard. If you would like to look into this issue as well, please let me know and I will update the assignment. |
I've update #36612 to match the C++ style modeling it after the GNU cstdint file. It passes CQ now as well as our build with the custom toolchain. I'll let you know if I have some free cycles to work on this issue (I'm very interested in ensuring good support for C++). |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
NOTE: For 2.7, we will keep the existing structure and only provide a fix with the minimum amount of changes. In the future, the C++ support will be completely re-architected to support multiple toolchains (further details to be discussed and finalised in the Toolchain WG meetings, alongside the C library integration refactoring). |
The TensorFlow Lite module makes use of the features provided by the standard C++ library (e.g. `#include <functional>`), so the standard C++ library config must be enabled for it. This used to work without `CONFIG_LIB_CPLUSPLUS=y` due to the bug described in the issue zephyrproject-rtos#36644. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The TensorFlow Lite module makes use of the features provided by the standard C++ library (e.g. `#include <functional>`), so the standard C++ library config must be enabled for it. This used to work without `CONFIG_LIB_CPLUSPLUS=y` due to the bug described in the issue #36644. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The TensorFlow Lite module makes use of the features provided by the standard C++ library (e.g. `#include <functional>`), so the standard C++ library config must be enabled for it. This used to work without `CONFIG_LIB_CPLUSPLUS=y` due to the bug described in the issue zephyrproject-rtos#36644. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
C++ examples such as `samples/cpp/cpp_synchronization` do not build on xtensa because some toolchain headers such as <limits.h> which is a C header turns out to depend on a C++ header when included in C++ mode. This change preserves the fix for issue zephyrproject-rtos#36644 while selectively enabling the use of C++ standard includes. Signed-off-by: William Tambe <williamt@cadence.com>
C++ examples such as `samples/cpp/cpp_synchronization` do not build on xtensa because some toolchain headers such as <limits.h> which is a C header turns out to depend on a C++ header when included in C++ mode. This change preserves the fix for issue zephyrproject-rtos#36644 while selectively enabling the use of C++ standard includes. Signed-off-by: William Tambe <williamt@cadence.com>
Status quo
The Zephyr build system does not specify
-nostdinc
argument when newlib is enabled (CONFIG_NEWLIB_LIBC=y
):zephyr/cmake/compiler/gcc/compiler_flags.cmake
Lines 115 to 121 in ae85da1
This has the effect of making the toolchain-provided standard headers (which includes newlib standard C library headers for the currently supported toolchains) available for inclusion.
When
CONFIG_LIB_CPLUSPLUS=y
, which semantically enables the use of libstdc++, this also has the intended effect since the toolchain-provided libstdc++ C++ standard library headers are available for inclusion when-nostdinc
is not specified.When
CONFIG_NEWLIB_LIBC=y
andCONFIG_LIB_CPLUSPLUS=n
however, this has an unintended effect of making the libstdc++ headers available for inclusion even when it was never the developer's intention to make use of the toolchain-provided libstdc++ features, as observed in #36612 (comment).The libstdc++, also known as the GNU C++ library, mainly consists of the standard C++ library header files, which include both definitions and implementations, and the standard C++ library object archive, which provides the implementations for the methods that do not come with implementation in the headers.
The current definition of
CONFIG_LIB_CPLUSPLUS
is "Link with STD C++ library":zephyr/subsys/cpp/Kconfig
Lines 47 to 48 in 6153719
One may possibly argue that allowing the use of libstdc++ headers without linking the libstdc++ archive, alongside the minimal C++ runtime implemented by the Zephyr C++ subsystem (one might call this a "hybrid" scheme), is a both valid and intended scheme; but, in reality, this is simply not a correct thing to do for the following reasons and need to be classified as a bug:
.a
file) is supposed to provide the implementations. In terms of C++, this separation often gets blurred and, as with the libstdc++, many small method implementations tend to get put in the header file. This does not mean that you can rely on the headers to provide the full implementation and making use of the headers without linking the relevant object files leaves the build success at the mercy of what gets put in the headers and source files on the libstdc++ side. This is non-deterministic and not a correct behaviour.To be
As briefly noted in #36612 (comment):
CONFIG_LIB_CPLUSPLUS=n
by specifying-nostdinc++
.subsys/cpp
) such that the separation between the "minimal C++ runtime library" and the toolchain-specific C++ runtime library integration (glue/shim) is clear.lib/cpp
) and adopt the same scheme as the C library (lib/libc
).lib/libc/minimal
).The text was updated successfully, but these errors were encountered: