2005-09-06 Benjamin Kosnik Jakub Jelinek * testsuite/testsuite_shared.cc: New. * testsuite/ext/mt_allocator/22309_thread.cc: New. * testsuite/lib/libstdc++.exp: Evil hacks for shared objects. Index: testsuite/testsuite_shared.cc =================================================================== RCS file: testsuite/testsuite_shared.cc diff -N testsuite/testsuite_shared.cc *** /dev/null 1 Jan 1970 00:00:00 -0000 --- testsuite/testsuite_shared.cc 7 Sep 2005 03:13:54 -0000 *************** *** 0 **** --- 1,44 ---- + // Copyright (C) 2004, 2005 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 + // terms of the GNU General Public License as published by the + // Free Software Foundation; either version 2, or (at your option) + // any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + // GNU General Public License for more details. + // + // You should have received a copy of the GNU General Public License along + // with this library; see the file COPYING. If not, write to the Free + // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + // USA. + + #include + #include + + // libstdc++/22309 + extern "C" void + foo() + { + typedef char value_t; + + typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, true> policy_t; + typedef __gnu_cxx::__mt_alloc allocator_t; + + typedef std::char_traits traits_t; + typedef std::basic_string string_t; + + #if 1 + string_t s; + s += "west beach, indiana dunes"; + #else + allocator_t a; + allocator_t::pointer p1 = a.allocate(128); + allocator_t::pointer p2 = a.allocate(512); + a.deallocate(p1, 128); + a.deallocate(p2, 512); + #endif + } Index: testsuite/ext/mt_allocator/22309_thread.cc =================================================================== RCS file: testsuite/ext/mt_allocator/22309_thread.cc diff -N testsuite/ext/mt_allocator/22309_thread.cc *** /dev/null 1 Jan 1970 00:00:00 -0000 --- testsuite/ext/mt_allocator/22309_thread.cc 7 Sep 2005 03:13:55 -0000 *************** *** 0 **** --- 1,100 ---- + // { dg-do run { target *-*-linux* } } + // { dg-options "-g -O2 -pthread -ldl" { target *-*-linux* } } + + // Copyright (C) 2004, 2005 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 + // terms of the GNU General Public License as published by the + // Free Software Foundation; either version 2, or (at your option) + // any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + // GNU General Public License for more details. + // + // You should have received a copy of the GNU General Public License along + // with this library; see the file COPYING. If not, write to the Free + // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + // USA. + + #include + #include + #include + #include + + void + check_dlopen(void*& h) + { + dlerror(); + void* tmp = dlopen("./testsuite_shared.so", RTLD_LAZY); + if (!tmp) + { + try + { + // Throws std::logic_error on NULL string. + std::string error(dlerror()); + throw std::runtime_error(error); + } + catch (const std::logic_error&) + { } + } + h = tmp; + } + + void + check_dlsym(void*& h) + { + dlerror(); + + typedef void (*function_type) (void); + function_type fn; + fn = reinterpret_cast(dlsym(h, "foo")); + + try + { + std::string error(dlerror()); + throw std::runtime_error(error); + } + catch (const std::logic_error&) + { } + + fn(); + } + + void + check_dlclose(void*& h) + { + dlerror(); + if (dlclose(h) != 0) + { + try + { + std::string error(dlerror()); + throw std::runtime_error(error); + } + catch (const std::logic_error&) + { } + } + } + + void* + tf(void* arg) + { + void* h; + check_dlopen(h); + check_dlsym(h); + check_dlclose(h); + return 0; + } + + // libstdc++/22309 + int + main (void) + { + pthread_t th; + pthread_create(&th, NULL, tf, NULL); + pthread_join(th, NULL); + return 0; + } Index: testsuite/lib/libstdc++.exp =================================================================== RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/lib/libstdc++.exp,v retrieving revision 1.45 diff -c -p -r1.45 libstdc++.exp *** testsuite/lib/libstdc++.exp 1 Sep 2005 16:58:25 -0000 1.45 --- testsuite/lib/libstdc++.exp 7 Sep 2005 03:13:55 -0000 *************** proc v3-build_support {} { *** 353,359 **** # Build the support objects. set source_files \ ! [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc] foreach f $source_files { set object_file [file rootname $f].o # Compile with "-w" so that warnings issued by the compiler --- 353,359 ---- # Build the support objects. set source_files \ ! [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc ] foreach f $source_files { set object_file [file rootname $f].o # Compile with "-w" so that warnings issued by the compiler *************** proc v3-build_support {} { *** 365,370 **** --- 365,384 ---- } append v3-test_objs "$object_file " } + + # Build the shared support objects. + set source_files \ + [list testsuite_shared.cc] + foreach f $source_files { + set object_file [file rootname $f].so + # Compile with "-w" so that warnings issued by the compiler + # do not prevent compilation. + if { [v3_target_compile $srcdir/$f $object_file "executable" \ + [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]] + != "" } { + error "could not compile $f" + } + } } proc check_v3_target_namedlocale { } { *************** proc check_v3_target_cxa_atexit { } { *** 491,517 **** puts $f "static unsigned int count;" puts $f "struct X" puts $f "{" ! puts $f "X() { count = 1; }" ! puts $f "~X()" ! puts $f "{" ! puts $f " if (count != 3)" ! puts $f " exit(1);" ! puts $f " count = 4;" ! puts $f "}" puts $f "};" puts $f "void f()" puts $f "{" ! puts $f "static X x;" puts $f "}" puts $f "struct Y" puts $f "{" ! puts $f "Y() { f(); count = 2; }" ! puts $f "~Y()" ! puts $f "{" ! puts $f "if (count != 2)" ! puts $f " exit(1);" ! puts $f "count = 3;" ! puts $f "}" puts $f "};" puts $f "Y y;" puts $f "int main()" --- 505,531 ---- puts $f "static unsigned int count;" puts $f "struct X" puts $f "{" ! puts $f " X() { count = 1; }" ! puts $f " ~X()" ! puts $f " {" ! puts $f " if (count != 3)" ! puts $f " exit(1);" ! puts $f " count = 4;" ! puts $f " }" puts $f "};" puts $f "void f()" puts $f "{" ! puts $f " static X x;" puts $f "}" puts $f "struct Y" puts $f "{" ! puts $f " Y() { f(); count = 2; }" ! puts $f " ~Y()" ! puts $f " {" ! puts $f " if (count != 2)" ! puts $f " exit(1);" ! puts $f " count = 3;" ! puts $f " }" puts $f "};" puts $f "Y y;" puts $f "int main()"