This is a part of allocator patch since I want to make sure the TLS for allocators are correctly handled. TLS dtors are not invoked on exit previously. This departures from major libc implementations. This PR fixes the issue by aligning the behavior with bionic. https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/exit.cpp I believe the finalization order is also consistent with glibc now: On main thread exiting: - pthread_key dtors are not called (unless exiting with `pthread_exit`) - `__cxa` based tls dtors are called - `::__cxa_atexit` and `::atexit` dtors are called - `.fini` dtors are called 