public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break
@ 2012-09-16 14:36 pedzsan at gmail dot com
  2012-09-16 14:39 ` [Bug c++/54601] " pedzsan at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: pedzsan at gmail dot com @ 2012-09-16 14:36 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54601
           Summary: AIX uses atexit which causes unloading of shared
                    modules to break
    Classification: Unclassified
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pedzsan@gmail.com


Created attachment 28200
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28200
git diff -c of base 4.5.2 tarball against new files and changes

The bug was hit when using Apache httpd with a module called passenger. 
passenger uses some c++ code.  httpd does an unload of all of the modules that
it loads when it exits.  The symptom is a core dump because by the time the
atexit is run, the TOC entries as well as the code to execute which are
registered as the DTORs have been unloaded.

Using the x1.cpp attached, I determined that the atexit is used to register a
DTOR for a static object with a non-trivial DTOR that is declared inside a
function.  The DTOR is registered only if the function is called.  (x1.cpp does
not demonstrate the problem.  It was just used to educate me about when gcc
used the atexit service.)

I am also supplying a patch to the base 4.5.2 tarball that fixes the problem. 
I stole the cxa_atexit and cxa_finialize from GNU's glibc-2.16.0
implementation.  I believe I have removed glibc's locking and successfully
added back in the locking that gcc uses so that the file is built properly on
the four different platforms: 32 bit, 32 bit threaded, 64 bit and 64 bit
threaded.

The changes to the configure and makefiles will need to be ported to the real
files.  I added references to the two new files introduced into the makefile
and changed the configure script to assume cxa_atexit is present on AIX systems
so that it will honor the --enable-__cxa_atexit configure option.  The options
I used for configure are:

    "--with-gmp=${PUBLIC_BASE}" \
    "--with-mpfr=${PUBLIC_BASE}" \
    "--with-mpc=${PUBLIC_BASE}" \
    "--disable-nls" \
    "--enable-threads=aix" \
    "--with-libiconv-prefix=/usr" \
    "--enable-__cxa_atexit" \
    "--enable-languages=c,c++"

If all goes well, I propose to have --enable-__cxa_atexit be the default for
AIX.

The final big change is to collect2.  The changes are rather large.  I tried to
keep the proper style.  There may be some debugging that can be removed.  A new
c stub is created in the first link pass so that __dso_handle can be declared
to allow the first link to complete.  I generalized a few things in the
process.  I hope all that is ok.

I've used this new compiler for a month now but only on the original problem. 
All seems to be working.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
@ 2012-09-16 14:39 ` pedzsan at gmail dot com
  2012-09-16 14:40 ` pedzsan at gmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pedzsan at gmail dot com @ 2012-09-16 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Perry Smith <pedzsan at gmail dot com> 2012-09-16 14:39:05 UTC ---
Created attachment 28201
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28201
Educational program demonstrating when atexit is used.

Run it without an argument, the function that declares the static is not called
-- thus the DTOR is not registered.  Run it with an argument to call the
function that declares the static.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
  2012-09-16 14:39 ` [Bug c++/54601] " pedzsan at gmail dot com
@ 2012-09-16 14:40 ` pedzsan at gmail dot com
  2012-09-16 18:47 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pedzsan at gmail dot com @ 2012-09-16 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Perry Smith <pedzsan at gmail dot com> 2012-09-16 14:40:25 UTC ---
Forgot to mention.  A long thread discussing the issue, etc is here:

http://www.mail-archive.com/gcc@gcc.gnu.org/msg65140.html


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
  2012-09-16 14:39 ` [Bug c++/54601] " pedzsan at gmail dot com
  2012-09-16 14:40 ` pedzsan at gmail dot com
@ 2012-09-16 18:47 ` redi at gcc dot gnu.org
  2012-09-17 14:18 ` pedzsan at gmail dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-16 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-09-16 18:47:11 UTC ---
To be included the patch needs to be against trunk.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (2 preceding siblings ...)
  2012-09-16 18:47 ` redi at gcc dot gnu.org
@ 2012-09-17 14:18 ` pedzsan at gmail dot com
  2012-10-01 16:31 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pedzsan at gmail dot com @ 2012-09-17 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Perry Smith <pedzsan at gmail dot com> 2012-09-17 14:18:34 UTC ---
(In reply to comment #3)
> To be included the patch needs to be against trunk.

I don't mind trying to redo this against trunk but I need some help learning
how to build against the trunk.  I'm assume it is documented somewhere but I
don't know where.  I looked (e.g. site:gcc.gnu.org/onlinedocs build trunk)
doesn't hit anything useful.  The pdf does not have "autoconf" nor "automake"
which I'm sure are needed.  So I got stumped.  Sorry.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (3 preceding siblings ...)
  2012-09-17 14:18 ` pedzsan at gmail dot com
@ 2012-10-01 16:31 ` paolo.carlini at oracle dot com
  2012-10-03 17:53 ` dje at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-01 16:31 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dje at gcc dot gnu.org

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-01 16:31:10 UTC ---
Adding David as AIX maintainer.

In terms of building, nothings extraordinary happened between 4.5 and current
mainline. Make sure you have the required libraries installed (minimally, gmp,
mpfr, mpc) and build as usual. Maybe David can help you about AIX-specific
details.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (4 preceding siblings ...)
  2012-10-01 16:31 ` paolo.carlini at oracle dot com
@ 2012-10-03 17:53 ` dje at gcc dot gnu.org
  2013-01-30 16:59 ` dje at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2012-10-03 17:53 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-03
     Ever Confirmed|0                           |1

--- Comment #6 from David Edelsohn <dje at gcc dot gnu.org> 2012-10-03 17:52:48 UTC ---
Perry and I have been discussing this for a while.  As others mentioned, the
patch should be against mainline and this discussion of the path should happen
on gcc-patches, not Bugzilla.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (5 preceding siblings ...)
  2012-10-03 17:53 ` dje at gcc dot gnu.org
@ 2013-01-30 16:59 ` dje at gcc dot gnu.org
  2013-01-30 21:58 ` dje at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2013-01-30 16:59 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from David Edelsohn <dje at gcc dot gnu.org> 2013-01-30 16:59:13 UTC ---
Created attachment 29307
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29307
cxa_atexit implementation in libgcc

This version of the patch implements __cxa_atexit and __cxa_finalize in libgcc,
not libsupc++, with no modifications to collect2.  I am not sure if using a low
priority C destructor to run __cxa_finalize early in the destructor list is
correct. The original collect2 patch ran it last, after other destructors,
which I believe is incorrect and does not match crtstuff.c semantics for ELF. 
When I configured GCC with the patch and --enable__cxa-atexit, I saw a few
additional C++ errors in the testsuite.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (6 preceding siblings ...)
  2013-01-30 16:59 ` dje at gcc dot gnu.org
@ 2013-01-30 21:58 ` dje at gcc dot gnu.org
  2013-01-31  4:53 ` dje at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2013-01-30 21:58 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #29307|0                           |1
        is obsolete|                            |

--- Comment #8 from David Edelsohn <dje at gcc dot gnu.org> 2013-01-30 21:57:52 UTC ---
Created attachment 29311
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29311
Revised __cxa_atexit for libgcc

The revised patch uses LIB2ADDEH to add the functions to libgcc_s.a and
libgcc_eh.a so that only one copy should exist in a process.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (7 preceding siblings ...)
  2013-01-30 21:58 ` dje at gcc dot gnu.org
@ 2013-01-31  4:53 ` dje at gcc dot gnu.org
  2013-01-31  5:50 ` pedzsan at gmail dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2013-01-31  4:53 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from David Edelsohn <dje at gcc dot gnu.org> 2013-01-31 04:52:51 UTC ---
This is going to be more difficult because __dso_handle needs to be provided by
a new crt file supplied by GCC, not by the libraries. That is the way that
every module ends up with a unique value. Otherwise the single __dso_handle is
shared across the entire process.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (8 preceding siblings ...)
  2013-01-31  4:53 ` dje at gcc dot gnu.org
@ 2013-01-31  5:50 ` pedzsan at gmail dot com
  2013-01-31  6:11 ` dje at gcc dot gnu.org
  2013-02-01 20:27 ` dje at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pedzsan at gmail dot com @ 2013-01-31  5:50 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #10 from Perry Smith <pedzsan at gmail dot com> 2013-01-31 05:50:00 UTC ---
Can you keep the libraries like you have them with the functions and private
structures for the functions coming from the library but just put the
definition of __dso_handle in crt?


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (9 preceding siblings ...)
  2013-01-31  5:50 ` pedzsan at gmail dot com
@ 2013-01-31  6:11 ` dje at gcc dot gnu.org
  2013-02-01 20:27 ` dje at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2013-01-31  6:11 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #29311|0                           |1
        is obsolete|                            |

--- Comment #11 from David Edelsohn <dje at gcc dot gnu.org> 2013-01-31 06:11:31 UTC ---
Created attachment 29312
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29312
__cxa_atexit with new crt file

I think it needs something like this new patch, which adds crtdso.o providing
__dso_handle.  collect2 searches the file properly and finds the destructor.
But I am not sure if the driver will find the file and if the file is installed
correctly yet.


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

* [Bug c++/54601] AIX uses atexit which causes unloading of shared modules to break
  2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
                   ` (10 preceding siblings ...)
  2013-01-31  6:11 ` dje at gcc dot gnu.org
@ 2013-02-01 20:27 ` dje at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: dje at gcc dot gnu.org @ 2013-02-01 20:27 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #12 from David Edelsohn <dje at gcc dot gnu.org> 2013-02-01 20:26:37 UTC ---
Author: dje
Date: Fri Feb  1 20:26:24 2013
New Revision: 195675

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195675
Log:
        PR target/54601
libgcc/
        * config.host (powerpc-ibm-aix[56789]): Add t-aix-cxa to tmake_file.
        Add crtcxa to extra_parts.
        * config/rs6000/exit.h: New file.
        * config/rs6000/cxa_atexit.c: New file.
        * config/rs6000/cxa_finalize.c: New file.
        * config/rs6000/crtcxa.c: New file.
        * config/rs6000/t-aix-cxa: New file.
        * config/rs6000/libgcc-aix-cxa.ver: New file.

gcc/
        * configure.ac (cxa_atexit): Add AIX.
        * configure: Regenerate.

        * config/rs6000/aix61.h (STARTFILE_SPEC): Add crtcxa.o.


Added:
    trunk/libgcc/config/rs6000/crtcxa.c
    trunk/libgcc/config/rs6000/cxa_atexit.c
    trunk/libgcc/config/rs6000/cxa_finalize.c
    trunk/libgcc/config/rs6000/exit.h
    trunk/libgcc/config/rs6000/libgcc-aix-cxa.ver
    trunk/libgcc/config/rs6000/t-aix-cxa
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/aix61.h
    trunk/gcc/configure
    trunk/gcc/configure.ac
    trunk/libgcc/ChangeLog
    trunk/libgcc/config.host


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

end of thread, other threads:[~2013-02-01 20:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-16 14:36 [Bug c++/54601] New: AIX uses atexit which causes unloading of shared modules to break pedzsan at gmail dot com
2012-09-16 14:39 ` [Bug c++/54601] " pedzsan at gmail dot com
2012-09-16 14:40 ` pedzsan at gmail dot com
2012-09-16 18:47 ` redi at gcc dot gnu.org
2012-09-17 14:18 ` pedzsan at gmail dot com
2012-10-01 16:31 ` paolo.carlini at oracle dot com
2012-10-03 17:53 ` dje at gcc dot gnu.org
2013-01-30 16:59 ` dje at gcc dot gnu.org
2013-01-30 21:58 ` dje at gcc dot gnu.org
2013-01-31  4:53 ` dje at gcc dot gnu.org
2013-01-31  5:50 ` pedzsan at gmail dot com
2013-01-31  6:11 ` dje at gcc dot gnu.org
2013-02-01 20:27 ` dje at gcc dot gnu.org

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).