This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/33704] AIX runs c++ constructors in incorrect order
- From: "ajd at gentrack dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Oct 2007 04:04:02 -0000
- Subject: [Bug target/33704] AIX runs c++ constructors in incorrect order
- References: <bug-33704-8038@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #17 from ajd at gentrack dot com 2007-10-10 04:04 -------
(In reply to comment #16)
> lib1.a depends on lib2.a
> main depends on lib1.a, but does not explicitly link with lib2.a
main initializes what it is explicitly linked against.
lib1 initializes lib2 before it initializes itself.
--
See attached test_init_order.cpp:
$ # -- create lib2
$ g++ -shared -o lib2.a -D LIBNAME=LIB2 test_init_order.cpp
$ # -- create lib1 depends on lib2
$ g++ -shared -L. -l2 -o lib1.a -D LIBNAME=LIB1 -DCALLEE=LIB2
test_init_order.cpp
$ # -- hide lib2 from main
$ mv lib2.a /tmp/lib2.hide
$ # -- link main against lib1
$ g++ -L. -l1 -o m -D LIBNAME=main -DCALLEE=LIB1 test_init_order.cpp
$ # -- unhide lib2
$ mv /tmp/lib2.hide lib2.a
$ ./m
LIB2_init
LIB1_init
main_init
main()
LIB1()
LIB2()
main_fini
LIB1_fini
LIB2_fini
$ # -- replace lib1 with a library that doesn't depend on lib2
$ # -- leave main alone
$ g++ -shared -o lib1.a -D LIBNAME=LIB1 test_init_order.cpp
$ /usr/local/bin/sudo slibclean
$ ./m
LIB1_init
main_init
main()
LIB1()
main_fini
LIB1_fini
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33704