c++ code frequency dlclose/dlopen *.so compiled by rust cause crash #134820
Labels
A-dynamic-library
Area: Dynamic/Shared Libraries
A-linkage
Area: linking into static, shared libraries and binaries
C-discussion
Category: Discussion or questions that doesn't represent real issues.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
reproduction code upload to this repo
Scenario:
aarch64-linux-android
then we will find the segment fault
info from logcat
Based on my analysis, this caused by
pthread_key_create
(which was never deleted) from emutls.cThe process is as follows
Simply put:
1. After dlopen, a threadlocal variable generated when rust func was first called use
pthread_key_create
, but the matchingpthread_key_delete
was not called when dlclose.2. Each
dlopen -> call -> dlclose
loop will occupy a key_map util the BIONIC_PTHREAD_KEY_COUNT was arrived.3. Then the abort happens.
But the same code ran happliy on an x86 Linux machine.
We hack libc(both bionic for android and glibc2.35 for my ubuntu 22.04).
We found that android(which use bionic on arm64 cpu) will generate a thread_local variable when rust func was first called after dlopen use
pthread_key_create
(code in bionic libc).But linux(which user glibc on x86 cpu) not call pthread_key_create(Maybe glibc use another mechanism to use manager threadlocal variable)
So, my final question is:
The text was updated successfully, but these errors were encountered: