microsoft / microsoft/mimalloc
Avoiding mi_cfree on mac interpose mode
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
I think you might just need to interpose malloc_default_zone too. This is what asan ends up doing, among other things (I suspect the other things it interposes are related to asan's functionality): https://github.com/llvm/llvm-project/blob/350fafabe9d3bda75e80bf077303eb5a09130b53/compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc#L85
You also can try `__attribute__((constructor(0)))` to try to get loaded earlier than with normal `__attribute__((constructor))`. Not sure if that matters for shared libs, probably not, but it can help for static linking.
This is a somewhat messy commit (includes unrelated whitespace changes, XXX comments, and doesn't reuse the existing interpose stuff) that does these and seems to work for me. https://github.com/thomcc/mimalloc/commit/52b5237028a27644ffc4e8a671d7b884a2fa7379
Unfortunately, IDK how to trigger the bad behavior that lead to you using mi_cfree in the first place, so IDK if it fixes it. That said, if you want I can PR it.
Still it's a bummer that doing this in a statically linked build isn't viable how it is on other unixes...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading compiler-rt/lib/sanitizer_common/sanitizer_malloc_mac.inc at the linked malloc_default_zone interposition code, then compare the proposed mimalloc commit 52b5237028a27644ffc4e8a671d7b884a2fa7379. Determine whether the interposition and constructor changes prevent the reported mi_cfree behavior, noting that the issue does not provide a way to reproduce it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, macos
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100