Menu

#504 Regression of 3105314: mingw crashes with GCC 4.6

closed-accepted
2011-11-30
2011-11-30
rodrigo
No

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.

Discussion

  • Earnie Boyd

    Earnie Boyd - 2011-11-30

    In the future please upload a patch file. SF screws with the spaces when displaying the entered text.

     
  • Earnie Boyd

    Earnie Boyd - 2011-11-30
    • assigned_to: nobody --> ir0nh34d
     
  • Earnie Boyd

    Earnie Boyd - 2011-11-30

    I confirm the patch corrects the issue I was having.

     
  • Earnie Boyd

    Earnie Boyd - 2011-11-30

    File a rekeyed by Earnie

     
  • Earnie Boyd

    Earnie Boyd - 2011-11-30

    I've attached the patch file.

     
  • Chris Sutcliffe

    Chris Sutcliffe - 2011-11-30

    I've applied your patch, thank you for the fix.

     
  • Chris Sutcliffe

    Chris Sutcliffe - 2011-11-30
    • status: open --> closed-accepted