Bug 183409

Summary: Valgrind does not support instructions sgdtq (x86_64) and sgdtl (x86)
Product: [Developer tools] valgrind Reporter: Konstantin Serebryany <konstantin.s.serebryany>
Component: vexAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: crash CC: konstantin.s.serebryany, njn, tom
Priority: NOR    
Version: 3.4 SVN   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Bug Depends on:    
Bug Blocks: 256630    

Description Konstantin Serebryany 2009-02-06 11:38:24 UTC
The following code will fail under valgrind like this: 
vex x86->IR: unhandled instruction bytes: 0xF 0x1 0x45 0xDE


#include <iostream>
#include <pthread.h>
// Compile and run:
// g++ -m64 sgdtq.cc -lpthread && valgrind  ./a.out
void *sgdtq(void *) {
 char ret_val[16] __attribute__((__aligned__(16)));
 // valgrind will fail here:
 __asm__ __volatile__("sgdtq %0" : "=m" (ret_val[6])::"memory");
 uint64_t id =  *reinterpret_cast<uint64_t *>(&ret_val[8]);
 std::cout << id << std::endl;
}

int main() {
 const int N = 100;
 pthread_t t[N];
 sgdtq(NULL);
 // start many threads. On a multi-cpu machine
 // this progam should print several different numbers.
 for (int i = 0; i < N; i++) {
   pthread_create(&t[i], 0, sgdtq, 0);
 }
 for (int i = 0; i < N; i++) {
   pthread_join(t[i], 0);
 }
}
Comment 1 Tom Hughes 2011-08-11 13:48:31 UTC
I'm a bit confused - the error you quote is "vex x86->IR" which suggests you are running 32 bit code but the test program says to compile as 64 bit, and indeed it won't compile as 32 bit because gcc says that the "sgdt" instruction is not recognised.
Comment 2 Tom Hughes 2011-08-11 13:51:15 UTC
Well it compiles and runs OK as 64 bit anyway, and as 32 bit after the q suffix is dropped from that instruction.

Looks like VEX r1982 fixed it.