Memory allocators / STL

Philip Martin philip_martin@ntlworld.com
Tue Oct 30 05:00:00 GMT 2001


Loren James Rittle <rittle@latour.rsch.comm.mot.com> writes:

> In article < Pine.SOL.3.91.1011030010707.8865A-100000@taarna.cygnus.com >,
> Benjamin Kosnik <bkoz@redhat.com> writes:
> 
> > No problems on 2 or 4 way with pthreads.
> 
> >> I am about the try the code on Solaris and FreeBSD machines I have gcc 3.X
> >> built on.
> 
> Using gcc-mainline on 1-way freebsd (don't have 3.0.X handy at the
> moment), test case runs fine.  Built using only -pthread instead of
> the instructions in file.
> 
> Using gcc-3.0 on 1-way Solaris 2.7, test case runs fine.  Built using
> only -pthreads instead of the instructions in file.
> 
> I have some 2-way Solaris 2.6 machine but no gcc 3.X built for it at
> the moment.

The code fails on my 2-way x86 running linux 2.4. This is machine is
running mostly debian-stable.

$ uname -a
Linux debian2 2.4.10-ac12 #1 SMP Thu Oct 11 19:40:03 BST 2001 i686 unknown

$ dpkg -l libc6 ldso | grep ii
ii  libc6          2.1.3-18       GNU C Library: Shared libraries and Timezone
ii  ldso           1.9.11-9       The Linux dynamic linker, library and utilit

$ g++ -v
Reading specs from //usr/local/gcc-3.0-cvs/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.0.3/specs
Configured with: /home/pm/sw/gcc-3.0-cvs/gcc/configure --prefix=/usr/local/gcc-3.0-cvs --enable-languages=c++ : (reconfigured) /home/pm/sw/gcc-3.0-cvs/gcc/configure --prefix=/usr/local/gcc-3.0-cvs --enable-languages=c++ : (reconfigured) /home/pm/sw/gcc-3.0-cvs/gcc/configure --prefix=/usr/local/gcc-3.0-cvs --enable-languages=c++ : (reconfigured) /home/pm/sw/gcc-3.0-cvs/gcc/configure --prefix=/usr/local/gcc-3.0-cvs --enable-languages=c++ : (reconfigured)  : (reconfigured) /home/pm/sw/gcc-3.0-cvs/gcc/configure --prefix=/usr/local/gcc-3.0-cvs --enable-languages=c++ --enable-threads
Thread model: posix
gcc version 3.0.3 20011027 (prerelease)


According to gdb it doesn't always crash in the same place.  Here's
one crash:

$ g++ -g -pthread z.cc
$ gdb a.out 
GNU gdb 2001-07-25-cvs (MI_OUT)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) r
Starting program: /home/pm/a.out 
[New Thread 1024 (runnable)]
[New Thread 2049 (runnable)]
[New Thread 1026 (runnable)]
[New Thread 2051 (runnable)]
[New Thread 3076 (runnable)]
[New Thread 4101 (runnable)]
[New Thread 5126 (runnable)]
[New Thread 6151 (runnable)]
[New Thread 7176 (runnable)]
[New Thread 8201 (runnable)]
[New Thread 9226 (runnable)]
[New Thread 10251 (runnable)]
[New Thread 11276 (runnable)]
[New Thread 12301 (runnable)]
[New Thread 13326 (runnable)]
[New Thread 14351 (runnable)]
[New Thread 15376 (runnable)]
[New Thread 16401 (runnable)]
[New Thread 17426 (runnable)]
[New Thread 18451 (runnable)]
[New Thread 19476 (runnable)]
[New Thread 20501 (runnable)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 17426 (runnable)]
0x0804bdb5 in std::__default_alloc_template<true, 0>::allocate(unsigned) (
    __n=19) at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/stl_alloc.h:344
344             *__my_free_list = __result -> _M_free_list_link;
(gdb) p __result
$1 = (_Obj *) 0x6
(gdb) bt
#0  0x0804bdb5 in std::__default_alloc_template<true, 0>::allocate(unsigned) (
    __n=19) at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/stl_alloc.h:344
#1  0x0804c3d7 in std::allocator<char>::allocate(unsigned, void const*) (
    this=0xbd7ffbdc, __n=19)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/stl_alloc.h:582
#2  0x0804bc6e in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (__capacity=6, __alloc=@0xbd7ffbdc)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.tcc:376
#3  0x0804bf01 in std::string::_M_mutate(unsigned, unsigned, unsigned) (
    this=0x8051de8, __pos=0, __len1=0, __len2=6)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.tcc:282
