Skip to content

Figure out and document how registration works when plugins are loaded dynamically by dlopen #1

Open

Description

@dtolnay
No description provided.

Activity

  1. dtolnay commented on Dec 24, 2018

    @dtolnay
    OwnerAuthor

    We may need to set up a dtor to unregister plugins on dlclose.

  2. mmastrac commented on Dec 29, 2018

    @mmastrac

    Note: #[dtor] might not be enough to unregister plugins as it is currently using a libc::atexit hook. I may have to figure out a way to generate the appropriate library hooks for the ctor library for shared libraries.

    I believe that I'd have to change over to using __cxa_atexit for this case. In the meantime I should also add a caveat noting that #[dtor] is probably not yet appropriate for shared libraries.

  3. dtolnay commented on Dec 29, 2018

    @dtolnay
    OwnerAuthor

    Thanks for the warning! I filed mmastrac/linktime#3 to follow up.

  4. mmastrac commented on Dec 30, 2018

    @mmastrac

    While trying to fully understand how this works, I also discovered this comment that details conditions under which OSX libraries won't be unloaded. In this case, the dtor won't run until process exit.

    It turns out that dragging in core::fmt is enough to prevent a rust cdylib from unloading.

  5. mathstuf commented on Nov 11, 2019

    @mathstuf
    Contributor

    Also note that the lifetime of any symbols stored in the loaded plugin is tied to the library being loaded. So any function pointers stored anywhere while it is loaded become undefined behavior. Maybe if there were some way to attach a library lifetime to any symbol lookups, that would work to avoid unsafe behavior? Marking library unloading as unsafe with a big comment about the perils of unloading might be sufficient.

  6. Hpmason commented on Dec 27, 2022

    @Hpmason

    I'm a bit confused, based off the title/description of this issue it sounds like registration doesn't work with dlopen, but the README.md says that registration does happen at the time of dlopen.

    I'm trying to use inventory when loading .dll's, I've tried with both the dlopen and libloading crates and plugins don't seem to be added to the registry. I don't know all the finer details of this crate and dll loading crates, so am I misunderstanding how it works? (Also, I'm on Windows just in case there's a possibility that it's an OS-specific problem)

  7. Enet4 commented on Dec 27, 2022

    @Enet4

    I'm a bit confused, based off the title/description of this issue it sounds like registration doesn't work with dlopen, but the README.md says that registration does happen at the time of dlopen.

    To the best of my knowledge, the registration happens during in the main application bootstrap routine (hence before main), but it does not mean that dlopen is involved. If dlopen is called as part of your application at run-time, that is not registered.

  8. Hpmason commented on Dec 27, 2022

    @Hpmason

    Gotcha, that makes sense. I was trying to figure out how a dynamically loaded dependency could access an existing static, which it can't lol. Thanks for clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions