Open
Description
crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64
Senario:
- Compile a Rust source file into a shared object (.so) file.
- A C++ file uses dlopen to load the .so file and retrieve the target symbol.
- Call the Rust function within the loaded .so.
- Use dlclose to unload the .so file.
Related issues #134820
Here's the translation of the provided text:
Known Information:
- There is no issue with regular arm64, but disassembly reveals differences involving the use of
TPIDR_EL0
. - The main difference between ohos/an and arm64 Linux options is
has_thread_local=true and tls-model=emulated
, but these two compilation options do not seem to take effect when compiling the shared object (suspected that the standard library needs to be recompiled with these options). The implementation ofprintl
is part of the Rust standard library. - Upon reviewing the code, it was found that the
tls-model=emulated
option affects the rustc compilation behavior (either usingTPIDR_EL0
or emulated TLS, by affecting the LLVM backend).
This seems to be a bug in the rustc implementation. In the combination of Android and OHOS target platform options, during the println process, a thread-local variable is implicitly created, and the thread-local resources initialized through lazy_init are not properly released when dlclose is called.