2011/11/2 Simson Garfinkel <[email protected]>:
> All,
>
> I have a program that I cross-compile for deployment on 32-bit and 64-bit
> windows.
>
> The problem that we are seeing is that the exact same code is crashing when
> compiled for 64-bit with mingw64 but not crashing when compiled for
> 32-bit with mingw32.
>
> Here is a sample of a crash from within GDB:
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 3008.0x1294]
> 0x00000000004c796c in PrefetchDecoder::microsoftDateToISODate (
>     time=@0x37eecf0) at scan_winprefetch.cpp:122
>
>
> And here is the function in question; the crash is in the call to
> gmtime_r():
>
>     static string microsoftDateToISODate(const uint64_t &time) {
>         /**
>
>          * See comment above for more information on
>
>          * SECONDS_BETWEEN_WIN32_EPOCH_AND_UNIX_EPOCH
>
>          *
>
>          * Convert UNIX time_t to ISO8601 format
>
>          */
>         time_t tmp = (time / ONE_HUNDRED_NANO_SEC_TO_SECONDS)
>             - SECONDS_BETWEEN_WIN32_EPOCH_AND_UNIX_EPOCH;
>
>         struct tm time_tm;
>         gmtime_r(&tmp, &time_tm);         /* CRASH HAPPENED HERE; line 122
> */
>         char buf[256];
>         strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &time_tm);
>         return string(buf);
>     }
>
>
> As you can see, there is no way that this should be able to cause a crash.
> My question --- do we know that the 64-bit compiler is producing code of the
> same quality as the 32-bit compiler?

Hi,

you are running here into the issue that time_t is for 32-bit an
32-bit integer scalar, and for 64-bit windows a 64-bit integer-scalar.
 The  scalar variant is the number of seconds elapsed since midnight
on January 1, 1970.

I tried to reproduce this on 64-bit Windows with current trunk version
of crt and headers, and I don't get a crash here.  So I have two
questions here:

First, what compiler version you are using?
Second, what mingw-w64 runtime-version you are using?

the gtime_r gets defined only if _POSIX was defined.  So check if
gmtime_r is defined as

#ifndef gmtime_r
#define gmtime_r(_Time,_Tm)     ({ struct tm *___tmp_tm =               \
                                                gmtime((_Time));        \
                                                if (___tmp_tm) {        \
                                                  *(_Tm) = *___tmp_tm;  \
                                                  ___tmp_tm = (_Tm);    \
                                                }                       \
                                                ___tmp_tm;      })
#endif

in your time.h.

Regards,
Kai

Regards,
Kai
_______________________________________________
mingw mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/mingw

Reply via email to