Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Korn <dave.korn.cygwin@gmail.com>2009-07-08 00:12:44 +0400
committerDave Korn <dave.korn.cygwin@gmail.com>2009-07-08 00:12:44 +0400
commitb602bb90e21d5259ce85e11bf968aa624bdb592b (patch)
tree8c7c57bdcb700df8cb617cc24876e437c1c1a6fa /winsup/cygwin/lib/_cygwin_crt0_common.cc
parent6499c6e07b217eb22274c090f7a9f3d0d3de2be4 (diff)
winsup/ChangeLog:
* Makefile.common (COMPILE_CXX): Add support for per-file overrides to exclude $(nostdinc) and $(nostdincxx) from compiler flags. (COMPILE_CC): Likewise for $(nostdinc). winsup/cygwin/ChangeLog: * Makefile.in (DLL_OFILES): Add libstdcxx_wrapper.o (libstdcxx_wrapper_CFLAGS): Add flags for new module. (_cygwin_crt0_common_STDINCFLAGS): Define per-file override. (libstdcxx_wrapper_STDINCFLAGS, cxx_STDINCFLAGS): Likewise. * cxx.cc: Include "cygwin-cxx.h". (operator new): Tweak prototype for full standards compliance. (operator new[]): Likewise. (operator new (nothrow)): New fallback function. (operator new[] (nothrow), operator delete (nothrow), operator delete[] (nothrow)): Likewise. (default_cygwin_cxx_malloc): New struct of pointers to the above, for final last-resort fallback default. * cygwin-cxx.h: New file. (struct per_process_cxx_malloc): Define. (default_cygwin_cxx_malloc): Declare extern. * cygwin.din (__wrap__ZdaPv): Export new wrapper. (__wrap__ZdaPvRKSt9nothrow_t, __wrap__ZdlPv, __wrap__ZdlPvRKSt9nothrow_t, __wrap__Znaj, __wrap__ZnajRKSt9nothrow_t, __wrap__Znwj, __wrap__ZnwjRKSt9nothrow_t): Likewise. * globals.cc (__cygwin_user_data): Init newly-repurposed 'forkee' field (now 'cxx_malloc') to point to default_cygwin_cxx_malloc. * libstdcxx_wrapper.cc: New file. (__wrap__ZdaPv, __wrap__ZdaPvRKSt9nothrow_t, __wrap__ZdlPv, __wrap__ZdlPvRKSt9nothrow_t, __wrap__Znaj, __wrap__ZnajRKSt9nothrow_t, __wrap__Znwj, __wrap__ZnwjRKSt9nothrow_t): Define wrapper functions for libstdc++ malloc operators and their overrides. * winsup.h (default_cygwin_cxx_malloc): Declare extern. * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump. * include/sys/cygwin.h (struct per_process_cxx_malloc): Forward declare here. (struct per_process::forkee): Rename and repurpose from this ... (struct per_process::cxx_malloc): ... to this. * lib/_cygwin_crt0_common.cc: Include cygwin-cxx.h. (WEAK): Define shorthand helper macro. (__cygwin_cxx_malloc): Define and populate with weak references to whatever libstdc++ malloc operators will be visible at final link time for Cygwin apps and dlls. (_cygwin_crt0_common): Always look up cygwin DLL's internal per_process data, and don't test for (impossible) failure. Inherit any members of __cygwin_cxx_malloc that we don't have overrides for from the DLL's default and store the resulting overall set of overrides back into the DLL's global per_process data.
Diffstat (limited to 'winsup/cygwin/lib/_cygwin_crt0_common.cc')
-rw-r--r--winsup/cygwin/lib/_cygwin_crt0_common.cc73
1 files changed, 62 insertions, 11 deletions
diff --git a/winsup/cygwin/lib/_cygwin_crt0_common.cc b/winsup/cygwin/lib/_cygwin_crt0_common.cc
index a81c3e932..280c50ef4 100644
--- a/winsup/cygwin/lib/_cygwin_crt0_common.cc
+++ b/winsup/cygwin/lib/_cygwin_crt0_common.cc
@@ -10,8 +10,34 @@ details. */
#include "winsup.h"
#include "crt0.h"
-
-/* Avoid an info message from linker when linking applications. */
+#include "cygwin-cxx.h"
+
+/* Weaken these declarations so the references don't pull in C++ dependencies
+ unnecessarily. */
+#define WEAK __attribute__ ((weak))
+
+/* Use asm names to bypass the --wrap that is being applied to redirect all other
+ references to these operators toward the redirectors in the Cygwin DLL; this
+ way we can record what definitions were visible at final link time but still
+ send all calls to the redirectors. */
+extern WEAK void *operator new(std::size_t sz) throw (std::bad_alloc)
+ __asm__ ("___real__Znwj");
+extern WEAK void *operator new[](std::size_t sz) throw (std::bad_alloc)
+ __asm__ ("___real__Znaj");
+extern WEAK void operator delete(void *p) throw()
+ __asm__ ("___real__ZdlPv ");
+extern WEAK void operator delete[](void *p) throw()
+ __asm__ ("___real__ZdaPv");
+extern WEAK void *operator new(std::size_t sz, const std::nothrow_t &nt) throw()
+ __asm__ ("___real__ZnwjRKSt9nothrow_t");
+extern WEAK void *operator new[](std::size_t sz, const std::nothrow_t &nt) throw()
+ __asm__ ("___real__ZnajRKSt9nothrow_t");
+extern WEAK void operator delete(void *p, const std::nothrow_t &nt) throw()
+ __asm__ ("___real__ZdlPvRKSt9nothrow_t");
+extern WEAK void operator delete[](void *p, const std::nothrow_t &nt) throw()
+ __asm__ ("___real__ZdaPvRKSt9nothrow_t");
+
+/* Avoid an info message from linker when linking applications. */
extern __declspec(dllimport) struct _reent *_impure_ptr;
#undef environ
@@ -25,6 +51,14 @@ int main (int, char **, char **);
int _fmode;
void _pei386_runtime_relocator ();
+struct per_process_cxx_malloc __cygwin_cxx_malloc =
+{
+ &(operator new), &(operator new[]),
+ &(operator delete), &(operator delete[]),
+ &(operator new), &(operator new[]),
+ &(operator delete), &(operator delete[])
+};
+
/* Set up pointers to various pieces so the dll can then use them,
and then jump to the dll. */
@@ -33,17 +67,15 @@ _cygwin_crt0_common (MainFunc f, per_process *u)
{
/* This is used to record what the initial sp was. The value is needed
when copying the parent's stack to the child during a fork. */
- DWORD newu;
+ per_process *newu = (per_process *) cygwin_internal (CW_USER_DATA);
int uwasnull;
if (u != NULL)
- uwasnull = 0; /* Caller allocated space for per_process structure */
- else if ((newu = cygwin_internal (CW_USER_DATA)) == (DWORD) -1)
- return 0;
+ uwasnull = 0; /* Caller allocated space for per_process structure. */
else
{
- u = (per_process *) newu; /* Using DLL built-in per_process */
- uwasnull = 1; /* Remember for later */
+ u = newu; /* Using DLL built-in per_process. */
+ uwasnull = 1; /* Remember for later. */
}
/* The version numbers are the main source of compatibility checking.
@@ -64,8 +96,6 @@ _cygwin_crt0_common (MainFunc f, per_process *u)
else
u->impure_ptr_ptr = &_impure_ptr; /* Older DLLs need this. */
- u->forkee = 0; /* This should only be set in dcrt0.cc
- when the process is actually forked */
u->main = f;
/* These functions are executed prior to main. They are just stubs unless the
@@ -84,7 +114,28 @@ _cygwin_crt0_common (MainFunc f, per_process *u)
u->realloc = &realloc;
u->calloc = &calloc;
- /* Setup the module handle so fork can get the path name. */
+ /* Likewise for the C++ memory operators - if any. */
+ if (newu && newu->cxx_malloc)
+ {
+ /* Inherit what we don't override. */
+#define CONDITIONALLY_OVERRIDE(MEMBER) \
+ if (!__cygwin_cxx_malloc.MEMBER) \
+ __cygwin_cxx_malloc.MEMBER = newu->cxx_malloc->MEMBER;
+ CONDITIONALLY_OVERRIDE(oper_new);
+ CONDITIONALLY_OVERRIDE(oper_new__);
+ CONDITIONALLY_OVERRIDE(oper_delete);
+ CONDITIONALLY_OVERRIDE(oper_delete__);
+ CONDITIONALLY_OVERRIDE(oper_new_nt);
+ CONDITIONALLY_OVERRIDE(oper_new___nt);
+ CONDITIONALLY_OVERRIDE(oper_delete_nt);
+ CONDITIONALLY_OVERRIDE(oper_delete___nt);
+ }
+
+ /* Now update the resulting set into the global redirectors. */
+ if (newu)
+ newu->cxx_malloc = &__cygwin_cxx_malloc;
+
+ /* Setup the module handle so fork can get the path name. */
u->hmodule = GetModuleHandle (0);
/* variables for fork */