Re: quadmath.h's expq() crashes at runtime

[email protected] Mon, 25 Nov 2013 13:00:26 +1100
Newsgroups perl.win32.vanilla
Message-ID <493CEAE358FA472681EAD68A605495AD@OwnerPC311012>
> -----Original Message----- 
> From: kmx Sent: Monday, November 25, 2013 8:41 AM To: 
> [email protected] Subject: Re: FYI: quadmath.h's expq() crashes at 
> runtime
> Hi Rob,
>
> On 5.10.2013 17:06, [email protected] wrote:
> > Hi,
> >
> > It's no big deal, but current Strawberry Perl 32-bit and 64-bit 
> > compilers create executables that crash when expq() is called.
> >
> > Here's the minimalistic demo script:
> >
> > ####################
> > #include <quadmath.h>
> >
> > int main (void) {
> >  __float128 r;
> >
> >  r = expq(2.0Q);
> >  r = sqrtq(2.0Q);
> >  r = fabsq(2.0Q);
> >  r = sinq(2.0Q);
> >  r = logq(2.0Q);
> >  r = cosq(2.0Q);
> >
> >  return 0;
> > }
> >
> > ####################
> >
> > The resultant executable crashes when run, but remove the expq() call 
> > and there's no problem. (Link to -lquadmath when building the above 
> > program.)
> >
> > It's not just MinGW64's gcc-4.6.3 compilers that are affected. I find 
> > the same with their 64-bit gcc-4.7.0, and 4.8.1 compilers. (I haven't 
> > tested any other MinGW64 compilers.)
> >
> > I've also found that mingw.org's gcc-4.7.0 does *not* suffer this 
> > problem; nor does Ubuntu's gcc-4.6.3 ... so I guess I probably should 
> > report this to the mingw64 project.
> >
> > BTW, the perl relevance here is that, because of this bug, 
> > Math::Float128 crashes its test suite when expq() gets called. But I 
> > don't think that there's a high demand for this module, so I wouldn't be 
> > too concerned about that aspect.
>
> I am afraid I cannot do much about expq crash unless there is newer 
> version of gcc and/or mingw-w64 runtime which does not suffer from this.
>

Yes - I subsequently reported the problem to the mingw64 mailing list, where 
it was confirmed as a bug in their compilers.
I don't know when/if it will be fixed. I didn't actually file a bug report 
anywhere - mainly because I don't know offhand where to file such a report, 
and no-one replied when I asked about that on the mailing list.

In the meantime, I've changed the relevant XS code so that if 
__MINGW64_VERSION_MAJOR is defined, instead of doing expq(p), it does 
powq(e,p) - and that works fine.

> >
> > Also of slight relevance to Strawberry Perl is the fact that 
> > c/lib/gcc/[whatever]-w64-mingw32/4.6.3 is not in $Config{libpth}.
> > As a consequence perl does not automatically find -lquadmath when the 
> > Math::Float128 Makefile.PL is run, and perl therefore removes the link. 
> > (The gcc linker can find -lquadmath without any help at all ... but it 
> > won't look for that library if perl has removed the link.)
>
> As for this part you mean using something like this:
>
> libpth='C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib 
> C:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3'
>
> right?

Yes - and similarly, for the 32-bit compiler, we want 
C:\strawberry\c\lib\gcc\i686-w64-mingw32\4.7.3 added to libpth. (Not sure if 
you're upgrading the compiler to "4.7.3" or whether you meant "4.6.3" ... 
I'll find out soon enough ;-)

Cheers,
Rob