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

Rewrite to use data segments instead of ctor? #13

Closed
kabergstrom opened this issue Aug 17, 2019 · 3 comments
Closed

Rewrite to use data segments instead of ctor? #13

kabergstrom opened this issue Aug 17, 2019 · 3 comments

Comments

@kabergstrom
Copy link

kabergstrom commented Aug 17, 2019

The inventory crate is super cool and it has become a critical part of some of the projects I am involved in. Thanks!

However, there are a number of issues due to inventory relying on a dynamic loader to invoke functions in the .ctor segment. Since inventory's interface is primarily for storing data that is later to be iterated over, it seems like it should be possible to implement inventory using custom data segments instead. Data segments are more portable and should be able to even work on platforms like WASM since it supports fetching custom sections. I guess the main difference when implementing inventory using data segments is that it can only support const expressions.

I have not tried to make it work in WASM yet, but I did make a proof-of-concept for Windows/OSX/Linux that seems to work. Check it out! It uses platform specifics to get pointers to the start and end of a custom data segment where the submitted data is stored. The linker concatenates all data in a custom data segment during the linking phase so that data from all modules can be iterated over. The idea is to have a custom data segment for each type by mangling the type name - the proof of concept only uses a constant name. Presumably this is something that can be done by a proc macro.

Does this seem like something that is worth doing or are there known issues with this approach that I should be aware of?

@dtolnay
Copy link
Owner

dtolnay commented Aug 17, 2019

Hi @kabergstrom, I have an implementation of your approach already in https://github.com/dtolnay/linkme. If I could interest you in contributing Windows support over there, it may be a better fit for your use case than inventory.

@kabergstrom
Copy link
Author

Thanks for the quick reply :) I'll have a look!

@kabergstrom
Copy link
Author

Linkme is probably what I wanted, closing.

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

2 participants