microsoft / microsoft/mimalloc

Resolving `mimalloc-redirect.dll` seems to be initialized after `ucrtbase.dll`

Open
#668 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

At application start, I am seeing the following output:

```
mimalloc-redirect: error: mimalloc-redirect.dll seems to be initialized after ucrtbase.dll
(hint: try to link with 'mimalloc-override.lib' earlier on the command line?)
mimalloc-redirect: error: mimalloc-redirect.dll seems to be initialized after ucrtbased.dll
(hint: try to link with 'mimalloc-override.lib' earlier on the command line?)
mimalloc-redirect: warning: standard malloc is _not_ redirected! -- using regular malloc/free
```

The executable spawning these messages is linking `mimalloc.lib` (this is the `mimalloc.dll` import lib) as well as `mimalloc-redirect.lib` (the import lib for `mimalloc-redirect.dll`). Both of the DLLs are in the executable directory (of course, or nothing would run at all). Care was taken to ensure these libs appear first in the linker input list.

I have even tried declaring a static variable like so:

```
static int mv = mi_version();
```

in an attempt to force the mimalloc DLLs to load early, albeit to no avail. Running the exe under `WinDbg`, I'm finding the `ModLoad` of `mimalloc.dll` and the associated `mimalloc-redirect.dll` far too late, after other DLLs and `ucrtbased.dll` is loaded. After playing around with this a bit, I'm convinced that changing the ordering of the linker inputs appears to do little to influence the actual DLL loading order (latest MSVC at the time of this writing, Windows 10).

I did confirm that allocations are properly being redirected to mimalloc's allocation and deallocation routines however, immediately after entry into main (mimalloc's `DllMain` runs first, resulting in the messages above).

Do you have any suggestions on how to properly use the redirect DLL? Thanks!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the WinDbg ModLoad trace and the initialization messages from mimalloc-redirect.dll, then compare the observed loading order with the stated use of mimalloc.lib, mimalloc-redirect.lib, and mimalloc-override.lib. Check the behavior around DllMain and entry into main; done means establishing the correct redirect-DLL usage or documenting the remaining limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.