there may still be some clumsiness here but I think the approach
most recently suggested by peter is working

I'd expect the registration code to crash if there's any significant
multithreaded execution of global constructors and this hasn't happened so far