http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
--- Comment #8 from H.J. Lu <hjl.tools at gmail dot com> 2010-12-11 14:28:35 UTC --- (In reply to comment #7) > Hi, > thanks for testcase. What I was concerned about is the static linking case. > When you have static library with constructors and main program with > constructors, my understanding was that the reverse execution order of .ctor > section was designed in a way so library even in this case is initialized > first. > > Now because ctors are handled before init_array, this no longer happen. I.e. > when I turn foo1.c into library (and add function used from foo.o) and compile > as > gcc -o foo4 foo2.o foo.o -l foo -L. > I still get > init_array > main > fini_array > dtor > i.e. the library is initialized later. > > I am not sure that this is actual requirement, or QOI issue or just something > I > was told to explain why ctor section is executed backwards while dtors forward > (it would make more sense performance wise to reverse this). But in order to > approve the patch I need to unerstand this better... > For static linking, there is no difference between gcc -o foo foo2.o foo.o vs gcc -o foo foo2.o -lfoo -L. We guarantee the relative order of constructors vs. destructors. The test in comment 5 shows it works fine with mixed .init_array and .ctors.