This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/46770] Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]