This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Add --enable-__cxa_atexit


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]