Currently we are half relying on libgcc's crtstuff. We have all the code for handling __CTOR_LIST__ but still rely on libgcc to provide the variables for us.
With respect to compiler-rt buitins this is an obvious problem because it assumes you already handle this rather then providing it for you. Please review. I was not quite sure how ld would react to __CTOR_LIST__ being defined in both libgcc and libmingw32 so I opted to change the name to __MINGW_CTOR_LIST__ to keep the peace :)
From a0aaf41fa802e171c82a1f956c600c7aa36c2eda Mon Sep 17 00:00:00 2001 From: Martell Malone <[email protected]> Date: Sat, 21 Nov 2015 18:43:46 -0800 Subject: [PATCH] Handle __CTOR_LIST__ internally within mingw-w64 diff --git a/mingw-w64-crt/crt/gccmain.c b/mingw-w64-crt/crt/gccmain.c index fc0e350..ba50691 100644 --- a/mingw-w64-crt/crt/gccmain.c +++ b/mingw-w64-crt/crt/gccmain.c @@ -9,8 +9,15 @@ #include <setjmp.h> typedef void (*func_ptr) (void); -extern func_ptr __CTOR_LIST__[]; -extern func_ptr __DTOR_LIST__[]; +#define STATIC static + +STATIC func_ptr __MINGW_CTOR_LIST__[1] + __attribute__ ((__used__, section(".ctors"), aligned(sizeof(func_ptr)))) + = { (func_ptr) (-1) }; + +STATIC func_ptr __MINGW_DTOR_LIST__[1] + __attribute__((section(".dtors"), aligned(sizeof(func_ptr)))) + = { (func_ptr) (-1) }; void __do_global_dtors (void); void __do_global_ctors (void); @@ -19,7 +26,7 @@ void __main (void); void __do_global_dtors (void) { - static func_ptr *p = __DTOR_LIST__ + 1; + static func_ptr *p = __MINGW_DTOR_LIST__ + 1; while (*p) { @@ -31,17 +38,17 @@ __do_global_dtors (void) void __do_global_ctors (void) { - unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0]; + unsigned long nptrs = (unsigned long) (ptrdiff_t) __MINGW_CTOR_LIST__[0]; unsigned long i; if (nptrs == (unsigned long) -1) { - for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++); + for (nptrs = 0; __MINGW_CTOR_LIST__[nptrs + 1] != 0; nptrs++); } for (i = nptrs; i >= 1; i--) { - __CTOR_LIST__[i] (); + __MINGW_CTOR_LIST__[i] (); } atexit (__do_global_dtors); -- 2.6.3
------------------------------------------------------------------------------
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
