On 15 February 2006 15:27, Perry Smith wrote: > I am assuming I am doing something wrong but I am hoping someone can > give me a clue as to where to look. > > I'm trying to write an AIX device driver using g++. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Clue: Look here! ;-)
> The drivers do > not have a __start or main, so I have to call the global constructors > and destructors myself. I've written code attempting to make sure > they get constructed before any globals are accessed and no global > access happens after they are destroyed. But my trace shows that the > object that is suppose to do that is getting its destructor called > recursively. Ah, I see you've already worked out just /why/ c++ is a tricky choice for system-level code. > The essence is that I have an automatic variable. The constructor > calls the global constructors; the destructor calls the global > destructors. Line 1 and 10 you see this variable's destructor getting > called. The second call returns at line 13. The first call returns > at line 23. The second call does nothing because I have already > flipped the bit that says that the global destructors need to be > called. So the second call comes and goes without much fuss. The > only thing unusual about the config_lock class is it has two static > members. I could move those and just have global C statics if > necessary. The static members are an int and an lock_t (C types). > > I can write code to cope with this but I assume that this is not > suppose to happen. My fear is that I am trashing something and just > getting lucky that I am not crashing. I first want to make sure (from > comments from this mailing list) that it is not suppose to happen. What, global destructors that infinitely recurse until the entire stack is filled? I suppose that's one way to get a process terminated, but I'm sure it's not the right one. No, this probably should not be happening. Nor should the presence of a couple of static class members necessitate calling the d-tor at global d-tor time, although if either of them were non-PODs they might have had d-tors of their own. > The second thing I'm hoping for is some suggestions on what may be > happening. The first call appears to be destroying objects, then > calls itself again, then continues destroying objects, then returns. Most likely you've written a bug in your code somewhere. > Why is it calling itself again? Any ideas? Well, I would like to suggest that you have inadvertently instantiated a static instance of your class, and so there is a call to the class d-tor in amongst the list of d-tors in the .dtors section. > > 1 **** config_lock_dtor > 2 get_lockl_ctor > 3 get_lockl_ctor ret 0 from line 108 > 4 global_dtors > 5 global_dtors 004E 0000 0000 0000 > 6 dtor > 7 dtor ret 0 from line 24 > 8 dvr_simple_lock_dtor > 9 dvr_simple_lock_dtor ret 0 from line 31 > 10 **** config_lock_dtor > 11 get_lockl_ctor > 12 get_lockl_ctor ret 0 from line 108 > 13 **** config_lock_dtor ret 0 from line 75 > 14 get_lockl_dtor > 15 get_lockl_dtor ret 0 from line 116 > 16 free ptr 70BDDFC0 > 17 free ret 0 from line 32 > 18 free ptr 70BCF480 > 19 free ret 0 from line 32 > 20 free ptr 70BCF820 > 21 free ret 0 from line 32 > 22 global_dtors ret 0 from line 82 > 23 **** config_lock_dtor ret 0 from line 75 > > Thank you for you help. > Perry Smith The most useful information would be to print out the value of 'this' in config_lock_dtor and see if it's the same or a different one each time. If it's different, you just need to find the static instantiation and delete it from your program. If it's the same, you must be doing something wrong in the way that your object's d-tor goes about calling the global d-tors. BTW, this is probably a gcc-help@ post really. It's only marginally related to the internals of gcc. cheers, DaveK -- Can't think of a witty .sigline today....