TLS (Thread Local Storage) is not introduced until Android 10, and the TLS Slot ABI is not designed to be stable. Force using Emulated TLS for better compatibility. The error message is as follows. ``` = note: ld.lld: error: undefined symbol: __aeabi_read_tp >>> referenced by static.c >>> 98cfcaec7182b1d8-static.o:(mi_free) in archive /tmp/rustcp5Rvgx/liblibmimalloc_sys-7086a69efa004ab8.rlib >>> referenced by static.c >>> 98cfcaec7182b1d8-static.o:(_mi_arena_segment_clear_abandoned) in archive /tmp/rustcp5Rvgx/liblibmimalloc_sys-7086a69efa004ab8.rlib >>> referenced by static.c >>> 98cfcaec7182b1d8-static.o:(_mi_arena_segment_clear_abandoned) in archive /tmp/rustcp5Rvgx/liblibmimalloc_sys-7086a69efa004ab8.rlib >>> referenced 9 more times clang-17: error: linker command failed with exit code 1 (use -v to see invocation) ``` --- a/build.rs +++ b/build.rs @@ -24,7 +28,10 @@ let dynamic_tls = env::var("CARGO_FEATURE_LOCAL_DYNAMIC_TLS").is_ok(); - if target_family == "unix" && target_os != "haiku" { + if target_family == "unix" && target_os == "android" { + build.flag_if_supported("-femulated-tls"); + } + else if target_family == "unix" && target_os != "haiku" { if dynamic_tls { build.flag_if_supported("-ftls-model=local-dynamic"); } else { --- a/c_src/mimalloc/include/mimalloc/prim.h +++ b/c_src/mimalloc/include/mimalloc/prim.h @@ -147,7 +147,7 @@ #elif defined(__GNUC__) && ( \ (defined(__GLIBC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \ || (defined(__APPLE__) && (defined(__x86_64__) || defined(__aarch64__))) \ - || (defined(__BIONIC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \ + || (defined(__BIONIC__) && 0 && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \ || (defined(__FreeBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \ || (defined(__OpenBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \ ) @@ -206,7 +206,7 @@ } static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept { - #if defined(__BIONIC__) + #if defined(__BIONIC__) && 0 // issue #384, #495: on the Bionic libc (Android), slot 1 is the thread id // see: https://github.com/aosp-mirror/platform_bionic/blob/c44b1d0676ded732df4b3b21c5f798eacae93228/libc/platform/bionic/tls_defines.h#L86 return (uintptr_t)mi_prim_tls_slot(1);