public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer
@ 2014-04-23 12:07 lbl2007 at gmx dot net
  2014-04-23 12:09 ` [Bug libgcc/60939] " lbl2007 at gmx dot net
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: lbl2007 at gmx dot net @ 2014-04-23 12:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

            Bug ID: 60939
           Summary: AIX: exceptions not caught when calling function via
                    pointer
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lbl2007 at gmx dot net

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
@ 2014-04-23 12:09 ` lbl2007 at gmx dot net
  2014-04-23 12:15 ` lbl2007 at gmx dot net
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: lbl2007 at gmx dot net @ 2014-04-23 12:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #1 from lbl2007 at gmx dot net ---
Created attachment 32661
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32661&action=edit
Test program


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
  2014-04-23 12:09 ` [Bug libgcc/60939] " lbl2007 at gmx dot net
@ 2014-04-23 12:15 ` lbl2007 at gmx dot net
  2014-04-26  0:35 ` dje at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: lbl2007 at gmx dot net @ 2014-04-23 12:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #2 from lbl2007 at gmx dot net ---
*** Bug 60938 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
  2014-04-23 12:09 ` [Bug libgcc/60939] " lbl2007 at gmx dot net
  2014-04-23 12:15 ` lbl2007 at gmx dot net
@ 2014-04-26  0:35 ` dje at gcc dot gnu.org
  2014-05-06 16:13 ` lbl2007 at gmx dot net
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu.org @ 2014-04-26  0:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

David Edelsohn <dje at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|powerpc-ibm-aix6.1.0.0      |powerpc-ibm-aix
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-26
                 CC|                            |dje at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.8.0, 4.8.1, 4.8.2

--- Comment #3 from David Edelsohn <dje at gcc dot gnu.org> ---
Confirmed. There are known issues with global static constructors on AIX.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (2 preceding siblings ...)
  2014-04-26  0:35 ` dje at gcc dot gnu.org
@ 2014-05-06 16:13 ` lbl2007 at gmx dot net
  2014-05-08 15:01 ` dje at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: lbl2007 at gmx dot net @ 2014-05-06 16:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #4 from lbl2007 at gmx dot net ---
Can you suggest a workaround? 
I already found that combining all sources into a single compilation solves the
problem. However, in some cases, the combined source code becomes too large and
won't compile. What else could I try?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (3 preceding siblings ...)
  2014-05-06 16:13 ` lbl2007 at gmx dot net
@ 2014-05-08 15:01 ` dje at gcc dot gnu.org
  2015-03-19 23:38 ` zoltan at hidvegi dot com
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu.org @ 2014-05-08 15:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #5 from David Edelsohn <dje at gcc dot gnu.org> ---
I am not aware of any specific workaround. I assume that if you could avoid the
function pointer, you would.  G++ exception handling implementation on AIX is
fragile.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (4 preceding siblings ...)
  2014-05-08 15:01 ` dje at gcc dot gnu.org
@ 2015-03-19 23:38 ` zoltan at hidvegi dot com
  2015-03-21  5:59 ` dje at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: zoltan at hidvegi dot com @ 2015-03-19 23:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #6 from Zoltan Hidvegi <zoltan at hidvegi dot com> ---
gcc collect2 links the programs twice, first it links just all the object and
archive files passed, then it parses the output and if necessary creates a
source file that contains information about static constructors and destructors
and some tables for exception unwinding, and compiles and relinks with that
additional object file. The problem is that the AIX linker by default does
garbage collection, and removes stuff that is unreachable. In the example b.cc
which contains main has no reference at all to anything in a.cc, so the garbage
collector thinks it can throw it away. If I use -bkeepfile:a.o for the first ld
call from collect2, then garbage collection is skipped for a.o, and this allows
the correct generation of frame_table and the example works. Unfortunately,
using -bnogc does not work, it leads to lots of undefined symbols. However
using -bexpfull for the first link does work (without keepfile), maybe that's a
proper fix? The only problem with that is that gcc does not call the second
link if it's not necessary, however keeping the executable created with
-bexpfull is not a good idea, so gcc would always have to relink.

Btw. a workaround is to refer to any symbol from a.cc from b.cc, e.g. adding a
dummy void bar() {} to a.cc and void junk() { bar(); } into b.cc would make the
example work.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (5 preceding siblings ...)
  2015-03-19 23:38 ` zoltan at hidvegi dot com
@ 2015-03-21  5:59 ` dje at gcc dot gnu.org
  2015-03-21  7:43 ` zoltan at hidvegi dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu.org @ 2015-03-21  5:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #7 from David Edelsohn <dje at gcc dot gnu.org> ---
I had not noticed the lack of a reference to any symbol in the file, so missing
the static constructor.  -bexpfull probably would work around that problem but
likely cause another.

It's a tension between two different use cases and a fundamental problem with
collect2 and AIX.  If collect2 utilizes -bexpfull for the first pass and all
symbols are exported, then every object file and every member of an archive
will be referenced, and every constructor will be run.  But what if the archive
contains otherwise unneeded object files and constructors?  With the proposed
change, the resulting binary or shared object will, at best, only be bloated
with unnecessary symbols and functions, and, at worst, run unnecessary or
damaging constructors.  It essentially is enabling the equivalent of
--whole-archive for every link.

There have been other bug reports about this and collect2 explicitly tries to
strike a balance.

I think this bug report really requires the user to explicitly reference the
file containing the constructor or manually use the equivalent of
--whole-archive.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (6 preceding siblings ...)
  2015-03-21  5:59 ` dje at gcc dot gnu.org
@ 2015-03-21  7:43 ` zoltan at hidvegi dot com
  2015-03-21 21:11 ` dje at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: zoltan at hidvegi dot com @ 2015-03-21  7:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #8 from Zoltan Hidvegi <zoltan at hidvegi dot com> ---
How about using -bkeepfile: for all linked .o objects, that would create a very
similar semantics to other platforms, all .o objects are included, and only
objects that resolve undefined symbols would be included from .a files. This
would be a fix for the current bugreport, since it juse uses two .o files, and
one is collected away, but not completely, only in the first link pass, not in
the second link pass, due to the export file I guess. Certainly using -bexpall
is not a good idea.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (7 preceding siblings ...)
  2015-03-21  7:43 ` zoltan at hidvegi dot com
@ 2015-03-21 21:11 ` dje at gcc dot gnu.org
  2023-06-12 20:25 ` adam.swartz@ricoh-usa.com
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu.org @ 2015-03-21 21:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #9 from David Edelsohn <dje at gcc dot gnu.org> ---
-bkeepfile probably will produce more SVR4-like semantics, but I suspect the
-bkeepfile and replicating each object file name probably can blow out the
argument list length limit.  The object files can be fully qualified paths.

Fixing one, obscure corner case on AIX often creates another, obscure corner
case.  At least now, a user can explicitly add -Wl,-bkeepfile: to the command
line.  If collect2 added this implicitly and the link line, it would be
difficult to avoid.  Both failure modes are fairly confusing to the average
user.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (8 preceding siblings ...)
  2015-03-21 21:11 ` dje at gcc dot gnu.org
@ 2023-06-12 20:25 ` adam.swartz@ricoh-usa.com
  2023-06-12 22:16 ` dje at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: adam.swartz@ricoh-usa.com @ 2023-06-12 20:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #10 from Adam Swartz <adam.swartz@ricoh-usa.com> ---
I have a program with 130+ .o files that would need the keepfile option.  Is
there a way to pass all of the object files to the linker with a single
keepfile option?  I cannot find any doc on the keepfile linker option.

Thanks,
Adam

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (9 preceding siblings ...)
  2023-06-12 20:25 ` adam.swartz@ricoh-usa.com
@ 2023-06-12 22:16 ` dje at gcc dot gnu.org
  2023-06-13 14:39 ` adam.swartz@ricoh-usa.com
  2023-06-13 14:44 ` adam.swartz@ricoh-usa.com
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu.org @ 2023-06-12 22:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #11 from David Edelsohn <dje at gcc dot gnu.org> ---
One can pass command line arguments to the AIX linker through a file.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (10 preceding siblings ...)
  2023-06-12 22:16 ` dje at gcc dot gnu.org
@ 2023-06-13 14:39 ` adam.swartz@ricoh-usa.com
  2023-06-13 14:44 ` adam.swartz@ricoh-usa.com
  12 siblings, 0 replies; 14+ messages in thread
From: adam.swartz@ricoh-usa.com @ 2023-06-13 14:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #12 from Adam Swartz <adam.swartz@ricoh-usa.com> ---
Thanks David.  I think I got it working through the makefile with patterns,
variables and some conditional logic.  It didn't complain about command size,
but having that as a backup is good to know.

I would like to see this fixed.  Our code broke when we upgraded our AIX system
and had to upgrade the compiler recently.  Figuring out the reason for the
cores was a pain. Our case was not related to externs but to third level
inheritance and templates.  The try block was in main.  I sent sample code to
the AIX open source team but will add it here as well.

I tried to turn off all gc (-bnogc) and that didn't work, so this is still
error prone as new code gets added in.

Thanks,
Adam

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug libgcc/60939] AIX: exceptions not caught when calling function via pointer
  2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
                   ` (11 preceding siblings ...)
  2023-06-13 14:39 ` adam.swartz@ricoh-usa.com
@ 2023-06-13 14:44 ` adam.swartz@ricoh-usa.com
  12 siblings, 0 replies; 14+ messages in thread
From: adam.swartz@ricoh-usa.com @ 2023-06-13 14:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

--- Comment #13 from Adam Swartz <adam.swartz@ricoh-usa.com> ---
Created attachment 55319
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55319&action=edit
InheritanceCase

The shell script will compile things.  OpenSource team said they had to change
the -ggdb3 option.  The program TestCreateByMethodV4 generates the error.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-06-13 14:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-23 12:07 [Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer lbl2007 at gmx dot net
2014-04-23 12:09 ` [Bug libgcc/60939] " lbl2007 at gmx dot net
2014-04-23 12:15 ` lbl2007 at gmx dot net
2014-04-26  0:35 ` dje at gcc dot gnu.org
2014-05-06 16:13 ` lbl2007 at gmx dot net
2014-05-08 15:01 ` dje at gcc dot gnu.org
2015-03-19 23:38 ` zoltan at hidvegi dot com
2015-03-21  5:59 ` dje at gcc dot gnu.org
2015-03-21  7:43 ` zoltan at hidvegi dot com
2015-03-21 21:11 ` dje at gcc dot gnu.org
2023-06-12 20:25 ` adam.swartz@ricoh-usa.com
2023-06-12 22:16 ` dje at gcc dot gnu.org
2023-06-13 14:39 ` adam.swartz@ricoh-usa.com
2023-06-13 14:44 ` adam.swartz@ricoh-usa.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).