Hi list.

I've encountered a strange bug deploying one of our C++ applications on
amd64. We tend to build most of our applications on i386, even if the
deployment box is amd64, as we aren't 100% sure that our code is 64 bit
clean yet. The boxes in question both run 6.2-RELEASE, at various kernel
release patchsets:

FreeBSD dellboy.mintel.co.uk 6.2-RELEASE-p8 FreeBSD 6.2-RELEASE-p8 #0:
Wed Dec 12 16:58:42 GMT 2007
[EMAIL PROTECTED]:/usr/obj/usr/src/sys/PE2650  i386

FreeBSD animal.mintel.co.uk 6.2-RELEASE-p5 FreeBSD 6.2-RELEASE-p5 #35:
Fri Jul 20 10:20:28 BST 2007
[EMAIL PROTECTED]:/usr/obj/usr/src/sys/PE2950  amd64

With an i386 binary running on an amd64 host, when we write a small
double, with value close to 0.1, to a C++ iostream, it is formatted
incorrectly. I have derived a small test case, which generates the
spurious value on the 18th iteration.

Compiled on i386:
> $ g++ -o doubletest -Wall doubletest.cc

Run on i386:

> $ ./doubletest
-0.9    0       0.09    0.099   0.0999
0.09999 0.099999        0.0999999       0.1     0.1
0.1     0.1     0.1     0.1     0.1
0.1     0.1     0.1     0.1     0.1
                ^^^
Run on amd64:

> $ ./doubletest 
-0.9    0       0.09    0.099   0.0999
0.09999 0.099999        0.0999999       0.1     0.1
0.1     0.1     0.1     0.1     0.1
0.1     0.1     0.0:    0.1     0.1
                ^^^^

If we compile with slightly different linkage (and run again on amd64):

> $ g++ -Wl,-Bstatic -o doubletest -Wall doubletest.cc -Wl,dy
> $ ./doubletest-halfstatic 
-0.9    0       0.09    0.099   0.0999
0.09999 0.099999        0.0999999       0.1     0.1
0.1     0.1     0.1     0.1     0.1
0.1     0.1     0.0:    0.1     0.1
                ^^^^
> $ g++ -static -o doubletest -Wall doubletest.cc
> $ ./doubletest-static     
-0.9    0       0.09    0.099   0.0999
0.09999 0.099999        0.0999999       0.1     0.1
0.1     0.1     0.1     0.1     0.1
0.1     0.1     0.1     0.1     0.1
                ^^^

This obviously produces unexpected results! Does anyone have any idea
what may be triggering this?

We currently have two workarounds, one is to compile completely
statically (add -static to the compile command line), and compile the
app natively 64bit. The former cannot be used on any application that
dlopen()s any libraries, and we're not confident with the latter!

Tom

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to