Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global destructors called for invalid objects on Darwin x86, but nowhere else.



Kevin Harris wrote:
I'll try to provide as many details as I can below, but for a quick
summary, I have two C++ files within a library where if there are any
non-trivial global constructors called within them, they will abort at
cleanup.  This included any global data that is constructed but never
accessed, and does not seem to be dependent on the name of the object
or namespace that it is declared within (I've tried lots of
combinations).
[...]
Several hours of peeking and poking through the debugger (I'll admit
that I don't track down these kinds of failures very often) led me to
two files that are having problems:
src/cimom/common/OW_CIMOMEnvironment.cpp and
src/cimom/common/OW_AuthorizerManager.cpp
The problem is most easy to locate when running the unit tests on
OW_ProviderManager and OW_ProviderMuxLoader (both of which call
functions that play with the CIMOMEnvironment global class).  Removing
any objects with non-trivial global constructors from these two files
in the cimom common library seems to fix things.

C++ makes no guarantees as to the order that dtors are called. My guess is that the CIMOMEnvironment has some global (probably singleton) class and its dtor is being called before whatever is crashing. If this is the case, you'll need to restructure your code in such a way as to avoid this ordering dependency.


I don't believe there is a problem with the code, as this functions
properly with several compilers on many platforms and only breaks on
the x86 version of Darwin.  The PPC version, with a much older xcode
and gcc3.3, seems to work fine, so it could be a gcc4 issue.  The PPC
version also runs correctly with rosetta.

I seem to recall reading of other issues of this nature before. I think that the x86 version calls the dtors in a different order than the ppc version of g++.


If anyone has any suggestions for things to check/fix, or could
actually apply their uber Mac debugging skills, I would really
appreciate it.

One idea is to reference count the global object and not to destroy it until no other object is using it. Something like:


// In GlobalData.h
class GlobalData
{
	static GlobalData *sharedData;
	int count;
	// Other private members here.
	GlobalData() {}
	~GlobalData() {}
public:
	GlobalData *AcquireGlobalData();
	void ReleaseGlobalData();
	// Other public members here.
};

// In GlobalData.cpp
GlobalData *GlobalData::sharedData = NULL;

GlobalData *GlobalData::AcquireGlobalData()
{
	if( sharedData == NULL )
		sharedData = new GlobalData;
	++sharedData->count;
	return sharedData;
}

void GlobalData::ReleaseGlobalData()
{
	assert( sharedData );
	if( sharedData.count )
		return;
	delete sharedData;
	sharedData = NULL;
}

Note, this was written in Thunderbird without testing and this isn't thread safe.

--
Steve Checkoway


_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >Global destructors called for invalid objects on Darwin x86, but nowhere else. (From: "Kevin Harris" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.