Bug 60938 - AIX: exceptions not caught when calling function via pointer
Summary: AIX: exceptions not caught when calling function via pointer
Status: RESOLVED DUPLICATE of bug 60939
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcc (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-23 12:06 UTC by mr1978
Modified: 2014-04-23 12:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mr1978 2014-04-23 12:06:57 UTC
The attached test program throws a std::runtime_error, but the corresponding
catch block is not executed. This only happens under certain circumstances. 
After some testing I found that the following conditions make the error appear:

(1) The function foo() doing the try/catch is in a compilation unit 
    different from main().
(2) foo() is called from main() via a function pointer (pfoo).
(3) pfoo is initialized in a global static constructor in a compilation 
    unit different from main.

To reproduce the error:
  g++ -g -o demo a.cc b.cc
  ./demo
  BEGIN
  terminate called after throwing an instance of 'std::runtime_error'
    what():  TILT
  IOT/Abort trap (core dumped)

Test program (both raw and preprocessed sources are in the attached TAR file):

//////////////////////////////////////////////////// FILE a.cc
#include <stdio.h>
#include <stdexcept>

extern void (*pFoo)();

void foo()
{
   fputs("BEGIN\n",stderr);
   try { throw std::runtime_error("TILT"); }
   catch( const std::runtime_error &e ) { }
   fputs("OK\n",stderr);
}

struct Init { Init() { pFoo = foo; } } init;

//////////////////////////////////////////////////// FILE b.cc
extern void foo();

void (*pFoo)() = 0;

int main( int argc, char *argv[] )
{
   pFoo();
   return 0;
}

//////////////////////////////////////////////////// Version info:
g++ -v
Using built-in specs.
COLLECT_GCC=/common/mringe/gcc482/local/bin/g++
COLLECT_LTO_WRAPPER=/common/mringe/gcc482/local/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.2/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: /common/mringe/gcc482/gcc-4.8.2/configure --prefix=/common/mringe/gcc482/local --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++ --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-gmp=/common/mringe/gcc482/local --with-mpfr=/common/mringe/gcc482/local --with-mpc=/common/mringe/gcc482/local --with-local-prefix=/common/mringe/gcc482/local
Thread model: aix
gcc version 4.8.2 (GCC) 

uname -a
AIX srva001 1 6 00F817FA4C00 AIX
Comment 1 mr1978 2014-04-23 12:15:42 UTC
Duplicate, please delete

*** This bug has been marked as a duplicate of bug 60939 ***