diff options
Diffstat (limited to 'winsup/cygwin/dlfcn.cc')
-rw-r--r-- | winsup/cygwin/dlfcn.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc index a9e3295da..bc95e221c 100644 --- a/winsup/cygwin/dlfcn.cc +++ b/winsup/cygwin/dlfcn.cc @@ -93,7 +93,28 @@ dlopen (const char *name, int) wchar_t *path = tp.w_get (); pc.get_wide_win32_path (path); + + /* Workaround for broken DLLs built against Cygwin versions 1.7.0-49 + up to 1.7.0-57. They override the cxx_malloc pointer in their + DLL initialization code even if loaded dynamically. This is a + no-no since a later dlclose lets cxx_malloc point into nirvana. + The below kludge "fixes" that by reverting the original cxx_malloc + pointer after LoadLibrary. This implies that their overrides + won't be applied; that's OK. All overrides should be present at + final link time, as Windows doesn't allow undefined references; + it would actually be wrong for a dlopen'd DLL to opportunistically + override functions in a way that wasn't known then. We're not + going to try and reproduce the full ELF dynamic loader here! */ + + /* Store original cxx_malloc pointer. */ + struct per_process_cxx_malloc *tmp_malloc; + tmp_malloc = __cygwin_user_data.cxx_malloc; + ret = (void *) LoadLibraryW (path); + + /* Restore original cxx_malloc pointer. */ + __cygwin_user_data.cxx_malloc = tmp_malloc; + if (ret == NULL) __seterrno (); } |