crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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 ofprintlis part of the Rust standard library. - Upon reviewing the code, it was found that the
tls-model=emulatedoption affects the rustc compilation behavior (either usingTPIDR_EL0or 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked c_cpp_dlopen_rust_so reproduction on Android or OHOS aarch64, repeating dlopen, the Rust call, and dlclose. Then inspect rustc and standard-library handling of tls-model=emulated, TPIDR_EL0, and lazy_init during shared-object unloading. Done means repeated load and unload cycles no longer crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, cpp, rust
- Domain
- compilers, mobile-dev, operating-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100