[PATCH] Libstdc++ support changes.

Dave Korn dave.korn.cygwin@googlemail.com
Tue Jul 7 16:10:00 GMT 2009

    Hi all,

  I just got done doing a C/C++/libstdc++-v3 test run against GCC HEAD using
the Cygwin DLL built with these patches, and everything worked.  In
particular, it passed these tests:

> FAIL: g++.old-deja/g++.abi/cxa_vec.C execution test
> FAIL: g++.old-deja/g++.brendan/new3.C execution test

... which fail on current 4.3.2-2 using shared libstdc++ DLL precisely because
they expect to be able to interpose libstdc++'s own internal calls to the
allocation operators.  I've also been using it in daily use (and before that,
the previous spin of this patch) for a while now and nothing unusual has been
showing up.

  I'm now busy packaging a version of gcc-4.3.3 that will incorporate the
necessary support to make this work, and though that'll be another few days
testing, it's not going to need anything different by way of support from the
Cygwin DLL, so I reckon this is ready for primetime.

  Re: the last outstanding issues we discussed; I decided not to try and fold
the malloc handling into this.  The malloc wrappers work without needing
compiler support, and we can do that because we are the libc and we own
malloc.  That isn't the same as for the C++ operators, and I don't think we
should conflate parts of libstdc++ into the Cygwin DLL.  For that reason, I
figured we shouldn't export ONDEE directly, even weakly, and that leaves us
just the option of ld wrappers.  Given that C++ is big and complex and
requires the whole toolchain to be aware anyway, I think that's an acceptable
compromise, but malloc and friends are plain old C and someone might even want
to call them from assembly, and I didn't see it was worth adding complexity
and fragility.

  The second idea was representing the pointers as an array somehow to make
extending it in future easier.  I had a quick go, but it gets pretty ugly
pretty quickly when you try and union them against an array of PVOIDs or
whatever, because you can't statically initialise a union, so you end up only
declaring the struct and then having to cast it to a union in other places.  I
 don't suppose extending this mechanism in future is terribly likely; it
exists to support the requirements of the C++ spec, and that's not likely to
start specifying any new function replacements anytime foreseeable.


	* Makefile.common (COMPILE_CXX):  Add support for per-file overrides
	to exclude $(nostdinc) and $(nostdincxx) from compiler flags.
	(COMPILE_CC):  Likewise for $(nostdinc).


	* 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.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygwin-dll-libstdcxx-wrappers-final.diff
Type: text/x-c
Size: 17890 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20090707/681c7bf6/attachment.bin>

More information about the Cygwin-patches mailing list