#4  0x0804b8af in std::string& std::string::_M_replace<char const*>(std::__normal_iterator<char*, std::string>, std::__normal_iterator<char*, std::string>, char const*, char const*, std::forward_iterator_tag) (this=0x8051de8, __i1=
      {<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x804faa4 ""}, __i2=
      {<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x804faa4 ""}, __k1=0x804d3c0 "foobar", 
    __k2=0x804d3c6 "")
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.tcc:456
#5  0x0804b043 in std::string& std::string::replace<char const*>(std::__normal_iterator<char*, std::string>, std::__normal_iterator<char*, std::string>, char const*, char const*) (this=0x8051de8, __i1=
      {<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x804faa4 ""}, __i2=
      {<iterator<std::random_access_iterator_tag,char,int,char*,char&>> = {<No data fields>}, _M_current = 0x804faa4 ""}, __k1=0x804d3c0 "foobar", 
    __k2=0x804d3c6 "")
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:645
#6  0x0804aa4c in std::string& std::string::assign<char const*>(char const*, char const*) (this=0x8051de8, __first=0x804d3c0 "foobar", __last=0x804d3c6 "")
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:511
#7  0x0804a2a6 in std::string::assign(char const*) (this=0x8051de8, 
    __s=0x804d3c0 "foobar")
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:502
#8  0x08049ec4 in std::string::operator=(char const*) (this=0x8051de8, 
    __s=0x804d3c0 "foobar")
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:350
#9  0x08049bb7 in f(void*) (arg=0x10) at z.cc:35
#10 0x400b9c9f in pthread_start_thread () from /lib/libpthread.so.0
#11 0x400b9ce2 in pthread_start_thread_event () from /lib/libpthread.so.0
(gdb) 

Here's another:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 2051 (runnable)]
__exchange_and_add(int volatile*, int) (__mem=0xfffffffc, __val=-1)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/i686-pc-linux-gnu/bits/atomicity.h:40
40        __asm__ __volatile__ ("lock; xaddl %0,%2"
(gdb) bt
#0  __exchange_and_add(int volatile*, int) (__mem=0xfffffffc, __val=-1)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/i686-pc-linux-gnu/bits/atomicity.h:40
#1  0x0804a537 in std::string::_Rep::_M_dispose(std::allocator<char> const&) (
    this=0xfffffff4, __a=@0xbf5ffbdc)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:179
#2  0x0804a0fe in std::string::~string() (__in_chrg=0x8051e58)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/basic_string.h:344
#3  0x0804cf05 in std::pair<int const, std::string>::~pair() (
    __in_chrg=0x8051e54)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/ext/hash_map:173
#4  0x0804d371 in void std::_Destroy<std::pair<int const, std::string> >(std::pair<int const, std::string>*) (__pointer=0x8051e54)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/stl_construct.h:88
#5  0x0804d331 in void std::destroy<std::pair<int const, std::string> >(std::pair<int const, std::string>*) (__pointer=0x8051e54)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/bits/stl_construct.h:138
#6  0x0804d206 in std::hashtable<std::pair<int const, std::string>, int, std::hash<int>, std::_Select1st<std::pair<int const, std::string> >, std::equal_to<int>, std::allocator<std::string> >::_M_delete_node(std::_Hashtable_node<std::pair<int const, std::string> >*) (this=0xbf5ffd0c, __n=0x8051e50)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/ext/stl_hashtable.h:528
#7  0x0804d0fe in std::hashtable<std::pair<int const, std::string>, int, std::hash<int>, std::_Select1st<std::pair<int const, std::string> >, std::equal_to<int>, std::allocator<std::string> >::clear() (this=0xbf5ffd0c)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/ext/stl_hashtable.h:924
#8  0x0804cfa3 in std::hashtable<std::pair<int const, std::string>, int, std::hash<int>, std::_Select1st<std::pair<int const, std::string> >, std::equal_to<int>, std::allocator<std::string> >::~hashtable() (__in_chrg=0xbf5ffd0c)
    at /usr/local/gcc-3.0-cvs/include/g++-v3/ext/stl_hashtable.h:314
#9  0x0804cf41 in std::hash_map<int, std::string, std::hash<int>, std::equal_to<int>, std::allocator<std::string> >::~hash_map() (__in_chrg=0xbf5ffd0c)
    at z.cc:34
#10 0x08049bd7 in f(void*) (arg=0x1) at z.cc:36
#11 0x400b9c9f in pthread_start_thread () from /lib/libpthread.so.0
#12 0x400b9ce2 in pthread_start_thread_event () from /lib/libpthread.so.0
(gdb)


Philip Martin



More information about the Libstdc++ mailing list