Copy link
@dnadlinger

dnadlinger Dec 2, 2013

Author Member

I should be able, yes, but I didn't find a way to get this to work on the LLVM IR level. Module-level inline assembly would be an option in theory, but then, we can't do LTO anymore, as the LLVM linker wouldn't know how to coalesce them, and I couldn't find a way to make the MC asm parsers just ignore the subsequent instances. The proper solution would be to use linkonce_odr globals with the section attribute set to .ctors.<something>, but unfortunately, MC doesn't currently handle this case properly (specifying a custom section causes the weak linkage part to be disregarded).

And once the constructor is called multiple times, just using dsoSlot to distinguish between initialization/destruction doesn't work anymore.

Thinking of it, I should add the above as a source comment, or at least write that blog post on the topic I have been meaning do to for ages. -.-