Date: Wed, 27 Jan 1999 21:57:51 -0800 (PST) From: John Polstra <jdp@polstra.com> To: bgrayson@marvin.ece.utexas.edu Cc: hackers@FreeBSD.ORG Subject: Re: a.out/ELF differences: C++ static constructor ordering Message-ID: <199901280557.VAA07235@vashon.polstra.com> In-Reply-To: <19990127170800.A27484@marvin.ece.utexas.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <19990127170800.A27484@marvin.ece.utexas.edu>, Brian C. Grayson <bgrayson@marvin.ece.utexas.edu> wrote: > 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. Yes, this is required by the C++ standard. > 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. The C++ standard specifically states that a conforming program is not allowed to rely on the ordering of static constructors in different object files. I didn't break your program intentionally; however, I also didn't violate the standard. If your program conformed to the C++ standard, it would work under both FreeBSD/aout and FreeBSD/ELF. Executing the constructors in reverse order of linking is probably "better," because it tends to construct dependencies before they're used. So probably I'll fix the dynamic linker to do that. But it isn't required by the standard. If you want your programs to be portable, you should take care to eliminate these kinds of dependencies. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Nobody ever went broke underestimating the taste of the American public." -- H. L. Mencken 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?199901280557.VAA07235>