If I use a lazy loading mechanism, say, with OnceCell etc (implementing a singleton using a mutex guard for example) , unfortunately in my situation I have no place to trigger this lazy loading. So the question is: can I do a dlopen, when the above code in a dynamic module gets loaded, the code also gets executed?
Are you, by any change, at some place using that HashMap you’d like to fill? That place where you use the HashMap might be a candidate for a “place to trigger this lazy loading”.
Or perhaps you’re talking about a case of collecting such map entries from different crates into a single map. There’s been discussions about this scenario somewhere, somewhat recently, I’ll look up where that was.
Edit:This was the thread I remembered. It mentions current approaches using existing crates such as ctor that hook into the linker somehow or something like that IIRC, and also discusses ideas for more proper solutions that Rust could offer in the future for different use-cases.