From owner-freebsd-hackers Wed Jan 27 15:08:05 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA27057 for freebsd-hackers-outgoing; Wed, 27 Jan 1999 15:08:05 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from marvin.ece.utexas.edu (marvin.ece.utexas.edu [128.83.52.151]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA27048 for ; Wed, 27 Jan 1999 15:08:02 -0800 (PST) (envelope-from bgrayson@marvin.ece.utexas.edu) Received: (from bgrayson@localhost) by marvin.ece.utexas.edu (8.8.8/8.6.9) id RAA05800 for freebsd-hackers@freebsd.org; Wed, 27 Jan 1999 17:08:01 -0600 (CST) Message-ID: <19990127170800.A27484@marvin.ece.utexas.edu> Date: Wed, 27 Jan 1999 17:08:00 -0600 From: "Brian C. Grayson" To: freebsd-hackers@FreeBSD.ORG Subject: a.out/ELF differences: C++ static constructor ordering Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.1i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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