Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

disable new/delete overrides when building as C code #959

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Noxybot
Copy link

@Noxybot Noxybot commented Nov 6, 2024

apparently, even if MI_USE_CXX is OFF, mimalloc still provides mangled definitions of new/delete operators. It causes inability to statically link mimaloc in our scenario, since we want to have our own overrides of new/delete functions.

apparently, even if MI_USE_CXX is OFF, mimalloc still provides mangled definitions of new/delete operators. It causes inability to statically link mimaloc in our scenario, since we want to have our own overrides of new/delete functions.
@res2k
Copy link
Contributor

res2k commented Nov 6, 2024

Uh, but wouldn't this change disable C++ new/delete overrides entirely when not compiling as C++?

The way MI_USE_CXX is described, and the fact that there are explicitly mangled symbols, suggests that "compiles as pure C, but provides C++ overrides" is a quite deliberately chosen scenario, and that those overrides are not supposed to be available only when MI_USE_CXX is enabled.
For one, I believe that, usually, C malloc/free and C++ new/delete are backed by the same allocator; so doing the same for overrides is probably the safe options.
And secondly, but more importantly, simply disabling the code when MI_USE_CXX is off will break any users that rely on the "built with C, overrides C++" behavior.

In other words: disabling the C++ overrides probably warrants a separate build option/preprocessor macro to check.

@Noxybot
Copy link
Author

Noxybot commented Nov 6, 2024

Uh, but wouldn't this change disable C++ new/delete overrides entirely when not compiling as C++?

Yes. But it was my anticipation from an option called MI_USE_CXX being set to OFF.

Why would we ever want to override global new/delete in C only code? It's C-only code, so those new/delete are not from C standard library.

@daanx
Copy link
Collaborator

daanx commented Dec 30, 2024

Bit tricky... if you don't want to override malloc/free/new/delete it is best to cmake with -DMI_OVERRIDE=OFF . However, this means there is no override for all those. There is no way to turn off just new/delete overriding.. Maybe we should have that but it is a bit dangerous to do this as most code assumes all are backed by the same allocator.

@daanx daanx changed the title fix new/delete overrides disable new/delete overrides when building as C code Dec 30, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants