On Sun, Nov 09, 2014 at 04:16:13PM +0900, Masao Uebayashi wrote: > +#if 0 > #ifndef PIPE_SOCKETPAIR > /* Initialize pipes. */ > pipe_init(); > @@ -604,6 +605,15 @@ main(void) > /* Initialize ptrace. */ > ptrace_init(); > #endif /* PTRACE */ > +#else > + typedef void kctors_func(void); > + __link_set_decl(kctors_9, kctors_func); > + > + kctors_func * const * func; > + __link_set_foreach(func, kctors_9) { > + (*(*func))(); > + } > +#endif
Please don't do that. Nothing good can come of it - you are asking for a thousand weird problems where undisclosed ordering dependencies silently manifest as strange bugs. Furthermore, the compiler can and probably will assume that constructor functions get called before all non-constructor code, and owing to unavoidable issues in early initialization this will not be the case in some contexts. (I first hit this problem back in about 1995ish when some more gung-ho colleagues were trying to use C++ global constructors in a C++ kernel, and we eventually had to declare a moratorium on all global constructors.) init_main.c could use some tidying, but there's nothing fundamentally wrong with it that will be improved by adding a lot of implicit magic that doesn't do what the average passerby expects. -- David A. Holland dholl...@netbsd.org