-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[C++] Use malloc/free instead of k_malloc/k_free in operator new/delete #20678
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
[C++] Use malloc/free instead of k_malloc/k_free in operator new/delete #20678
Conversation
@@ -1,5 +1,5 @@ | |||
tests: | |||
misc.app_dev.cpp: | |||
arch_exclude: posix | |||
build_only: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this excluded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test case to cover new/delete and this onde can run in CI, before this change the test case did not contained any runnable test and was only build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right but why did you exclude qemu_x86_coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason qemu_x86_coverage hangs when running with c++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a bug filed on this, since this is an indicator that gathering code coverage will fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created bug report #20729, looks like our own coverage code ends up in a endless loop
@vanwinkeljan What is the motivation for doing this change? |
This isn't what I expected. Please check my understanding:
At this point I have no clue of how all the different C++ and libc Kconfig features interact. I'm particularly concerned here that it might become easy for somebody to replace new/delete in a newlib-based libc++ (which already implements them using malloc), which would be gratuitous and risky. That mess pre-dates this PR, but I'm uncomfortable with changing it at this point. For the purposes of settling the basic need in #18990 to get rid of using kernel memory for C++ objects is it not sufficient to just replace the |
We could just drop the option of using the zephyr version of new/delete if a libc++ is used (it uses malloc internally). Actually this is maybe the most correct and clean way forward and actually the Kconfig could be dropped in this way. Shall I update the PR to get a feeling how it would look like? |
@pabigot @andrewboie Another surprise is the failing CI, it seems that virtual destructors are calling |
Yes, why would we not want to do this? Maybe this is historical cruft but we should not be providing our own versions of these functions if the C library already provides them! |
Use malloc/free instead of k_malloc/k_free in operator new/delete implementation or use libstdc++ implementation when available. Further updated cpp_synchronization sample to enable minimal libc heap as virtual destructor requires operator delete which depends on free. Signed-off-by: Jan Van Winkel <[email protected]>
Extended c++ test case to cover the zephyr implementation of new and delete. Signed-off-by: Jan Van Winkel <[email protected]>
604697f
to
0a151d0
Compare
@dleach02 do you want this PR in 2.1? It has a medium prio bug associated. |
@vanwinkeljan, yes we should merge this to clear the medium bug. |
Use malloc/free instead of k_malloc/k_free in operator new/delete and extended test cases to cover new/delete.
Fixes: #18990