[K42-discussion] Cause of cxa_atexit/dso_handle reference
Patrick G. Bridges
bridges at cs.unm.edu
Wed Aug 16 07:14:02 EST 2006
As Donour has mentioned before, he's been going through adding
virtual destructors to objects that need them to avoid compiler
warnings from gcc 4.0 that K42 currently treats as errors because of
the -Werror compiler directive we pass to K42. When we add these
destructors to certain classes, however, the kernel link fails with
references to ._cxa_atexit and __dso_handle. The compiler is using
these functions to make sure that the (noop) virtual destructor is
called on a static global C++ object.
TO address this problem, we can either
1. Add implementations of ._cxa_atexit and __dso_handle (the page I
just linked has simple, though limited, implementations)
2. Not use global objects
3. Not implement destructors for any object in the kernel that is a
global static and filter out
-Werror or use some pragma to avoid stopping the build on these
objects.
To start looking at this, I tracked down the biggest case we're run
into with ._cxa_atexit being generated.
* DeletedObject in BaseObj.C currently has virtual functions, but no
virtual destructor, so a virtual destructor is needed to suppress a
gcc 4.0 compiler warning.
* BaseObj::ClassInit() contains a global static DeletedObject:
Obj* theDeletedObj;
/*static*/ void
BaseObj::ClassInit(VPNum vp)
{
static DeletedObject deletedObject;
if (vp == 0) {
theDeletedObj = (Obj*)&deletedObject;
}
}
* theDeletedObj is exported to the rest of the kernel in Obj.H and,
as far aas I can tell, used only in fslib currently as follows:
bridges at milhouse:~/k42/kitchsrc$ find . -name \*.C -print | xargs
grep theDeletedObj
./lib/libc/cobj/BaseObj.C:Obj* theDeletedObj;
./lib/libc/cobj/BaseObj.C: theDeletedObj = (Obj*)&deletedObject;
./lib/libc/fslib/DirLinuxFSVolatile.C: fileInfo = (FSFile*)
theDeletedObj;
./lib/libc/fslib/virtfs/ServerFileVirtFS.C: fileInfo =
(FileInfoVirtFSDir*)theDeletedObj;
./lib/libc/fslib/virtfs/ServerFileVirtFS.C: fileInfo =
(FileInfoVirtFSDir*)theDeletedObj;
***
So, should we just break down and put together simple implemetations
of cxa_atexit and dso_handle, or should we further limit the kinds of
things we do in C++ to avoid these problems (i.e., either forbid
destructors in certain classes or forbid global objects of certain
types)?
More information about the K42-discussion
mailing list