Closed folowing closed 3 years ago
There were recently some commits related to the M1. Does this still happen with the latest dev-slice
? I guess I will need to get an M1 soon so I can test properly :-)
There were recently some commits related to the M1. Does this still happen with the latest
dev-slice
? I guess I will need to get an M1 soon so I can test properly :-)
I pulled latest sources and checked it again just now and there is still a problem
:-( difficult to guess what goes wrong -- I need an M1 to properly debug/port mimalloc. Hmm, I'll look into getting a test M1 mac mini perhaps.
Looking at #343 it seems #xhochy was able to run mimalloc on the M1; -- I wonder what has changed? Perhaps a renaming from __MACH__
to __APPLE__
?
I attempted to apply the following changes:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca2ce3e..10c7db7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -362,7 +362,7 @@ if (MI_BUILD_TESTS)
target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags})
target_include_directories(mimalloc-test-stress PRIVATE include)
- target_link_libraries(mimalloc-test-stress PRIVATE mimalloc ${mi_libraries})
+ target_link_libraries(mimalloc-test-stress PRIVATE mimalloc-static ${mi_libraries})
enable_testing()
add_test(test_api, mimalloc-test-api)
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index 449893b..47290a9 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -712,7 +712,8 @@ static inline void* mi_tls_slot(size_t slot) mi_attr_noexcept {
#elif defined(__aarch64__)
void** tcb; UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
- __asm__ volatile ("mrs %0, tpidrro_el0" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidrro_el0\n"
+ "bic %0, %0, #0x7\n" : "=r" (tcb));
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
#endif
@@ -739,7 +740,8 @@ static inline void mi_tls_slot_set(size_t slot, void* value) mi_attr_noexcept {
#elif defined(__aarch64__)
void** tcb; UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
- __asm__ volatile ("mrs %0, tpidrro_el0" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidrro_el0\n"
+ "bic %0, %0, #0x7\n" : "=r" (tcb));
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
#endif
@@ -749,8 +751,7 @@ static inline void mi_tls_slot_set(size_t slot, void* value) mi_attr_noexcept {
static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
#if defined(__aarch64__) && defined(__APPLE__) // M1
- // on macOS on the M1, slot 0 does not seem to work, so we fall back to portable C for now. See issue #354
- return (uintptr_t)&_mi_heap_default;
+ return (uintptr_t)mi_tls_slot(0);
#elif defined(__BIONIC__) && (defined(__arm__) || defined(__aarch64__))
// on Android, slot 1 is the thread ID (pointer to pthread internal struct)
return (uintptr_t)mi_tls_slot(1);
Then, the executable mimalloc-test-stress
, linked to static libmimalloc.a
, seems to work. However, I still failed to run the same program dynamically linked to libmimalloc.dylib
yet.
I think this is fixed now in the latest releases (v1.7.2, and v2.0.2)
mimalloc version: 2.0.0 or dev-slice
Crash Reports