Repository navigation
Open
Description
The problem does not occur on linux.
(lldb) r
Process 93543 launched: './bin/arangodbtests' (x86_64)
mimalloc: option 'secure': 0
mimalloc: option 'pool_commit': 0
mimalloc: process init: 0x7fffc980c3c0
mimalloc: debug level : 1
mimalloc: option 'show_errors': 1
mimalloc: error: trying to mi_free a pointer that does not point to a valid heap space: 0x111040000
mimalloc: assertion failed: at "/Users/jenkins/arangodb/3rdParty/mimalloc/src/options.c":121, _mi_error_message
assertion: "false"
Process 93543 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00007fffc0a21d42 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
-> 0x7fffc0a21d42 <+10>: jae 0x7fffc0a21d4c ; <+20>
0x7fffc0a21d44 <+12>: movq %rax, %rdi
0x7fffc0a21d47 <+15>: jmp 0x7fffc0a1acaf ; cerror_nocancel
0x7fffc0a21d4c <+20>: retq
Target 0: (arangodbtests) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x00007fffc0a21d42 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007fffc0b0f457 libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x00007fffc0987420 libsystem_c.dylib`abort + 129
frame #3: 0x00000001055e339f arangodbtests`_mi_assert_fail(assertion="false", fname="/Users/jenkins/arangodb/3rdParty/mimalloc/src/options.c", line=121, func="_mi_error_message") at options.c:136
frame #4: 0x00000001055e3e24 arangodbtests`_mi_error_message(fmt="trying to mi_free a pointer that does not point to a valid heap space: %p\n") at options.c:121
frame #5: 0x00000001055dfa53 arangodbtests`mi_free(p=0x0000000111040000) at alloc.c:212
frame #6: 0x00000001055dfbc5 arangodbtests`_ZdlPv(p=0x0000000111040000) at alloc-override.c:90
frame #7: 0x0000000105573910 arangodbtests`testing::internal::MakeAndRegisterTestInfo(test_case_name="ActiveFailover", name="creating_a_job_should_create_a_job_in_todo", type_param=0x0000000000000000, value_param=0x0000000000000000, code_location=(file = "/Users/jenkins/arangodb/tests/Agency/ActiveFailoverTest.cpp", line = 113), fixture_class_id=0x0000000109537728, set_up_tc=(arangodbtests`testing::Test::SetUpTestCase() at gtest.h:20190), tear_down_tc=(arangodbtests`testing::Test::TearDownTestCase() at gtest.h:20198), factory=0x0000000111020000)(), void (*)(), testing::internal::TestFactoryBase*) at gtest-all.cc:4053
frame #8: 0x00000001000ae474 arangodbtests`::__cxx_global_var_init.29() at ActiveFailoverTest.cpp:113
frame #9: 0x00000001000aee64 arangodbtests`_GLOBAL__sub_I_ActiveFailoverTest.cpp at ActiveFailoverTest.cpp:0
frame #10: 0x000000010f80ca1b dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 385
frame #11: 0x000000010f80cc1e dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
frame #12: 0x000000010f8084aa dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 338
frame #13: 0x000000010f807524 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 138
frame #14: 0x000000010f8075b9 dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 75
frame #15: 0x000000010f7f947a dyld`dyld::initializeMainExecutable() + 195
frame #16: 0x000000010f7fd8c6 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 3966
frame #17: 0x000000010f7f8249 dyld`dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 470
frame #18: 0x000000010f7f8036 dyld`_dyld_start + 54
(lldb)
In order to reproduce you could build the tests in this branch:
https://github.com/arangodb/arangodb/tree/feature/mimalloc
Metadata
Metadata
Assignees
Labels
No labels
Activity
ObiWahn commentedon Jun 26, 2019
I am actually wondering if this might be a bug in our code.
santagada commentedon Jun 26, 2019
Can't you put it in a debugger and take a look what exactly is happening? But it seems like there is memory being freed during global init (maybe because of a resize?).
Interesting points would be to know what is the state of the heap at that point or right before it, what allocated that memory. I completely don't know how the override works on osx, but we had some problems like that because of the ordering of the heap initialization and overrides.
daanx commentedon Jun 26, 2019
Ah, that is no good! I am on it -- tomorrow I have access to a Mac and will look into it. For now, the message implies that a pointer is freed that perhaps was allocated using some other
malloc? The_ZdlPvroutine is plaindeleteon a C++ object. (One thing it could be is that the overriding is kicking in too late where an object is allocated using the system malloc, and then freed by mimalloc.)Can you compile the debug version with
cmake ../.. -DMI_CHECK_FULL=ONto enable all assertions?By default, the macOS version uses "interpose" but only overrides the four basic functions,
malloc,free,reallocandcalloc-- I wonder if we need to interpose more functions, like the array new or something.By running cmake as
cmake ../.. -DMI_CHECK_FULL=ON -DMI_INTERPOSE=OFFwe use malloc zones instead of interpose --maybe that will work? This is still more experimental though.Tomorrow I will also look into it, but just wanted to offer some pointers. There is also the
MI_TLS_RECURSE_GUARDthat is enabled whenMI_INTERPOSEis enabled which prevents recursion as thedylibloader in macOS tries to allocate memory itself (withmimalloc) for thread local storage while themimallocmodule is still being loaded ... :(ObiWahn commentedon Jun 27, 2019
MI_INTERPOSE=OFF
MI_INTERPOSE=ON
I have just pulled the following change into the branch
arangodb/arangodb@6354372
That seems to resolve the problem here (The test fixture is using a builder in the constructor). It was made because we had issues with
thread_localvariables on windows.Unfortunately we end up with a different error in
curl(https://github.com/arangodb/arangodb/blob/devel/3rdParty/curl/curl-7.63.0/lib/url.c#L2708-L2761).I guess I use the overrides incorrectly.
strdupis used in one of your test - So it should work. I think it israther strange that within the same TU some of the functions get substituted while others seem to stay the same.
UPDATE -- running your static tests that use
strdupon the same machine works fine.ObiWahn commentedon Jun 28, 2019
Any idea why the allocations could be partially replaced?
After adding an extra override for
strdupthe test was successful. Do you think it is possible that there is some non overridden special allocation function that is used by clangs osxstrdupimplementation?daanx commentedon Jun 28, 2019
Great -- thanks for the debug output. I am currently working on a mac book through these problems too and addressing various issues. My feeling is indeed that the system
strdupcalls an internal allocation routine... not sure. Also, I read somewhere that one cannot interpose functions in system libraries? So perhaps more is needed. For now, I will concentrate on making at least the basic scenarios work and protect against recursion in the thread local storage allocation.daanx commentedon Jul 3, 2019
I think the latest
devbranch should now work withMI_INTERPOSE=ONonstatic-overloadtest. The dynamic one is still being worked on.ObiWahn commentedon Jul 3, 2019
Thank You! Unfortunately we have still problems.
cupertino:arangodb-build jenkins$ cmake -DCMAKE_BUILD_TYPE=Debug -DMI_CHECK_FULL=ON -DMI_INTERPOSE=ON ../arangodbon our mimalloc branchdaanx commentedon Jul 3, 2019
Good to hear there is progress -- just to confirm , the
static-overridetest passes now right?Also, the new error is "better" as it is an assertion failure in mimalloc (so happy we have thorough invariant checking!), and it seems to have started the actual program instead of having trouble during the dyld loading.
Actually, this could be related to another issue in the
devbranch -- can you check you have the latestdevcommits (in particular 1587058) ? Also, cmake the debug version with-DMI_CHECK_FULL=ONto ensure all invariants are checked continuously.Apologies for your trouble, but your feedback is very helpful to get automatic overriding to work well on macOS.
ObiWahn commentedon Jul 4, 2019
Sources upgraded maybe 3 hours ago from
mimalloc/masterThank you for your time!
[-]Tries to free invalid heap space on OSX[/-][+]OSX debugging[/+]daanx commentedon Jul 4, 2019
Ah.. frustrating.. on Linux/BSD systems this is so easy with LD_PRELOAD ... :-)
Anyway, I will keep working on this -- I have the macOS machine available maybe tomorrow but otherwise next week. Apologies for your troubles getting the overriding to work for you.
ObiWahn commentedon Jul 16, 2019
I there anything I can do? Should I try a newer version?
daanx commentedon Jul 16, 2019
Ah sorry for not following up -- I have been just a bit too busy to look into it further. However, I have been working on improving the situation of dynamic overriding on Windows which should also help on the macOS side. I will try to look into it later today or otherwise tomorrow as I do have a macbook available now for testing.
ObiWahn commentedon Jul 17, 2019
No problem it was the same for me, I actually forgot to check the thread for some days ;)
erikolofsson commentedon Aug 5, 2019
MacOS system libraries will call
freeon any pointer, it doesn't even have to be previously allocated. I have seen system library code (I believe it was ObjC, or swift runtime) where it stores either an allocated pointer, or a pointer to constant data and then callsfreeon it, letting the memory allocators figure out if it's owned or not.The implementation is required to check if any of the zones own a pointer. If you look at the documentation for
_malloc_zone_t.Basically the default malloc implementation will go through all registered malloc zones and call
size(zone, ptr)until it finds a zone that claims ownership of that pointer and then callfreeon that zone.What I have done in my memory manager/interposer implementation to get around the most annoying performance implications of this is:
_setjmpand catching segfaults if the checked location is not a valid pointersize()michaeleisel commentedon Jan 27, 2020
Why not replace the default zone, rather using interposing, like jemalloc does: https://github.com/jemalloc/jemalloc/blob/dev/src/zone.c
michaeleisel commentedon Jan 27, 2020
Oops, I see that there is indeed a zone-based way of injecting mimalloc
michaeleisel commentedon Jan 27, 2020
Daan (@daanx) just curious to see what the status of this is. I'm having similar issues myself
daanx commentedon Mar 7, 2020
Finally I think the current version of mimalloc
v1.6.1is working on macOSX.Thank you Erik Olofsson (@erikolofsson) for your insights! (I did take a slightly different approach though)
I did a bit of testing with dynamic and static linking and it worked for those cases. I did a bit of light benchmarking and mimalloc seems quite a bit faster than the default allocator:
this is despite it being not yet as optimal as it could be as it needs to check pointers before freeing if they belong to our zone.
michaeleisel commentedon Mar 11, 2020
It's crashing for me when using XcodeProj
michaeleisel commentedon Mar 27, 2020
Also, one thing to be aware of is mimalloc may need to always check that the pointer it's being given to free is one that was allocated by it, as Apple can sometimes give improper pointers to be freed
michaeleisel commentedon Mar 27, 2020
Ah, explained much more thoroughly by Eric above 😛
daanx commentedon Apr 6, 2020
Michael Eisel (@michaeleisel): do you mean there is crash when dynamically overriding malloc with mimalloc in XcodeProj ? Not when you create programs using mimalloc directly right?
The comment by Erik Olofsson (@erikolofsson) is quite discouraging -- that is just terrible for allocation performance on macOS. :-( Currently, the regular
freeis checking for ownership on macOS (usingcfree) but thezone_freecalls justmi_free.Can you try to change that into a call to
mi_cfreeto see if that works for XCodeProj?Harold2017 commentedon Jul 1, 2020
my code works well with
tcmalloc/jemalloc/tbbmallocbut failed withmimallocdynamic override on osx gives me bus error here
mimalloc version: 1.6 (git master branch)
same bus error occurs with or without disable build-in libc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")compile with AddressSanitizer, in lldb:
================================================================= ==12137==ERROR: AddressSanitizer: negative-size-param: (size=-8) #0 0x1044c8f61 in wrap___bzero (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x37f61) #1 0x7fff38a85d6c in -[__NSArrayM insertObject:atIndex:] (CoreFoundation:x86_64h+0x1fd6c) #2 0x7fff38a85401 in _createUniqueStringWithUTF8Bytes (CoreFoundation:x86_64h+0x1f401) #3 0x7fff38a852f7 in parseStringTag (CoreFoundation:x86_64h+0x1f2f7) #4 0x7fff38a8300d in parseXMLElement (CoreFoundation:x86_64h+0x1d00d) #5 0x7fff38a83737 in parseXMLElement (CoreFoundation:x86_64h+0x1d737) #6 0x7fff38a8310a in parseXMLElement (CoreFoundation:x86_64h+0x1d10a) #7 0x7fff38a82186 in _CFPropertyListCreateFromUTF8Data (CoreFoundation:x86_64h+0x1c186) #8 0x7fff38b886d8 in _CFPropertyListCreateWithData (CoreFoundation:x86_64h+0x1226d8) #9 0x7fff38a81496 in CFPropertyListCreateWithData (CoreFoundation:x86_64h+0x1b496) #10 0x7fff38ad21b9 in _CFCopyVersionDictionary (CoreFoundation:x86_64h+0x6c1b9) #11 0x7fff38ad2123 in ___CFCopySystemVersionDictionary_block_invoke (CoreFoundation:x86_64h+0x6c123) #12 0x7fff72a8b657 in _dispatch_client_callout (libdispatch.dylib:x86_64+0x2657) #13 0x7fff72a8c7dd in _dispatch_once_callout (libdispatch.dylib:x86_64+0x37dd) #14 0x7fff38ad20f9 in _CFCopySystemVersionDictionary (CoreFoundation:x86_64h+0x6c0f9) #15 0x7fff38b470ba in _CFCopySystemVersionDictionaryValue (CoreFoundation:x86_64h+0xe10ba) #16 0x7fff38b46f9b in ___CFOperatingSystemVersionGetCurrent_block_invoke (CoreFoundation:x86_64h+0xe0f9b) #17 0x7fff72a8b657 in _dispatch_client_callout (libdispatch.dylib:x86_64+0x2657) #18 0x7fff72a8c7dd in _dispatch_once_callout (libdispatch.dylib:x86_64+0x37dd) #19 0x7fff38b46f7f in _CFOperatingSystemVersionGetCurrent (CoreFoundation:x86_64h+0xe0f7f) #20 0x7fff3b1e3b21 in -[NSProcessInfo operatingSystemVersion] (Foundation:x86_64+0xc3b21) #21 0x1136203f3 in QOperatingSystemVersion::current() (QtCore:x86_64+0x1f3f3) #22 0x113616178 (QtCore:x86_64+0x15178) #23 0x1000791e2 in ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (dyld:x86_64+0x1b1e2) #24 0x1000795ed in ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (dyld:x86_64+0x1b5ed) #25 0x10007400a in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x1600a) #26 0x100073f75 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x15f75) #27 0x100073f75 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x15f75) #28 0x100073f75 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x15f75) #29 0x100073f75 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x15f75) #30 0x100073f75 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x15f75) #31 0x100072013 in ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (dyld:x86_64+0x14013) #32 0x1000720b3 in ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (dyld:x86_64+0x140b3) #33 0x1000605e5 in dyld::initializeMainExecutable() (dyld:x86_64+0x25e5) #34 0x100065af7 in dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (dyld:x86_64+0x7af7) #35 0x10005f226 in dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) (dyld:x86_64+0x1226) #36 0x10005f024 in _dyld_start (dyld:x86_64+0x1024) Address 0x04d5194b06b8 is a wild pointer. SUMMARY: AddressSanitizer: negative-size-param (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x37f61) in wrap___bzero ==12137==ABORTING (lldb) AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report. Process 12137 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = Negative size used when accessing memory frame #0: 0x00000001044df230 libclang_rt.asan_osx_dynamic.dylib`__asan::AsanDie() libclang_rt.asan_osx_dynamic.dylib`__asan::AsanDie: -> 0x1044df230 <+0>: pushq %rbp 0x1044df231 <+1>: movq %rsp, %rbp 0x1044df234 <+4>: pushq %rbx 0x1044df235 <+5>: pushq %rax Target 0: (test) stopped. (lldb) thread info -s thread #1: tid = 0x2a4e3, 0x00000001044df230 libclang_rt.asan_osx_dynamic.dylib`__asan::AsanDie(), queue = 'com.apple.main-thread', stop reason = Negative size used when accessing memory { "access_size" : 0, "access_type" : 0, "address" : 0, "description" : "negative-size-param", "instrumentation_class" : "AddressSanitizer", "pc" : 0, "stop_type" : "fatal_error" }anthonyyya commentedon Jan 26, 2024
I am also getting the following errors. Is it safe to say that the static object implementation doesn't work for OSX Daan (@daanx) ?