microsoft / microsoft/mimalloc
MacOS Dynamic Linking Corruption Error
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
Using shared libmalloc fails with a SIGABRT.
### System Information
HW: Mac with Intel Chip
OS: macOS Big Sur 11.1
Toolchain: Mainline Clang 11.0
### Steps to Reproduce
1. Get mimalloc as described in the README.md, build and install.
2. Build the trivial program below
```CMakeLists.txt
cmake_minimum_required( VERSION 3.0 )
project(hello)
find_package(mimalloc 1.6 REQUIRED)
add_executable(hello hello.cpp)
target_link_libraries(hello PUBLIC mimalloc)
```
```cpp
int main() {
return 0;
}
```
### Additional Information
I presume I am not using the malloc override method but every system library and ObjC runtime library allocation call uses mimalloc nevertheless which causes libobjc's realizeClassWithoutSwift fail with memory corruption error whose format string can be found below.
```
"realized class %p has corrupt data pointer %p"
```
libmalloc-static works without any problem but still overrides any malloc calls.
### Debugging Backtrace
```
frame #0: 0x00007fff2032a792 libsystem_kernel.dylib`__abort_with_payload + 10
frame #1: 0x00007fff2032c1d9 libsystem_kernel.dylib`abort_with_payload_wrapper_internal + 80
frame #2: 0x00007fff2032c189 libsystem_kernel.dylib`abort_with_reason + 19
frame #3: 0x00007fff201f9b6a libobjc.A.dylib`_objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) + 114
frame #4: 0x00007fff201f9af8 libobjc.A.dylib`_objc_fatal(char const*, ...) + 135
frame #5: 0x00007fff201ebb77 libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 107
frame #6: 0x00007fff201ebc47 libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 315
frame #7: 0x00007fff201ebc71 libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 357
frame #8: 0x00007fff201ebc47 libobjc.A.dylib`realizeClassWithoutSwift(objc_class*, objc_class*) + 315
frame #9: 0x00007fff201d728c libobjc.A.dylib`_read_images + 2876
frame #10: 0x00007fff201d5f74 libobjc.A.dylib`map_images_nolock + 2441
frame #11: 0x00007fff201e701c libobjc.A.dylib`map_images + 59
frame #12: 0x000000010000dd2c dyld`dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) + 1778
frame #13: 0x000000010000decf dyld`dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) + 63
frame #14: 0x00007fff203448ef libdyld.dylib`_dyld_objc_notify_register + 113
frame #15: 0x00007fff201d54d9 libobjc.A.dylib`_objc_init + 1228
frame #16: 0x00007fff20191e3d libdispatch.dylib`_os_object_init + 13
frame #17: 0x00007fff2019efd1 libdispatch.dylib`libdispatch_init + 285
frame #18: 0x00007fff2a53a65b libSystem.B.dylib`libSystem_initializer + 224
```
### Questions
1. What am I doing wrong in regards to building and linking that causes libmalloc to override malloc calls? How do I use the non-intrusive way (mi_malloc* calls) described in the docs.
2. How do I track down what is causing this?
### Further Actions
1. I will try to use another allocator (jemalloc probably) to override allocation calls of system libraries to if I can reproduce the same error.
2. I will try and report a bug to Apple Developer but I do not think it will be much of an help.
Cheers.
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 with the README.md build instructions and the provided CMakeLists.txt, then reproduce the failure with hello.cpp on macOS Big Sur. Compare the shared libmalloc behavior with libmalloc-static and inspect the supplied dyld/libobjc backtrace. Done means identifying why system allocations are overridden and documenting how to use the non-intrusive mi_malloc* calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake, cpp, macos
- Domain
- build-system, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100