Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valgrind Unrecognised instruction

I have the following code:

#include <iostream> #include <random>  int main() {     std::mt19937_64 rng(std::random_device{}());     std::cout << std::uniform_int_distribution<>(0, 100)(rng) << '\n'; } 

I try to profile it using valgrind, but it says:

vex amd64->IR: unhandled instruction bytes: 0xF 0xC7 0xF0 0x89 0x6 0xF 0x42 0xC1 vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0 vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0 ==2092== valgrind: Unrecognised instruction at address 0x4cdc1b5.   ==2092== at 0x4CDC1B5:std::(anonymous namespace)::__x86_rdrand() (random.cc:69)   ==2092== by 0x4CDC321: std::random_device::_M_getval() (random.cc:130)   ==2092== by 0x4009D4: main (random.h:1619)   

Preceded by multiple instances of:

--2092-- WARNING: Serious error when reading debug info   --2092-- When reading debug info from /lib/x86_64-linux-gnu/ld-2.22.so:   --2092-- Ignoring non-Dwarf2/3/4 block in .debug_info   

I am on Debian using standard packages on an x86-64 platform compiling with gcc 5.3.1 using valgrind-3.11.0. The illegal instruction seems to be inside libstdc++6.

How do I get valgrind to profile my code?

like image 856
nwp Avatar asked May 04 '16 15:05

nwp


1 Answers

In fact, Valgrind emulate your program with an intermediate language (VEX) to know if it discovers memory violation.

This VEX language capture all the instructions of several assemblers such as i386, amd64, arm, ... But, from time to time, it miss a few instructions (especially specialized ones like rdrand which is linked to the AES specific instructions set).

Well, this is exactly what happened with your program. Valgrind did probably stumbled on an unknown instruction and could not translate it into the VEX intermediate language.

But, you are not the only one to be in line waiting for a fix:

  • Same issue on Launchpad.
  • Same issue on KDE bugtracker.
  • ... and so on ...

Here is a patch that has been applied to Valgrind and that may solve the problem for you (depending on your CPU).

But, the only thing you can do is to install a newer version of Valgrind and hope that the instruction is supported in the newest version.

like image 77
perror Avatar answered Sep 23 '22 09:09

perror