Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dtolnay opened this issue Dec 24, 2018 · 8 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Dec 24, 2018

No description provided.

@dtolnay
Copy link
Owner Author

dtolnay commented Dec 24, 2018

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

@mmastrac
Copy link

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.

@dtolnay
Copy link
Owner Author

dtolnay commented Dec 29, 2018

Thanks for the warning! I filed mmastrac/rust-ctor#3 to follow up.

@mmastrac
Copy link

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.

@mathstuf
Copy link
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.

@Hpmason
Copy link

Hpmason commented Dec 27, 2022

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)

@Enet4
Copy link

Enet4 commented Dec 27, 2022

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.

@Hpmason
Copy link

Hpmason commented Dec 27, 2022

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants