Skip to content

Unloading Rust-made SOs can lead to segfaults in host program #52138

Closed
@SoniEx2

Description

@SoniEx2

Steps to reproduce:

  1. Have two versions of libplugin_written_in_rust.so (rust always adds that "lib" prefix for some reason)
  2. Load one of them
  3. Unload it
  4. Load the other
  5. ???
  6. Segfault

I don't seem to get the crashes if I have two different plugins under different names.

This is an issue for the hexchat-plugin crate, and (probably) anything that lets you write plugins in Rust. (rlua? I haven't entirely tested this)

(No, this isn't an issue with hexchat's module system. Hexchat's module system is basically just dlopen and dlclose, at least on Linux.)

(No, this shouldn't be dismissed as "unsafe and dangerous"/"unsupported", because if you have heap-allocated globals in your rust code, all you're gonna get is some memory/resource leaks, which aren't considered unsafe. This really shouldn't be segfaulting.)

$ rustc --version --verbose
rustc 1.27.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.27.0
LLVM version: 6.0

(Note: this has been a thing for a while, it's not new in 1.27.0.)

Other (important?) things to note:

  • Only happens if code is changed. Changing strings doesn't seem to trigger the issue (or I was just very (un)lucky). (but maybe optimizations can have an effect, for example dead code elimination based on a constant?)
  • Happens in both debug and release builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions