From 6bb19351d92b3ea1691f96c15fdd230f2f4ce9ac Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 29 Oct 2014 09:56:18 +0000 Subject: * common.din (__cxa_atexit): Define as cygwin__cxa_atexit. * dcrt0.cc (cygwin__cxa_atexit): New function. Explain what we do. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/common.din | 2 +- winsup/cygwin/dcrt0.cc | 18 ++++++++++++++++++ winsup/cygwin/release/1.7.33 | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'winsup/cygwin') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e8c833377..ee1fff587 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2014-10-29 Corinna Vinschen + + * common.din (__cxa_atexit): Define as cygwin__cxa_atexit. + * dcrt0.cc (cygwin__cxa_atexit): New function. Explain what we do. + 2014-10-28 Corinna Vinschen * globals.cc (dos_file_warning): Set to false by default. diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din index 95d6a7d98..3fcde65cc 100644 --- a/winsup/cygwin/common.din +++ b/winsup/cygwin/common.din @@ -41,7 +41,7 @@ __assert_func NOSIGFE __assertfail NOSIGFE __b64_ntop NOSIGFE __b64_pton NOSIGFE -__cxa_atexit SIGFE +__cxa_atexit = cygwin__cxa_atexit SIGFE __cxa_finalize SIGFE __dn_comp SIGFE __dn_expand SIGFE diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index b2bbe8657..f021f0281 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1232,6 +1232,24 @@ do_exit (int status) myself.exit (n); } +/* When introducing support for -fuse-cxa-atexit with Cygwin 1.7.32 and + GCC 4.8.3-3, we defined __dso_value as &ImageBase. This supposedly allowed + a reproducible value which could also be easily evaluated in cygwin_atexit. + However, when building C++ applications with -fuse-cxa-atexit, G++ creates + calls to __cxa_atexit using the *address* of __dso_handle as DSO handle. + + So what we do here is this: A call to __cxa_atexit from the application + actually calls cygwin__cxa_atexit. From the dso_handle value we fetch the + ImageBase address, which is then used as the actual DSO handle value in + calls to __cxa_atexit and __cxa_finalize. */ +extern "C" int +cygwin__cxa_atexit (void (*fn)(void *), void *obj, void *dso_handle) +{ + if (dso_handle) + dso_handle = *(void **) dso_handle; + return __cxa_atexit (fn, obj, dso_handle); +} + extern "C" int cygwin_atexit (void (*fn) (void)) { diff --git a/winsup/cygwin/release/1.7.33 b/winsup/cygwin/release/1.7.33 index 652a61ed4..02c07faad 100644 --- a/winsup/cygwin/release/1.7.33 +++ b/winsup/cygwin/release/1.7.33 @@ -88,3 +88,7 @@ Bug Fixes - Fix a SEGV in some 64 bit applications explicitely dlclosing DLLs. Addresses: https://cygwin.com/ml/cygwin/2014-10/msg00402.html + +- Fix -fuse-cxa-atexit handling where dlclose fails to trigger calling + global dtors in dynamically loaded modules in C++ applications (and + thus another potential SEGV). -- cgit v1.2.3