Date: Wed, 27 Jan 1999 17:08:00 -0600 From: "Brian C. Grayson" <bgrayson@marvin.ece.utexas.edu> To: freebsd-hackers@FreeBSD.ORG Subject: a.out/ELF differences: C++ static constructor ordering Message-ID: <19990127170800.A27484@marvin.ece.utexas.edu>
next in thread | raw e-mail | index | archive | help
I just noticed (after two days of gdb and instrumenting the STL header files -- fun!) that my current problem stems from the fact that under ELF, static constructors are invoked in a different order than under a.out. 1. Under both formats, objects within a file are created in program-order. Good. 2. Under ELF, objects in different files are constructed in the order that the files appear on the link command line (example below). Under a.out, objects in different files are constructed in _reverse_ order from the file order on the command line (this is the behavior I've seen under *BSD/a.out, AIX XCOFF, Solaris ELF, and probably others). Is this change intentional? Unfortunately, this behavior breaks a major project of mine (50Kloc and counting). I wouldn't be surprised if it breaks numerous other complex C++ programs, also. This is with gcc 2.7.2.1 on both a.out and ELF. As an example, create the files foo.h, a.cc, b.cc, and main.cc as follows: foo.h: class Foo { public: Foo(char* p) { printf("%s\n", p); } }; a.cc: #include "foo.h" Foo a("a"); Foo a2("a2"); b.cc #include "foo.h" Foo b("b"); main.cc: main () {} Now, build some executables. The first two are on an ELF machine, the second two on a.out. c++ -o ab.elf a.cc b.cc main.cc c++ -o ba.elf b.cc a.cc main.cc c++ -o ab.aout a.cc b.cc main.cc c++ -o ba.aout b.cc a.cc main.cc ab.elf and ab.aout behave differently: % ab.elf a a2 b % ab.aout b a a2 ba.elf and ba.aout also differ: % ba.elf b a a2 % ba.aout a a2 b Looking at the csu source code, __ctors/do_ctors both process the lists in the same order, so it appears that the linker is appending in one case, and prepending in the other???? Brian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990127170800.A27484>