diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2014-11-05 19:26:18 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2014-11-05 19:26:18 +0300 |
commit | e5e6b6c49f1fbca0b3fd9b58e98fa25116d9e438 (patch) | |
tree | 4d4216ec255829e0b96889ee66c9321ced9005b5 /winsup | |
parent | b8fd41f5df60b386cfa623ec12cd2f3840c39081 (diff) |
* lib/atexit.c (atexit): Check for being linked into the executable.
If so, call __cxa_atexit with NULL DSO handle. Explain why.
* lib/dso_handle.c: New file providing fallback __dso_handle.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/cygwin/lib/atexit.c | 13 | ||||
-rw-r--r-- | winsup/cygwin/lib/dso_handle.c | 12 |
3 files changed, 30 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 69ad486e0..8b1098e5c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,11 @@ 2014-11-05 Corinna Vinschen <corinna@vinschen.de> + * lib/atexit.c (atexit): Check for being linked into the executable. + If so, call __cxa_atexit with NULL DSO handle. Explain why. + * lib/dso_handle.c: New file providing fallback __dso_handle. + +2014-11-05 Corinna Vinschen <corinna@vinschen.de> + * Makefile.in (NEW_FUNCTIONS): Add atexit to be not exported. * lib/atexit.c (atexit): New, statically linkable version of atexit. * dcrt0.cc (cygwin_atexit): Add comment to mark this function as old diff --git a/winsup/cygwin/lib/atexit.c b/winsup/cygwin/lib/atexit.c index 0b724771a..af82d1de7 100644 --- a/winsup/cygwin/lib/atexit.c +++ b/winsup/cygwin/lib/atexit.c @@ -9,6 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include <stddef.h> +#include <windows.h> /* Statically linked replacement for the former cygwin_atexit. We need the function here to be able to access the correct __dso_handle of the @@ -18,6 +19,16 @@ atexit (void (*fn) (void)) { extern int __cxa_atexit(void (*)(void*), void*, void*); extern void *__dso_handle; + extern void *__ImageBase; - return __cxa_atexit ((void (*)(void*))fn, NULL, &__dso_handle); + /* Check for being called from inside the executable. If so, use NULL + as __dso_handle. This allows to link executables with GCC versions + not providing __dso_handle in crtbegin{S}.o. In this case our own + __dso_handle defined in lib/dso_handle.c is used. However, our + __dso_handle always points to &__ImageBase, while the __dso_handle + for executables provided by crtbegin.o usually points to NULL. + That's what we remodel here. */ + return __cxa_atexit ((void (*)(void*))fn, NULL, + &__ImageBase == (void **) GetModuleHandleW (NULL) + ? NULL : &__dso_handle); } diff --git a/winsup/cygwin/lib/dso_handle.c b/winsup/cygwin/lib/dso_handle.c new file mode 100644 index 000000000..c3069b732 --- /dev/null +++ b/winsup/cygwin/lib/dso_handle.c @@ -0,0 +1,12 @@ +/* dso_handle.c: Provide default __dso_handle. + + Copyright 2014 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +extern void *__ImageBase; +void *__dso_handle = &__ImageBase; |