From owner-freebsd-hackers Wed Jan 27 21:57:55 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id VAA18274 for freebsd-hackers-outgoing; Wed, 27 Jan 1999 21:57:55 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id VAA18263 for ; Wed, 27 Jan 1999 21:57:53 -0800 (PST) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.1/8.9.1) with ESMTP id VAA03573; Wed, 27 Jan 1999 21:57:52 -0800 (PST) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.1/8.9.1) id VAA07235; Wed, 27 Jan 1999 21:57:51 -0800 (PST) (envelope-from jdp@polstra.com) Date: Wed, 27 Jan 1999 21:57:51 -0800 (PST) Message-Id: <199901280557.VAA07235@vashon.polstra.com> To: bgrayson@marvin.ece.utexas.edu Subject: Re: a.out/ELF differences: C++ static constructor ordering Newsgroups: polstra.freebsd.hackers In-Reply-To: <19990127170800.A27484@marvin.ece.utexas.edu> Organization: Polstra & Co., Seattle, WA Cc: hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <19990127170800.A27484@marvin.ece.utexas.edu>, Brian C. Grayson 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