Commit Graph

19 Commits

Author SHA1 Message Date
Alberto Escolar Piedras 6e977ae2d5 lib c/cpp: Move .ctor .init_array handling from C++ to kernel
* Move ctors and init_array from the CPP library
  to the kernel library, as this is common for both C
  and C++ and it is the kernel who is running it.
* Rename the hidden kconfig option CPP_STATIC_INIT_GNU
  STATIC_INIT_GNU instead.
* If STATIC_INIT_GNU is not selected verify there is
  constructors left behind.
* Rename common-rom-cpp.ld to common-rom-init.ld
* Rename z_cpp_init_static to z_init_static,
  and have the kernel always call it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Signed-off-by: Keith Packard <keithp@keithp.com>
2024-06-25 19:14:37 -04:00
Yong Cong Sin 67578faefe lib: cpp: remove deprecated Kconfigs
These Kconfigs should have been deprecated for more than 2
releases, remove them:

- `CONFIG_CPP_MAIN`
- `CONFIG_CPLUSPLUS`
- `CONFIG_LIB_CPLUSPLUS`
- `CONFIG_EXCEPTIONS`
- `CONFIG_RTTI`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -04:00
Patryk Duda ce438da14f llvm: Add support for LLVM libc++ C++ Standard Library
LLVM toolchain provides its own C++ standard library called libc++.
This patch adds new LLVM_LIBCXX config which should be used to indicate
that libc++ is used.

Information about library can be found at https://libcxx.llvm.org

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-10-20 14:59:31 +02:00
Al Semjonovs 955d85aa67 libc: picolibc: Fix picolibc to allow third party CPP
Picolibc dependencies limit ability to use third party minimal
implementations of CPP when enablng PICOLIBC_USE_MODULE.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2023-10-09 15:05:39 +03:00
Damian Krolik 74859013f1 lib: cpp: name the choice group for selecting C++ standard
Add a name to the choice group for selecting the C++
standard to be able to override the default standard in
Kconfig.* files.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2023-07-27 22:33:14 -04:00
Alberto Escolar Piedras 56dc20eb1d Kconfig: Tidy up dependants of NATIVE_APPLICATION
So they depend or select on the right NATIVE_BUILD
instead of NATIVE_APPLICATION.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-05 07:01:19 -04:00
Keith Packard 6ccdf47f60 lib/cpp: Remove CONFIG_CPP_MAIN
With Zephyr now always using `int main(void)`, there's no longer any need
for this definition. The last remaining use which gated the declaration of
_posix_zephyr_main isn't necessary as adding that declaration
unconditionally is harmless.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-05-31 06:16:35 -04:00
Alberto Escolar Piedras b0668cc586 lib: cpp: Do not define __cxa_atexit() for the posix arch
For the POSIX architecture we do not define an
empty __cxa_atexit() as it otherwise would
override its host libC counterpart. And this would
both disable the atexit() hooks, and prevent possible
test code global destructors from being registered.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-05-12 18:31:44 -04:00
Kumar Gala e268f8eb4f lib: cpp: Introduce FULL_LIBCPP_SUPPORTED similar to C version
Introduce Kconfig symbol FULL_LIBCPP_SUPPORTED that is similar to the
C version FULL_LIBC_SUPPORTED.  This way we can utilize the same
pattern in tests and samples to filter for when a full libc++ is
needed.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-03 10:01:05 +02:00
Keith Packard dc3f1d7d62 lib/cpp: Allow REQUIRES_FULL_LIBCPP to be selected by applications
Add a prompt to the Kconfig symbol so that applications can select this in
to guide C++ standard library selection towards configurations which
provide a complete implementation.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-25 06:20:49 -04:00
Andy Ross 7df2ca6e86 minimal libcpp: Un-11-ify cstddef
Don't expose C++11 APIs unless we're building for that platform

Signed-off-by: Andy Ross <andyross@google.com>

squashme cdecl
2023-03-01 19:42:32 -05:00
Keith Packard 13dfbaebd1 libc/picolibc: Clean up Picolibc Kconfig for C++
libstdc++ is supported with Picolibc only when the toolchain version of
Picolibc is use -- libstdc++ must be built using a specific Picolibc build
and libstdc++ is included with the toolchain.

Ideally, we'd allow the use of the Picolibc module whenever we weren't
using the GNU libstdc++, including when using the minimal libc++. However,
the obvious dependency settings create a loop:

config PICOLIBC
    depends on PICOLIBC_SUPPORTED

