[Bug 852795] Re: valgrind does not support ivybridge rdrand instruction

Alessandro Ghedini ghedo at debian.org
Tue May 15 19:32:06 UTC 2012


Here is a shorter test case:

% cat rdrand.c 
int main(void) {
	asm(".byte 0x66, 0xF, 0xC7, 0xF0, 0xBA, 0x1");

	return 0;
}

Disassembled by gdb as:

   0x00000000004004a0 <+0>:	mov    eax,0x0
   0x00000000004004a5 <+5>:	mov    DWORD PTR [rsp-0x4],0x0
   0x00000000004004ad <+13>:	rdrand ax
   0x00000000004004b1 <+17>:	mov    edx,0x9090c301

** Changed in: valgrind (Ubuntu)
       Status: New => Confirmed

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to valgrind in Ubuntu.
https://bugs.launchpad.net/bugs/852795

Title:
  valgrind does not support ivybridge rdrand instruction

Status in “valgrind” package in Ubuntu:
  Confirmed

Bug description:
  Valgrind does not support Ivybridge rdrand instructions in Oneiric but
  gcc does support it.

  #include <stdint.h>
  #include <stdio.h>
  #include <stdlib.h>

  static inline uint16_t rdrand16(void)
  {
          uint16_t val;
          int error;

          do {
                  asm("rdrand %%ax;\n\
                  mov $1,%%edx;\n\
                  cmovae %%ax,%%dx;\n\
                  mov %%edx,%1;\n\
                  mov %%ax, %0;":"=r"(val),"=r"(error)::"%ax","%dx");
          } while (error == 0);

          return val;

  }

  main(int argc, char *argv[])
  {
          printf("%d\n", (int)rdrand16());
  }

  $ gcc -O5 rdrand.c
  $ valgrind --version
  valgrind-3.6.1
  $ valgrind ./a.out 
  ==5007== Memcheck, a memory error detector
  ==5007== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
  ==5007== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
  ==5007== Command: ./a.out
  ==5007== 
  vex amd64->IR: unhandled instruction bytes: 0x66 0xF 0xC7 0xF0 0xBA 0x1
  ==5007== valgrind: Unrecognised instruction at address 0x4004fb.
  ==5007== Your program just tried to execute an instruction that Valgrind
  ==5007== did not recognise.  There are two possible reasons for this.
  ==5007== 1. Your program has a bug and erroneously jumped to a non-code
  ==5007==    location.  If you are running Memcheck and you just saw a
  ==5007==    warning about a bad jump, it's probably your program's fault.
  ==5007== 2. The instruction is legitimate but Valgrind doesn't handle it,
  ==5007==    i.e. it's Valgrind's fault.  If you think this is the case or
  ==5007==    you are not sure, please let us know and we'll try to fix it.
  ==5007== Either way, Valgrind will now raise a SIGILL signal which will
  ==5007== probably kill your program.
  ==5007== 
  ==5007== Process terminating with default action of signal 4 (SIGILL)
  ==5007==  Illegal opcode at address 0x4004FB
  ==5007==    at 0x4004FB: rdrand16 (in /home/ubuntu/a.out)
  ==5007==    by 0x400538: main (in /home/ubuntu/a.out)
  ==5007== 
  ==5007== HEAP SUMMARY:
  ==5007==     in use at exit: 0 bytes in 0 blocks
  ==5007==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
  ==5007== 
  ==5007== All heap blocks were freed -- no leaks are possible
  ==5007== 
  ==5007== For counts of detected and suppressed errors, rerun with: -v
  ==5007== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
  Illegal instruction (core dumped)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/valgrind/+bug/852795/+subscriptions




More information about the foundations-bugs mailing list