-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
We have a huge project that uses mimalloc, linked via static object override (i.e. we put mimalloc.o as the first object in the list).
We made the following code change locally: (I'm writing here a simplified but working version)
// track.h
#else
// no tracking
#include <unistd.h>
#define MI_TRACK_ENABLED 1
#define MI_TRACK_HEAP_DESTROY 1
#define MI_TRACK_TOOL "stderr"
#define mi_track_malloc_size(p,reqsize,size,zero) (void)write(2, "A", 1)
#define mi_track_free_size(p,_size) (void)write(2, "F", 1)
curiously, this crashes both in linux and freebsd, both with CXX on and off, but works on MacOs.
the executable prints a lot of "A"s and "F"s (so tracking does work) but at some point, another library that we link invokes the default free:
(here's the output of lldb in linux)
munmap_chunk(): invalid pointer
* thread #1, name = 'test', stop reason = signal SIGABRT
* frame #0: 0x0000fa0eceb93c18 libc.so.6`__pthread_kill_implementation(threadid=274941449560096, signo=6, no_tid=<unavailable>) at pthread_kill.c:44:76
frame #1: 0x0000fa0eceb4a8ac libc.so.6`__GI_raise(sig=6) at raise.c:26:13
...
frame #4: 0x0000fa0eceb9e1bc libc.so.6`malloc_printerr(str="") at malloc.c:5660:3
frame #5: 0x0000fa0eceb9e3bc libc.so.6`munmap_chunk(p=0x000005358a67c3d0) at malloc.c:3054:5
frame #6: 0x0000fa0eceba2a34 libc.so.6`__GI___libc_free(mem=<unavailable>) at malloc.c:3375:7
...
frame #12: 0x0000fa0ecefee470 libhs.so.5`hs_compile_multi + 132
...
I suspect that this behaviour is due to the following line:
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) && !MI_TRACK_ENABLED
// gcc, clang: use aliasing to alias the exported function to one of our `mi_` functions
but I'm not really sure this is intentional.
What's precisely the role of MI_TRACK_ENABLED?
thanks in advance for the help.
daanx
Metadata
Metadata
Assignees
Labels
No labels