Skip to content

crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64 #135815

Open
@Rust401

Description

@Rust401

crash when dlopen/dlclose rust-made *.so multi-times on android/ohos aarch64

Senario:

  1. Compile a Rust source file into a shared object (.so) file.
  2. A C++ file uses dlopen to load the .so file and retrieve the target symbol.
  3. Call the Rust function within the loaded .so.
  4. Use dlclose to unload the .so file.

Related issues #134820

reproduction code

Here's the translation of the provided text:

Known Information:

  1. There is no issue with regular arm64, but disassembly reveals differences involving the use of TPIDR_EL0.
  2. 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 of printl is part of the Rust standard library.
  3. Upon reviewing the code, it was found that the tls-model=emulated option affects the rustc compilation behavior (either using TPIDR_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-discussionCategory: Discussion or questions that doesn't represent real issues.O-androidOperating system: Android

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions