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: unassig...@gcc.gnu.org
        ReportedBy: pedz...@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.

Reply via email to