The latest update to file winsup/mingw/tlssup.c has undo the path I sent about a year ago in ID: 3105314, so the same bug reappeared. The difference now is that GCC 4.6 is no longer experimental, so the problem is more notorious.
For reference, I copy the description again and an updated patch (this time with comments).
The issue here seems to be that the new GCC optimizes away the comparison before the first iteration of the loop, so if the list is empty (which is in simple test programs), it crashes.
The patch below solves the issue by avoiding the comparison between pointers to global variables.
--- a/tlssup.c 2011-11-30 15:20:26.388725544 +0100
+++ b/tlssup.c 2011-11-30 15:25:26.798214841 +0100
@@ -84,7 +84,7 @@
__dyn_tls_init (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
_PVFV *pfunc;
-
+ int nfuncs, ifunc;
/* We don't let us trick here. */
if (_CRT_MT != 2)
_CRT_MT = 2;
@@ -96,8 +96,12 @@
return TRUE;
}
- for (pfunc = &__xd_a + 1; pfunc != &__xd_z; ++pfunc)
+ /* Use the nfuncs variable to iterate the TLS functions instead of pfunc to avoid
+ nasty compiler optimizations when comparing two global pointers. */
+ nfuncs = &__xd_z - (&__xd_a + 1);
+ for (ifunc = 0; ifunc < nfuncs; ++ifunc)
{
+ pfunc = (&__xd_a + 1) + ifunc;
if (*pfunc != NULL)
(*pfunc)();
}
Changelog:
mingw/
2011-11-30 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
* tlssup.c (__dyn_tls_init): Reapply patch from 3105314.
Thank you for the heads up and the patch. This likely corrects the issue reported here:
http://sourceforge.net/tracker/?func=detail&atid=102435&aid=3443215&group_id=2435
I will test and commit your patch later tonight.
In the future please upload a patch file. SF screws with the spaces when displaying the entered text.
I confirm the patch corrects the issue I was having.
File a rekeyed by Earnie
I've attached the patch file.
I've applied your patch, thank you for the fix.