-
Notifications
You must be signed in to change notification settings - Fork 865
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
Resolving mimalloc-redirect.dll
seems to be initialized after ucrtbase.dll
#668
Comments
The easiest way is to use the
lists the current import table, and
rewrites |
Thanks @daanx that did seem to do the trick and I see that |
ah great to hear it works for you. I do not know of a reliable way to do this at link time :-( but it does help if the mimalloc-redirect.lib is the first one on the linker command line; try to see if that is actually the case as often other "default" libs are put before it by msvc |
This is the same thing I was seeing in my issue #542. Although, it was mixed in with a number of other issues I was dealing with at the time. I think the other ones basically got sorted out, but I never found any workaround for having to run I also find it slightly disturbing that a |
I ended up taking an evening to quickly whip up this tool which does a quick-and-dirty import data directory reordering in-place in a PE file. For getting things to work with mimalloc, I found you only need to reorder the |
I found that the message was accurate, but I did need it to be the very first item in <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<!-- Force mimalloc to be the first library. It needs to come first so that mimalloc-redirect.dll can do its magic.
This also needs to be done after Microsoft.Cpp.targets, since %(AdditionalDependencies) gets modified more than once. -->
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>
$(MiMallocLib);
%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
(And |
@daanx Hello, I tried minject.exe, but it didn't work when executed in cmd and PowerShell. I linked my exe with mimalloc-override.dll, it worked as expected in VS and git bash. But when i executed the program in cmd and PowerShell, i got the error "mimalloc-redirect.dll seems to be initialized after ucrtbase.dll" I tried to use minject.exe and it showed mimalloc-redirect.dll is definitely in first place: 0: mimalloc-redirect.dll But the modifed exe still got the same error when executed in cmd and PowerShell. So what happened in cmd or PowerShell? And any idea to resolve this error? |
If I use the Developer PowerShell in Visual Studio(in "Tools" -> "Command Line"), it works, but it don't in Developer Command Prompt and normal PowerShell. The more interesting thing is, if i open a terminal in VS(in "View" -> "Terminal"), both the Developer Command Prompt and Developer PowerShell terminal work. IMO, some environment variables or options had an effect on how the ucrtbase.dll loads, but I don't know which they are and how to set them correctly. Can anyone tell what's the difference between a normal PowerShell and a VS Developer PowerShell? |
At application start, I am seeing the following output:
The executable spawning these messages is linking
mimalloc.lib
(this is themimalloc.dll
import lib) as well asmimalloc-redirect.lib
(the import lib formimalloc-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:
in an attempt to force the mimalloc DLLs to load early, albeit to no avail. Running the exe under
WinDbg
, I'm finding theModLoad
ofmimalloc.dll
and the associatedmimalloc-redirect.dll
far too late, after other DLLs anducrtbased.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!
The text was updated successfully, but these errors were encountered: