Skip to content

sys/cpp11-compat: use new/delete operators from sys/cpp_new_delete#17475

Merged
aabadie merged 2 commits intoRIOT-OS:masterfrom
gschorcht:sys/move_new_delete_dso_handle
Jan 6, 2022
Merged

sys/cpp11-compat: use new/delete operators from sys/cpp_new_delete#17475
aabadie merged 2 commits intoRIOT-OS:masterfrom
gschorcht:sys/move_new_delete_dso_handle

Conversation

@gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Jan 6, 2022

Contribution description

This PR provides code deduplication as well as the ability for an application to use (re)defined new/delete operators without requiring libstdc++.

  1. The sys/cpp11-compat module (re)defines the new/delete operators but depends on libstdc++ even for new/delete operators that don't need libtsdc++. Module sys/cpp_new_delete provides these operators for platforms that don't have the libstdc++. Since these operators in sys/cpp11-compat are just wrappers for standard malloc/free functions like in sys/cpp_new_delete, the new/delete operators that don't need libstdc++ are used from sys/cpp_new_delete. Only the new/delete operators that require the libstd++ are left in sys/cpp11-compat.

    So it is sufficient for the use of the (re)defined new/delete operators that an application uses the module sys/cpp_new_delete instead of sys/cpp11-compat and thus also works on platforms without libstdc++.

  2. On ARM platforms, __dso_handle is used for dynamic shared objects. But it is also required if global static objects are used. To avoid that sys/cpp11_compat is required only for using the (re)defined new/delete operators, __dso_handle is moved to module sys/cpp_new_delete

Testing procedure

Green CI.

Issues/PRs references

Uses the module introduced by PR #17464

The `new` and `delete` operators that don't need `libtsdc++` are also provided by module `sys/cpp_new_delete` for platforms that don't have the `libstdc++`. Since these operators in `sys/cpp11-compat` are just wrappers for standard `malloc`/`free` functions like in `sys/cpp_new_delete`, the `new`/`delete` operators that don't need `libstdc++` are used from `sys/cpp_new_delete`. Only the `new`/`delete` operators that require the `libstd++` are left in `sys/cpp11-compat`.
  So it is sufficient for the use of the (re)defined `new`/`delete` operators that an application uses the module `sys/cpp_new_delete` instead of `sys/cpp11-compat` and thus also works on platforms without `libstdc++`.
On ARM platforms, `__dso_handle` is used for dynamic shared objects. But it is also required if global static objects are used. To avoid that `sys/cpp11_compat` is required only for using the (re)defined `new`/`delete` operators, `__dso_handle` is moved to module `sys/cpp_new_delete`
@github-actions github-actions bot added the Area: sys Area: System label Jan 6, 2022
@gschorcht gschorcht added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Jan 6, 2022
@gschorcht gschorcht requested a review from maribu January 6, 2022 09:21
@aabadie aabadie merged commit 7d8b31d into RIOT-OS:master Jan 6, 2022
@gschorcht
Copy link
Contributor Author

Thanks for reviewing and merging.

@fjmolinas fjmolinas added this to the Release 2022.01 milestone Jan 21, 2022
endif

ifneq (,$(filter cpp11-compat,$(USEMODULE)))
USEMODULE += cpp_new_delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gschorcht,

Trying to understand the cpp11-compat and cpp_new_delete structure I have a question regarding this PR:
The docs of cpp_new_delete state the following:

@brief      This module provides the `new` and `delete` operators for platforms
            that do not use `libstdc++`.
@warning    This module is automatically selected, if needed. Never add it
            manually.

# Background

On some platforms `libstdc++` is not used or not available, like on the AVR.
Such platforms can use this module to implement the C++ `new` and `delete`
operators using `malloc` and `free` respectively. However, to be thread-safe,
a thread-safe implementation of `malloc` and `free` must be present.

# Usage

This module is intended to be use by platforms that not providing the required
operators. Hence, application developers and users should never select this
module by hand.

This PR adds the above module whenever cpp-compat is selected which contradicts to the above docs. Which is correct?
I'd like to file a PR to break down cpp11-compat in separate modules and align them better to the current RIOT structure, but first I need to understand this.

Thanks a lot!

CC @maribu

@gschorcht gschorcht deleted the sys/move_new_delete_dso_handle branch July 31, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants