Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 552464 - C++ program outputs floats to stdout as 11.111 through valgrind
Summary: C++ program outputs floats to stdout as 11.111 through valgrind
Status: RESOLVED CANTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Anthony Basile
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-18 13:34 UTC by corto
Modified: 2016-02-12 01:53 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
valgrind_float_test.cpp (valgrind_float_test.cpp,509 bytes, text/plain)
2015-06-18 13:37 UTC, corto
Details
emerge --info (on affected computer) (emerge_info.txt,5.19 KB, text/plain)
2015-06-18 13:39 UTC, corto
Details
emerge --info (on *unaffected* 32 bit computer) (emerge_info_32bit.txt,5.11 KB, text/plain)
2015-06-18 13:42 UTC, corto
Details
emerge --info on a similar system (emerge-info.txt,4.95 KB, text/plain)
2015-06-21 10:19 UTC, Anthony Basile
Details
cpuinfo from affected system (running as vbox guest) (cpuinfo.64bit-vbox-guest.txt,4.99 KB, text/plain)
2015-06-21 11:46 UTC, corto
Details
kernel .config (gentoo-sources 3.14.14) (gentoosrc-3.14.14.64bit.config.txt,97.21 KB, text/plain)
2015-06-21 11:47 UTC, corto
Details

Note You need to log in before you can comment on or make changes to this bug.
Description corto 2015-06-18 13:34:49 UTC
A basic c++ program that simply outputs the number 123.456 to stdout, will show 111.111 when run through valgrind (see valgrind_float_test.cpp for clear example).

The issue happens on a 64bit system with these versions:
sys-libs/glibc-2.20-r2
dev-util/valgrind-3.10.1
sys-devel/gcc-4.8.4
or sys-devel/gcc-4.9.0

Another system with identical versions of these packages but 32bit did NOT have the bug.

The program was compiled with these options:-O0 -g3 -fpic -std=c++1y 
Compiling the C++ program with -O0 or -O3 didn't change anything.



Reproducible: Always

Steps to Reproduce:
1. Compile attached program "valgrind_float_test.cpp" using:
   g++ -x c++ -O0 -g3 -fpic -std=c++1y -c ./valgrind_float_test.cpp

2. Link using:
   g++ -lstdc++ -o "./valgrind_float_test.elf" ./valgrind_float_test.o

3. Execute program normally:
   ./valgrind_float_test.elf

4. Check the output corresponds to this:
   0 4.7 9.4 14.1 18.8 23.5 28.2 32.9 37.6 42.3 47 51.7 56.4 61.1 65.8 70.5 75.2 79.9 84.6 89.3 94 98.7

5. Execute the program through valgrind using:
   valgrind -q ./valgrind_float_test.elf

6. Check the output corresponds to this (or to something different from above):
   0 4.7 9.4 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111
Actual Results:  
The output of the program when run through valgrind gives:
0 4.7 9.4 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111

Expected Results:  
The output of the program is expected to be this, with and without valgrind:
0 4.7 9.4 14.1 18.8 23.5 28.2 32.9 37.6 42.3 47 51.7 56.4 61.1 65.8 70.5 75.2 79.9 84.6 89.3 94 98.7
Comment 1 corto 2015-06-18 13:37:02 UTC
Created attachment 405326 [details]
valgrind_float_test.cpp

Simple C++ program that shows the bug in action.
Comment 2 corto 2015-06-18 13:39:32 UTC
Created attachment 405328 [details]
emerge --info (on affected computer)

Ouput from `emerge --info` on the computer where the bug is present.
Comment 3 corto 2015-06-18 13:42:04 UTC
Created attachment 405332 [details]
emerge --info (on *unaffected* 32 bit computer)

Output from `emerge --info` on the 32bit computer referred from the description.  The bug is not present on that computer.
Comment 4 corto 2015-06-18 13:45:38 UTC
An even simpler test case program is this one:

#include <iostream>

int main(int argc, char* argv[]){

  std::cout << 3.14159 << std::endl
	    << 314.159 << std::endl;

  return 0;
}

----------------

When run normally, this program outputs:
3.14159
314.159

When run through valgrind, it outputs:
3.14159
111.111
Comment 5 Mike Gilbert gentoo-dev 2015-06-20 22:30:36 UTC
So is this a toolchain issue, or a valgrind issue? Who do I assign this bug to?
Comment 6 corto 2015-06-20 22:42:10 UTC
I can't decide myself given that I'm not sure where the problem comes from.  I only witnessed problems when using valgrind and I only use it to diagnose my own programs.
Comment 7 Anthony Basile gentoo-dev 2015-06-21 10:19:11 UTC
Created attachment 405472 [details]
emerge --info on a similar system

I'm not able to reproduce this on a similar, so I'm not sure what's going on here.  Here's what I'm getting:

amd64-hardened-gdb ~ # valgrind -q ./valgrind_float_test.elf
0 4.7 9.4 14.1 18.8 23.5 28.2 32.9 37.6 42.3 47 51.7 56.4 61.1 65.8 70.5 75.2 79.9 84.6 89.3 94 98.7 


valgrind is very fragile.  There are difference between our systems but I'm reluctant to start guessing.  The one big difference is that my system is hardened, but a hardened toolchains usually causes, not "fixes", issues like this
Comment 8 Anthony Basile gentoo-dev 2015-06-21 10:25:19 UTC
(In reply to Anthony Basile from comment #7)
> 
> valgrind is very fragile.  There are difference between our systems but I'm
> reluctant to start guessing.  The one big difference is that my system is
> hardened, but a hardened toolchains usually causes, not "fixes", issues like
> this

I just noticed that you are using the hardened profile, but not a hardened kernel but something else.

Can you explain how your system is different that a typical hardened system (whatever that might mean).  Also can you give me your cpu flags `cat /proc/cpuinfo`
Comment 9 corto 2015-06-21 11:45:21 UTC
I wasn't aware the kernel had any influence in this matter.  There sure are many difference here.  I'll describe them and try to reduce the differences later.

Firstly, this machine runs within VirtualBox. The additions (kernel modules) have been compiled from those shipped with the executable.  The host runs windows 8.1.   I'll try to run it natively, this will take a lot of time.

Secondly, the kernel I use is gentoo-sources 3.14.14.  I haven't updated or recompiled it in a while for no special reason.  I'll try to update it to something stable and more recent.

I'll start by removing vbox from the equation, but this may take a day or two, so let me know if you have different priorities in mind.
Comment 10 corto 2015-06-21 11:46:04 UTC
Created attachment 405476 [details]
cpuinfo from affected system (running as vbox guest)
Comment 11 corto 2015-06-21 11:47:21 UTC
Created attachment 405478 [details]
kernel .config (gentoo-sources 3.14.14)
Comment 12 corto 2015-06-21 15:07:58 UTC
valgrind works as expected when running with this system natively (without vbox).

It is not practical to use this system without vbox, so I'd be interested to hear suggestions.

Thanks!
Comment 13 Anthony Basile gentoo-dev 2015-07-04 19:24:30 UTC
(In reply to corto from comment #12)
> valgrind works as expected when running with this system natively (without
> vbox).
> 
> It is not practical to use this system without vbox, so I'd be interested to
> hear suggestions.
> 
> Thanks!

Sorry no ideas here and I can't reproduce.  Can you push this upstream.
Comment 14 Anthony Basile gentoo-dev 2016-02-12 01:53:25 UTC
This is a corner case bug which I can't really fix.  If you want, push it upstream.  I'm closing this bug report as cantfix.