Skip to content
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

Document interaction of MI_OVERRIDE / MI_INTERPOSE options with static and dynamic builds #71

Closed
gnzlbg opened this issue Jul 3, 2019 · 2 comments

Comments

@gnzlbg
Copy link

gnzlbg commented Jul 3, 2019

IIUC if I compile src/static.c and statically link it to my binary, all calls to malloc and similar APIs will be overriden by mimalloc. Is this correct on all platforms ? (Windows, Linux, MacOSX, Android, FreeBSD, OpenBSD, NetBSD, etc.) ?

That is, it doesn't matter whether I define MI_OVERRIDE / MI_INTERSPERSE for this configuration ?

It would be worth it to document the CMake options somewhere, explaining specifically what they do, and how they interact with the different ways in which the library can be built.

@daanx
Copy link
Collaborator

daanx commented Jul 4, 2019

I will try to document this better -- unfortunately, the situation for each platform is so different :-(
If you compile the static object file, you still need to define MI_OVERRIDE so all calls are forwarded to the mi_ variants. On Linux and BSD you can link with the object file first so it has priority when linking.

On Windows, and I believe macOS, this does not work -- due to link errors and/or non-flat namespaces. It can be made to work on Windows by turning off the specific linker errors -- see the Visual Studio projects for details.

The MI_INTERSPERSE should be MI_INTERPOSE I believe? That is specific for macOS and currently the only way to override standard malloc automatically when linking. Currently this works for static linking only (overriding with dynamic linking on macOS is still WIP).

On Windows, see the Visual Studio project for overriding mimalloc when dynamic linking.

Hope this helps!

@gnzlbg
Copy link
Author

gnzlbg commented Jul 4, 2019

The MI_INTERSPERSE should be MI_INTERPOSE I believe?

Yes, sorry, that was a typo.

@gnzlbg gnzlbg changed the title Document interaction of MI_OVERRIDE / MI_INTERSPERSE options with static and dynamic builds Document interaction of MI_OVERRIDE / MI_INTERPOSE options with static and dynamic builds Jul 4, 2019
@daanx daanx closed this as completed Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants