Prepend mimalloc lib in EXE link order; add MRTest gate#6176
Merged
Conversation
`<ForceSymbolReferences>mi_version` pulls mimalloc.dll into the EXE import table but doesn't control its position. With other libs (cpr/gmock/libcurl/fmt/jsoncpp) added by vcpkg's auto-link in alphabetical order, `mimalloc-debug.dll` landed at position 7 in MRTest.exe; the Windows loader resolved ucrtbase before mimalloc-redirect.dll and the redirect bailed with "standard malloc is _not_ redirected!" — `mi_is_redirected()` returned 0. Fix: a shared `source/MimallocRedirect.props` prepends the mimalloc import lib to `<AdditionalDependencies>` so it's the first PE import. `Exists()` probes pick `mimalloc(-debug).dll.lib` (3.x) or `mimalloc(-debug).lib` (2.x), so the same props works against any vcpkg snapshot. The CMake helper does the same via `set_property` + prepended `LINK_LIBRARIES`. Verified by new gtest `MRMesh.MimallocRedirectActive` in MRTest, gated by `MIMALLOC_DISABLE_REDIRECT=1` (mimalloc's own kill-switch). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fedr
approved these changes
May 28, 2026
The two `mi_is_redirected` / `mi_is_in_heap_region` extern decls were typed as `int`, but mimalloc.h declares them as `bool`. MSVC returns `bool` in the low byte of EAX; reading it back as `int` picks up garbage in the upper 24 bits. Local Debug happened to zero those bits so the test passed; CI Release surfaced `-980287487` and EXPECT_EQ against `1` failed. Match the real signature and use EXPECT_TRUE (idiomatic for bool). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<ForceSymbolReferences>mi_versionpullsmimalloc.dllinto the EXE import table but doesn't control its position. With other libs (cpr/gmock/libcurl/fmt/jsoncpp) added by vcpkg's auto-link in alphabetical order,mimalloc-debug.dlllanded at position 7 inMRTest.exe; the loader resolveducrtbasebeforemimalloc-redirect.dll, the redirect bailed withstandard malloc is _not_ redirected!, andmi_is_redirected()returned0.source/MimallocRedirect.propsprepends the mimalloc import lib to<AdditionalDependencies>so it becomes the first PE import.Exists()probes pickmimalloc(-debug).dll.lib(3.x) ormimalloc(-debug).lib(2.x) so the same props works against any vcpkg snapshot — sidesteps the lib-name version trap that previously affected the older-vcpkg runner.cmake/Modules/MimallocRedirect.cmakemirrors the prepend on the CMake side viaset_property+ reorderedLINK_LIBRARIES(call-site order no longer matters).MRMesh.MimallocRedirectActivegtest inMeshLib/source/MRTest/MRMimallocRedirectTests.cppassertsmi_is_redirected() == 1andmi_is_in_heap_region(malloc(64)) == 1. Skipped whenMIMALLOC_DISABLE_REDIRECT=1(mimalloc's own kill-switch).Verified locally on Debug|x64:
dumpbin /imports MRTest.exeshowsmimalloc-debug.dllas the first entry; full MRTest suite is 295/295 green. The MRApp side (MeshInspector.exe) is wired up via a matching change in the consumer repo, with the submodule pointer bumped to this commit there.Test plan
full-ci+disable-build-*for every non-Windows platform to focus coverage).Exists()probe falls through to the.lib(not.dll.lib) variant; noLNK1181.MRMesh.MimallocRedirectActivepasses.set MIMALLOC_DISABLE_REDIRECT=1 && MRTest.exe --gtest_filter=MRMesh.MimallocRedirectActive→ SKIPPED.