Date: Tue, 12 Feb 2008 18:23:18 +0000 From: Tom Evans <tevans.uk@googlemail.com> To: freebsd-stable@freebsd.org Subject: Formatting bug in C++ iostreams when running i386 binary on amd64 Message-ID: <1202840599.2126.86.camel@localhost>
next in thread | raw e-mail | index | archive | help
--=-dbHEw7bGWLF00gCgPFzP Content-Type: multipart/mixed; boundary="=-NYmYATEVp0oDSWkVFF8f" --=-NYmYATEVp0oDSWkVFF8f Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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 root@bob.mintel.co.uk:/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 root@roley.mintel.co.uk:/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=20 -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=20 -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 =20 -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 --=-NYmYATEVp0oDSWkVFF8f-- --=-dbHEw7bGWLF00gCgPFzP Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQBHseQOlcRvFfyds/cRAjVAAJ4wjMZ0OFNwFSNVOcIT95G4vjjHWgCbBvpa 9J3n275mft9Y22zMjG3mQ8Q= =TQ5U -----END PGP SIGNATURE----- --=-dbHEw7bGWLF00gCgPFzP--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1202840599.2126.86.camel>