I have an annoying problem with cross-compiled binaries.
Both in Sjaak and in Leonidas I use exponential functions to initialise a number of evaluation tables. This works fine in 32 and 64 bit under Linux and under OS X, and (apparently) under Windows if compiled there natively.
However, I don't have Windows myself, so I generate Windows binaries by cross-compiling. This is fine in 32 bit, but the program crashes in 64 bit (under Windows, but not under Wine) when it calls the exponential function.
Does anyone have experience with something like this? Is there a linker option I'm missing, or a compiler flag? I have -lm to link to libm, but it actually seems not to be required anyway (confirmed by documentation as well as experimentation).
Cross compiling woes
Moderators: hgm, Dann Corbit, Harvey Williamson
-
lucasart
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: Cross compiling woes
From what you describe, it sounds like the bug is in mingw-w64. Is it possible to replicate the problem with a trivial program that just calls the exp() function?Evert wrote:I have an annoying problem with cross-compiled binaries.
Both in Sjaak and in Leonidas I use exponential functions to initialise a number of evaluation tables. This works fine in 32 and 64 bit under Linux and under OS X, and (apparently) under Windows if compiled there natively.
However, I don't have Windows myself, so I generate Windows binaries by cross-compiling. This is fine in 32 bit, but the program crashes in 64 bit (under Windows, but not under Wine) when it calls the exponential function.
Does anyone have experience with something like this? Is there a linker option I'm missing, or a compiler flag? I have -lm to link to libm, but it actually seems not to be required anyway (confirmed by documentation as well as experimentation).
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
sje
- Posts: 4675
- Joined: Mon Mar 13, 2006 7:43 pm
Re: Cross compiling woes
Try coding an explicit routine for calculating e^x using series expansion.
-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: Cross compiling woes
Worth a shot...lucasart wrote:From what you describe, it sounds like the bug is in mingw-w64. Is it possible to replicate the problem with a trivial program that just calls the exp() function?Evert wrote:I have an annoying problem with cross-compiled binaries.
Both in Sjaak and in Leonidas I use exponential functions to initialise a number of evaluation tables. This works fine in 32 and 64 bit under Linux and under OS X, and (apparently) under Windows if compiled there natively.
However, I don't have Windows myself, so I generate Windows binaries by cross-compiling. This is fine in 32 bit, but the program crashes in 64 bit (under Windows, but not under Wine) when it calls the exponential function.
Does anyone have experience with something like this? Is there a linker option I'm missing, or a compiler flag? I have -lm to link to libm, but it actually seems not to be required anyway (confirmed by documentation as well as experimentation).
I've uploaded an archive with both the crashing Sjaak (it crashes after receiving a "new" command) and the following test program
Code: Select all
#include <stdio.h>
#include <math.h>
int main(void)
{
double x, y;
y = 0;
for (x = -1.; x< 2.; x+=0.1)
y += exp(x);
printf("%g\n", y);
return 0;
}
Perhaps someone with Windows could give this a try?
Note that google seems to be completely silent on anything like this issue...
Last edited by Evert on Sun Feb 17, 2013 7:35 am, edited 1 time in total.
-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: Cross compiling woes
I've considered that, but it seems so silly to write a replacement for a standard library function because a cross compiler for one particular platform seems to generate buggy code when you call that function...
-
lucasart
- Posts: 3232
- Joined: Mon May 31, 2010 1:29 pm
- Full name: lucasart
Re: Cross compiling woes
But why do you need exp() in your programs ? Is there no way to do without it, and avoid the problem ?Evert wrote:I've considered that, but it seems so silly to write a replacement for a standard library function because a cross compiler for one particular platform seems to generate buggy code when you call that function...
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
-
sje
- Posts: 4675
- Joined: Mon Mar 13, 2006 7:43 pm
Re: Cross compiling woes
Just use the standard power series for e^x. It is probably the simplest of all math library functions.Evert wrote:I've considered that, but it seems so silly to write a replacement for a standard library function because a cross compiler for one particular platform seems to generate buggy code when you call that function...
e^x = 1 + x + x^2/2! + x^3/3! + ...
-
Alexander Schmidt
- Posts: 1181
- Joined: Thu May 10, 2007 2:49 pm
Re: Cross compiling woes
Both crash here.Evert wrote:Perhaps someone with Windows could give this a try?
Note that google seems to be completely silent on anything like this issue...
Alex
-
smrf
- Posts: 484
- Joined: Mon Mar 13, 2006 11:08 am
- Location: Klein-Gerau, Germany
Re: Cross compiling woes
To calculate y := exp(x) you also could use a continuous fraction:
first calculate z := x/(-2 + x²/(-6 + x²/(-10 + x²/(-14 + ... ... )))
then you will get y := (1 - z) / (1 + z) using higher precision.
first calculate z := x/(-2 + x²/(-6 + x²/(-10 + x²/(-14 + ... ... )))
then you will get y := (1 - z) / (1 + z) using higher precision.
-
Evert
- Posts: 2929
- Joined: Sat Jan 22, 2011 12:42 am
- Location: NL
Re: Cross compiling woes
It's used for the initialisation of tables used in progressive evaluation.lucasart wrote: But why do you need exp() in your programs ? Is there no way to do without it, and avoid the problem ?
For instance, the king-safety evaluation uses a Fermi-Dirac distribution for the shape, so the value is small if risk is low and rises (steeply) above a certain threshold and then saturates. The slope, inflection point and saturation value are all adjustable parameters that can be tuned.
Sure, I could do something different, and it may not even be worse. I like this approach though because it's straightforward and natural for me. And, it works properly, except apparently under cross-compiled Windows executables. I'd prefer to fix the problem rather than work around it...
For Jazz and Leonidas I can do the tuning under Linux and simply hard-code the results for the Windows version, but for Sjaak I can't because the pieces that are used in the game are defined at run time.