microsoft / microsoft/mimalloc

Heap corruption on macOS x64 in `getaddrinfo()` when using object file

Open
#512 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

This only happens on macOS x64 when linking via object file. If using an archive file, it works fine.

The specific object file being linked is `CMakeFiles/mimalloc-obj.dir/src/static.c.o`. This works on linux amd64, linux arm64, and macOS arm64.

CMake command:
```bash
cmake -DCMAKE_C_COMPILER=/usr/local/opt/llvm@12/bin/clang-12 -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@12/bin/clang++ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 -DCMAKE_BUILD_TYPE=Release -DMI_BUILD_SHARED=OFF -DMI_BUILD_STATIC=OFF -DMI_BUILD_TESTS=OFF -DMI_BUILD_OBJECT=ON .
```

Error message:
```objc
objc[81759]: realized class 0x7fff807d6088 has corrupt data pointer 0x1044044c0
```
Callstack:

```objc
__abort_with_payload (@__abort_with_payload:6)
abort_with_payload_wrapper_internal (@abort_with_payload_wrapper_internal:30)
abort_with_reason (@abort_with_payload_wrapper_internal:3)
_objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) (@_objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*):35)
_objc_fatal(char const*, ...) (@_objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*):3)
realizeClassWithoutSwift(objc_class*, objc_class*) (@realizeClassWithoutSwift(objc_class*, objc_class*):35)
realizeClassWithoutSwift(objc_class*, objc_class*) (@realizeClassWithoutSwift(objc_class*, objc_class*):87)
realizeClassWithoutSwift(objc_class*, objc_class*) (@realizeClassWithoutSwift(objc_class*, objc_class*):87)
_read_images (@_read_images:669)
map_images_nolock (@map_images_nolock:585)
map_images (@map_images:20)
dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (@dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool):446)
ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, bool, ImageLoader::RPathChain const&, char const*) (@ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, bool, ImageLoader::RPathChain const&, char const*):134)
dyld::link(ImageLoader*, bool, bool, ImageLoader::RPathChain const&, unsigned int) (@dyld::link(ImageLoader*, bool, bool, ImageLoader::RPathChain const&, unsigned int):101)
dlopen_internal (@dlopen_internal:138)
dlopen_internal(char const*, int, void*) (@dlopen_internal(char const*, int, void*):54)
dlopen (@dlopen:14)
_gai_load_libnetwork_once (@_gai_load_libnetwork_once:23)
__pthread_once_handler (@__pthread_once_handler:21)
_os_once_callout (@_os_once_callout:11)
pthread_once (@pthread_once:26)
si_addrinfo (@si_addrinfo:519)
getaddrinfo (@getaddrinfo:56)
.http.AsyncSocket.connect (@.http.AsyncSocket.connect:480)
.http.sendHTTPS (@.http.sendHTTPS:727)
.http.AsyncHTTP.do (@.http.AsyncHTTP.do:78)
std.Thread.Instance.entryFn.31375 (@std.Thread.Instance.entryFn.31375:137)
_pthread_start (@_pthread_start:54)
thread_start (@thread_start:8)
```

![image](https://user-images.githubusercontent.com/709451/147526340-09fbc0b4-ca22-4fed-a04f-15f6088cf964.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the macOS x64 build with the provided CMake command, focusing on CMakeFiles/mimalloc-obj.dir/src/static.c.o and comparing object-file and archive-file linking. Investigate the getaddrinfo() call stack and verify that the object build no longer produces the reported corrupt data pointer.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake, macos
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.