Skip to content
New issue

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

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

Already on GitHub? # to your account

#[ctor] from a (static) library not applied if library not imported with use #306

Open
peter-lyons-kehl opened this issue Aug 17, 2024 · 0 comments

Comments

@peter-lyons-kehl
Copy link

Thanks Matt for rust-ctor.

Situation:

  • a (static) library crate (let's call it static_library here) uses #[ctor], and
  • that (static) library doesn't have any public items. Instead, its only purpose is to run its functionality at start (with #[ctor]), and
  • a consumer binary imports/declares that (static) library in its Cargo.toml's [dependencies], but it doesn't have use static_library; nor #[allow(unused)] use static_library;, then
  • the function(s) in static_library marked with #[ctor] are not run (at least not on x64 Linux).

If the binary has use static_library; or #[allow(unused)] use static_library; then the #[ctor] function(s) from static_library are run as expected.

Such a use is probably rare, so this may not need any action/investigation, and a note in documentation may be enough.

FYI: I've tried with #[constructor(65535)] of static_init crate (current 1.0.3) instead of rust-ctor, and it has the same problem/limitation. Without use (of the static library) functions marked with #[constructor(...)] are not run.

Even when I use static_init's #[dynamic(drop)] together with #[used], expressions that generate initial values of such statics is not run (again, if I don't use the static library).

(I may migrate always-abort to depend on static_init instead of ctor, but there are no emotions here. Thank you for ctor.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant