Bug 29517 - Exception handling not thread-safe on AIX5.x and HP-UX
Summary: Exception handling not thread-safe on AIX5.x and HP-UX
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-19 16:43 UTC by Ulrich Beingesser
Modified: 2021-01-11 17:50 UTC (History)
6 users (show)

See Also:
Host:
Target: powerpc-ibm-aix5.3.0.0
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test program that demonstrates the bug. (830 bytes, text/plain)
2006-10-19 16:45 UTC, Ulrich Beingesser
Details
gdb backtrace info (796 bytes, text/plain)
2006-10-20 07:53 UTC, Ulrich Beingesser
Details
backtrace info case 2 (455 bytes, text/plain)
2006-10-20 08:08 UTC, Ulrich Beingesser
Details
backtrace info case 3 (457 bytes, text/plain)
2006-10-20 08:10 UTC, Ulrich Beingesser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Beingesser 2006-10-19 16:43:50 UTC
The attached code crashes under AIX5.2 and AIX5.3 when compiled with g++ 4.1.1.
The effect also occurs using g++ 4.0.3.

It seems that throwing exceptions is not completely thread safe.

The crash symptom is one of:
1. segmentation fault (core dumped)
2. illegal instruction (core dumped)
3. terminate called after throwing an instance of 'int' (core dumped). 

The effect cannot clearly be reproduced.
However when running the test program (crashme.cpp) with rather big parameter values
one can proove that the program crashes very often after some time if the params are choosen big enough.

The program was build with following command:
g++ crashme.cpp -o crashme -lpthread

Usage: crashme <number of threads> <number of runs>

For example 'crashme 50 1000' was enough to crash it on our box almost every time.
Comment 1 Ulrich Beingesser 2006-10-19 16:45:11 UTC
Created attachment 12462 [details]
Test program that demonstrates the bug.
Comment 2 Andrew Pinski 2006-10-19 16:51:21 UTC
-lpthread
I think that is your problem, you should be using -pthread instead.

Can you try using -pthread instead of -lpthread?
Comment 3 Ulrich Beingesser 2006-10-19 17:02:00 UTC
(In reply to comment #2)
> -lpthread
> I think that is your problem, you should be using -pthread instead.
> Can you try using -pthread instead of -lpthread?

Using -pthread instead of -lpthread shows the same results.

gcc was configured using (taken from g++ -v):
Using built-in specs.
Target: powerpc-ibm-aix5.3.0.0
Configured with: /tools/gnu/gcc/gcc-4.1.1/configure --prefix=/newtools/OS_AIX53/gcc4.1.1 --enable-threads=posix --enable-languages=c,c++
Thread model: aix
gcc version 4.1.1 
Comment 4 Ulrich Beingesser 2006-10-20 07:53:33 UTC
Created attachment 12466 [details]
gdb backtrace info

Shows complete sequence how program is build, run, crashes and gdb backtrace on AIX5.2. On AIX5.3 the same conditions occur, but there we have no gdb available yet.
Comment 5 Ulrich Beingesser 2006-10-20 08:08:04 UTC
Created attachment 12467 [details]
backtrace info case 2

Shows backtrace info for scenario when program crashes due to signal 11
Comment 6 Ulrich Beingesser 2006-10-20 08:10:01 UTC
Created attachment 12468 [details]
backtrace info case 3

Shows backtrace info for scenario when program crashes due to signal 4
Comment 7 Ulrich Beingesser 2006-10-26 18:38:58 UTC
(In reply to comment #0)
> The attached code crashes under AIX5.2 and AIX5.3 when compiled with g++ 4.1.1.
> The effect also occurs using g++ 4.0.3.
> 
> It seems that throwing exceptions is not completely thread safe.
> 
> The crash symptom is one of:
> 1. segmentation fault (core dumped)
> 2. illegal instruction (core dumped)
> 3. terminate called after throwing an instance of 'int' (core dumped). 
> 
> The effect cannot clearly be reproduced.
> However when running the test program (crashme.cpp) with rather big parameter
> values
> one can proove that the program crashes very often after some time if the
> params are choosen big enough.
> 
> The program was build with following command:
> g++ crashme.cpp -o crashme -lpthread
> 
> Usage: crashme <number of threads> <number of runs>
> 
> For example 'crashme 50 1000' was enough to crash it on our box almost every
> time.
> 

Effect can also be reproduced with gcc 4.1.1 on HP-UX 11.11
Comment 8 Richard Biener 2007-01-20 10:37:26 UTC
How did you configure the hpux compiler?  I was told Linux/x86 works for you.
Can you verify that gthr-aix.h selected gthr-posix.h for compiling libgcc2 and
libstdc++-v3?
Comment 9 Chris Morley 2007-07-20 21:22:10 UTC
This fails for me too on HPUX 11.11, gcc 4.1.1:

cmm@wendy:121>uname -a
HP-UX wendy B.11.11 U 9000/785 1681839108 unlimited-user license
cmm@wendy:122>make
/opt/hp-gcc64-4.1.1/bin/g++ -pthread crashme.cpp -o crashme -lpthread
cmm@wendy:123>~/dev/.dev/gdb/hpux-hppa-11.11/bin/gdb crashme
GNU gdb 6.4
Copyright 2005 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 "hppa64-hp-hpux11.11"...(no debugging symbols found)

(gdb) run 5 10
Starting program: /home/cmm/hpux/crashme 5 10
Detaching after fork from child process 17434.
Detaching after fork from child process 17435.
Detaching after fork from child process 17436.
(no debugging symbols found)
(no debugging symbols found)
[New process 17433, lwp 886906]
Pass 1: Throwing exception in thread 0
[New process 17433, lwp 886907]
Pass 1: Throwing exception in thread 1
[New process 17433, lwp 886908]
Pass 1: Throwing exception in thread 2
[New process 17433, lwp 886909]
Pass 1: Throwing exception in thread 3
[New process 17433, lwp 886910]
Pass 1: Throwing exception in thread 4

Program received signal SIGSEGV, Segmentation fault.
[Switching to process 17433, lwp 886910]
_Unwind_SetGR (context=<value optimized out>, index=<value optimized out>, val=<value optimized out>)
    at /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/gcc/unwind-dw2.c:176
176     /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/gcc/unwind-dw2.c: No such file or directory.
        in /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/gcc/unwind-dw2.c
(gdb) bt
#0  _Unwind_SetGR (context=<value optimized out>, index=<value optimized out>, val=<value optimized out>)
    at /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/gcc/unwind-dw2.c:176
#1  0x800003ffbffc66c8 in __gxx_personality_v0 (version=<value optimized out>, actions=6, exception_class=<value optimized out>,
    ue_header=0x80000001000c4038, context=0x800003ffbfc8b490)
    at /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/libstdc++-v3/libsupc++/eh_personality.cc:672
#2  0x800003ffbfe36218 in _Unwind_RaiseException_Phase2 (exc=<value optimized out>, context=<value optimized out>)
    at unwind.inc:66
#3  0x800003ffbfe36524 in _Unwind_RaiseException (exc=<value optimized out>) at unwind.inc:135
#4  0x800003ffbffc6b70 in __cxa_throw (obj=<value optimized out>, tinfo=0x14, dest=0x80000001000c4038)
    at /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/libstdc++-v3/libsupc++/eh_throw.cc:72
#5  0x4000000000002bd8 in f ()
#6  0x800003ffbffdb250 in __pthread_body () from /lib/pa20_64/libpthread.1
#7  0x800003ffbffdb250 in __pthread_body () from /lib/pa20_64/libpthread.1
#8  0x800003ffbffdb250 in __pthread_body () from /lib/pa20_64/libpthread.1
#9  0x800003ffbffdb250 in __pthread_body () from /lib/pa20_64/libpthread.1
Cannot access memory at address 0x800003ffbfc8afb0
(gdb) quit
The program is running.  Exit anyway? (y or n) y
cmm@wendy:124>/opt/hp-gcc64-4.1.1/bin/g++ -v
Using built-in specs.
Target: hppa64-hp-hpux11.11
Configured with: /tmp/gcc-4.1.1.tar.gz/gcc-4.1.1/configure --host=hppa64-hp-hpux11.11 --target=hppa64-hp-hpux11.11 --build=hppa64-hp
-hpux11.11 --prefix=/opt/hp-gcc64-4.1.1 --enable-languages=c,c++ --with-gnu-as --without-gnu-ld --with-ld=/usr/ccs/bin/ld --enable-t
hreads=posix
Thread model: posix
gcc version 4.1.1
cmm@wendy:125>
Comment 10 Chris Morley 2007-07-24 15:51:50 UTC
It doesn't seem to fail using g++ 4.2. Fix or fluke?
Comment 11 dave 2007-07-24 16:25:54 UTC
Subject: Re:  Exception handling not thread-safe on AIX5.x and HP-UX

> It doesn't seem to fail using g++ 4.2. Fix or fluke?

There were some changes to config/pa/hpux-unwind.h in 2006 that
improved unwinding over stubs.  If using 4.1 is important, you
might try back porting these changes to see if that helps.  The
4.1 branch is essentially closed at this point in time.

Dave
Comment 12 Tony Reix 2021-01-11 17:50:14 UTC
This test no more fails on AIX 7.1 with GCC 8.4.0-5 provided by BullFreeware.
http://www.bullfreeware.com/?searching=true&package=gcc%208.4&from=&to=&libraries=false&exact=false&version=5