Valgrind は、CPUID オペコード命令によって返される値を変更しています。簡単に言えば、どうすれば Valgrind に実際の CPUID 命令を尊重させることができますか?
参考までに、これは、aes-ni 命令セットを持たないことがわかっている古いコンピューターで aes-ni サポートを検出したときに奇妙なエラーが発生したときに発見されました。ただし、この動作は明らかに複数の値を変更しています。
valgrind-3.10.1
この動作は、次の C コードを使用して観察できます。
#include <stdio.h>
int main() {
unsigned eax, ebx, ecx, edx;
eax = 1;
__asm__ volatile("cpuid"
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
: "0" (eax), "2" (ecx)
);
if(ecx & (1<<25)) {
printf("aes-ni enabled (ecx=%08x)n", ecx);
} else {
printf("no aes-ni support (ecx=%08x)\n", ecx);
}
return 1;
}
そのようにコンパイルして実行します:
$ gcc -o test test.c
$ ./test
no aes-ni support (ecx=0098e3fd)
$ valgrind ./test
==25361== Memcheck, a memory error detector
==25361== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==25361== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==25361== Command: ./test
==25361==
aes-ni enabled (ecx=0298e3ff)
==25361==
==25361== HEAP SUMMARY:
==25361== in use at exit: 0 bytes in 0 blocks
==25361== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==25361==
==25361== All heap blocks were freed -- no leaks are possible
==25361==
==25361== For counts of detected and suppressed errors, rerun with: -v
==25361== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
同じバイナリは通常0098e3fdを返しますが、valgrind では0298e3ffを返すことに注意してください。これは間違っています!