PATCH: Reguire __cxa_atexit for ext/{new, throw}_allocator/deallocate_global.cc
Rainer Orth
ro@CeBiTec.Uni-Bielefeld.DE
Wed Feb 24 14:36:00 GMT 2010
While investigating the three remaining libstdc++ testsuite failures on
Solaris 11/x86, two of them proved to have a common cause:
FAIL: ext/new_allocator/deallocate_global.cc execution test
FAIL: ext/throw_allocator/deallocate_global.cc execution test
The first test failed with
terminate called after throwing an instance of '__gnu_test::counter_error'
what(): std::exception
operator new is called
It turned out that __gnu_test::~counter() in
testsuite/util/replacement_memory_operators.h threw counter_error() upon
exit from the testcase since _M_count was 1 at that point. If I replace
the throw() with
std::printf("~counter is called, _M_count = %d\n", _M_count);
I get the following output from the testcase instead:
operator new is called
~counter is called, _M_count = 1
operator delete is called
All memory released
I'm pretty sure this happens because the destructors aren't run in the
sequence expected, since Solaris 2 lacks __cxa_atexit().
To avoid this problem, the correct solution seems to be to require
__cxa_atexit, which this patch does. As expected, both tests become
untested now.
I haven't yet read up on the semantics of __cxa_atexit, but looking
through the OpenSolaris sources
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/common/i386/crt1.s#101
I found that atexit() has a hook for a _get_exit_frame_monitor()
function with a reference to the C++ runtime. It's most likely possible
to use this to provide a __cxa_atexit() replacement in libgcc, and
perhaps get Sun to implement (or accept an implementation) of
__cxa_atexit() into their libc to fix the problem once and for all.
Ok for mainline?
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2010-02-19 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* testsuite/ext/new_allocator/deallocate_global.cc: Require
__cxa_atexit.
* testsuite/ext/throw_allocator/deallocate_global.cc: Likewise.
diff -r d756770ee041 -r 72b534606d20 libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc
--- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc Thu Feb 18 02:37:59 2010 +0100
+++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc Fri Feb 19 08:46:46 2010 +0100
@@ -1,5 +1,7 @@
+// { dg-require-cxa-atexit "" }
+
//
-// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
diff -r d756770ee041 -r 72b534606d20 libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc
--- a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc Thu Feb 18 02:37:59 2010 +0100
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc Fri Feb 19 08:46:46 2010 +0100
@@ -1,5 +1,7 @@
+// { dg-require-cxa-atexit "" }
+
//
-// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
More information about the Libstdc++
mailing list