config PICOLIBC_SUPPORTED
    depends on !(GLIBCXX_LIBCPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")

config GLIBCXX_LIBCPP
    depends on NEWLIB_LIBC || PICOLIBC

To break this loop, we replace GLIBCXX_LIBCPP in the second block with
CPP:

config PICOLIBC_SUPPORTED
    depends on !(CPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")

This means that picolibc cannot be used with any C++ apps when using the
Zephyr SDK, even when not using the GNU libstdc++. However, Zephyr SDK 0.16
will come with an additional Kconfig file that includes:

config PICOLIBC_SUPPORTED
    def_bool y
    depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr"

This will override the Kconfig bits included in Zephyr and allow use of the
Picolibc module with C++ code, including using the minimal libc++ bits.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-20 09:03:25 +01:00
Stephanos Ioannidis 669a0f5bec lib: cpp: Rework C++ standard library configurations
This commit reworks the C++ standard library configurations such that:

* the separation between the Zephyr minimal C++ library and the fully
  featured C++ standard libraries, such as GNU libstdc++, is clear.
  This is done by deprecating the Kconfig `CONFIG_LIB_CPLUSPLUS`
  symbol, which implies that the minimal C++ library is selected when
  set to `n`, and introducing the `CONFIG_MINIMAL_LIBCPP` symbol.

* the type of the selected C++ standard library is clear. This is done
  by introducing a Kconfig choice, `LIBCPP_IMPLEMENTATION`, for the C++
  standard library type and providing the choice symbols for each
  library type supported, such as `CONFIG_MINIMAL_LIBCPP` and
  `CONFIG_GLIBCXX_LIBCPP`.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 45ba8d5787 lib: cpp: Rename CONFIG_RTTI to CONFIG_CPP_RTTI
The Kconfig `CONFIG_RTTI` symbol enables the C++ Run-Time Type
Information (RTTI) support and is a feature of the standard C++
library; therefore, it should be prefixed with `CPP_` as with the rest
of the C++-specific symbols.

This commit renames the Kconfig `CONFIG_RTTI` symbol to
`CONFIG_CPP_RTTI` in order to better align with the other existing C++
Kconfig symbols, and deprecates the old `CONFIG_RTTI` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 26ede92f84 lib: cpp: Rename CONFIG_EXCEPTIONS to CONFIG_CPP_EXCEPTIONS
`CONFIG_EXCEPTIONS` is ambiguous in that the word "exception" may be
used to refer to many different types of exceptions, from the hardware
generated faults and interrupts (aka. exceptions) to the C++
exceptions.

This commit renames the Kconfig `CONFIG_EXCEPTIONS` symbol to
`CONFIG_CPP_EXCEPTIONS` in order to clarify that the symbol refers to
the C++ exceptions and eliminate any ambiguity, and deprecates the old
`CONFIG_EXCEPTIONS` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 05aea1ce58 lib: cpp: Rename CONFIG_CPLUSPLUS to CONFIG_CPP
There is no reason for the top-level C++ Kconfig symbol to be called
`CPLUSPLUS` when the convention used throughout the Zephyr codebase is
to use "cpp" to refer to C++ and the rest of the C++-related Kconfig
symbols are prefixed with `CPP_`.

This commit renames the Kconfig `CPLUSPLUS` symbol to `CPP` in order to
better align with the de-facto standard naming convention used throughout
the Zephyr codebase, and deprecates the old `CPLUSPLUS` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 96234b15df lib: cpp: Relocate C++ minimal library components to lib/cpp/minimal
This commit relocates the "C++ minimal library" components, that
implement a very limited subset of the standard C++ library, to a
dedicated directory, `lib/cpp/minimal`, in order to provide a clear
separation among the different C++ library components.

After this refactoring, the top `lib/cpp` directory should only contain
the sub-directories for each C++ library (i.e. `abi`, `minimal`). In
the future, a C++ library-specific shim layer implementation may be
added as sub-directories under `lib/cpp` as well (e.g. `libstdc++`
sub-directory containing the shim layer implementation for the GCC
libstdc++ library) -- this is similar to how the libc directories are
structured under `lib/libc`.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 03879b9e2b lib: cpp: Relocate C++ ABI library components to lib/cpp/abi
This commit relocates the "C++ ABI library" components such as
global constructor/destructor and initialiser handlers to a dedicated
directory, `lib/cpp/abi`, in order to provide a clear separation
between the C++ ABI/runtime library and the standard C++ library
components.

Note that the Zephyr C++ ABI library currently implements the GNU/GCC
C++ ABI, which is the de-facto standard ABI used by many compilers
including Clang -- it may be necessary to sub-divide the `lib/cpp/abi`
into `lib/cpp/abi/gnu` and `lib/cpp/abi/someotherabi` in the future
when adding the support for a C++ compiler that expects an ABI vastly
different from the GNU C++ ABI.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis feaab27c1b lib: cpp: Relocate subsys/cpp to lib/cpp
This commit moves the files under `subsys/cpp` directory to the
`lib/cpp` directory because the C++ ABI runtime library and the
standard C++ library components are not a "subsystem" (aka. API) in
conventional sense and is better described as a "library."

Classifying the C++ ABI runtime library and the standard C++ library as
"libraries" instead of "subsystems" also better aligns with how the
existing C standard library implementation (`lib/libc`) is handled.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00