Skip to content

Prepend mimalloc lib in EXE link order; add MRTest gate#6176

Merged
Grantim merged 2 commits into
masterfrom
feat/mimalloc-redirect-test
May 28, 2026
Merged

Prepend mimalloc lib in EXE link order; add MRTest gate#6176
Grantim merged 2 commits into
masterfrom
feat/mimalloc-redirect-test

Conversation

@Grantim
Copy link
Copy Markdown
Contributor

@Grantim Grantim commented May 28, 2026

Summary

  • <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 loader resolved ucrtbase before mimalloc-redirect.dll, the redirect bailed with standard malloc is _not_ redirected!, and mi_is_redirected() returned 0.
  • New shared source/MimallocRedirect.props prepends the mimalloc import lib to <AdditionalDependencies> so it becomes 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 — sidesteps the lib-name version trap that previously affected the older-vcpkg runner.
  • cmake/Modules/MimallocRedirect.cmake mirrors the prepend on the CMake side via set_property + reordered LINK_LIBRARIES (call-site order no longer matters).
  • New MRMesh.MimallocRedirectActive gtest in MeshLib/source/MRTest/MRMimallocRedirectTests.cpp asserts mi_is_redirected() == 1 and mi_is_in_heap_region(malloc(64)) == 1. Skipped when MIMALLOC_DISABLE_REDIRECT=1 (mimalloc's own kill-switch).

Verified locally on Debug|x64: dumpbin /imports MRTest.exe shows mimalloc-debug.dll as 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

  • CI: all Windows configs green (this PR is labeled full-ci + disable-build-* for every non-Windows platform to focus coverage).
  • Older-vcpkg runners (mimalloc 2.x): Exists() probe falls through to the .lib (not .dll.lib) variant; no LNK1181.
  • MRMesh.MimallocRedirectActive passes.
  • Negative manual check: set MIMALLOC_DISABLE_REDIRECT=1 && MRTest.exe --gtest_filter=MRMesh.MimallocRedirectActive → SKIPPED.

`<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>
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>
@Grantim Grantim merged commit 68cae6b into master May 28, 2026
37 checks passed
@Grantim Grantim deleted the feat/mimalloc-redirect-test branch May 28, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants