This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Add --enable-__cxa_atexit
- From: "H . J . Lu" <hjl at lucon dot org>
- To: "Martin v. Loewis" <martin at v dot loewis dot de>
- Cc: Jack Howarth <howarth at bromo dot msbb dot uc dot edu>, gcc-patches at gcc dot gnu dot org
- Date: Sun, 2 Jun 2002 21:21:40 -0700
- Subject: PATCH: Add --enable-__cxa_atexit
- References: <200206020310.XAA81729@bromo.msbb.uc.edu> <m3lm9y9kd7.fsf@mira.informatik.hu-berlin.de> <20020602093511.A6263@lucon.org> <m3ptz98id1.fsf@mira.informatik.hu-berlin.de> <20020602145116.A10713@lucon.org> <m3u1ol72p7.fsf@mira.informatik.hu-berlin.de>
On Mon, Jun 03, 2002 at 12:09:24AM +0200, Martin v. Loewis wrote:
> "H . J . Lu" <hjl@lucon.org> writes:
>
> > Please provide a testcase to show that. I don't believe -fuse-cxa-atexit
> > should make a difference on glibc.
>
> [Not copying bug 148651, since that already has that testcase]
>
> Consider the example below. It should print
>
> Created first
> Called second
> Created third
> Destroyed first
> Destroyed second
> Destroyed third
>
> (and does so with -fuse-cxa-atexit)
>
> However, with g++ 3.1, on Linux glibc 2.2, with -fno-use-cxa-atexit,
> it prints
>
> Created first
> Called second
> Created third
> Destroyed second
> Destroyed first
> Destroyed third
>
> Notice that the atexit function is not called in-between the dtors,
> as it should.
>
> Regards,
> Martin
>
> #include <stdio.h>
> #include <stdlib.h>
>
> struct Order{
> char *fini;
> Order(char*, char*, bool);
> ~Order();
> };
>
> void c_fini(){
> printf("Destroyed second\n");
> }
>
> void c_init(){
> printf("Called second\n");
> atexit(c_fini);
> }
>
> Order::Order(char* init, char* fini, bool atexit):fini(fini)
> {
> if(atexit)
> c_init();
> printf("Created %s\n", init);
> }
>
> Order::~Order()
> {
> printf("Destroyed %s\n", fini);
> }
>
> Order o1("first", "third", false);
> Order o2("third", "first", true);
>
> int main(){}
It seems that -fuse-cxa-atexit does make a difference for Linux. I am
resubmitting my patch. I think people configuring gcc 3 on Linux should
add --enable-__cxa_atexit.
H.J.