Bug 498494 - illegal instructions with none/tests/amd64/rdseed and rdrand on FreeBSD
Summary: illegal instructions with none/tests/amd64/rdseed and rdrand on FreeBSD
Status: RESOLVED NOT A BUG
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: FreeBSD Ports FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-10 19:19 UTC by Paul Floyd
Modified: 2025-01-11 08:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Floyd 2025-01-10 19:19:35 UTC
Both run OK outside of Valgrind.

rdseed gives me

paulf@freebsd:~/valgrind $ ./vg-in-place ./none/tests/amd64/rdseed
==78559== Memcheck, a memory error detector
==78559== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==78559== Using Valgrind-3.25.0.GIT and LibVEX; rerun with -h for copyright info
==78559== Command: ./none/tests/amd64/rdseed
==78559==
vex amd64->IR: unhandled instruction bytes: 0x49 0xF 0xC7 0xFB 0x41 0xF 0x92 0xC4 0x4C 0x89
vex amd64->IR:   REX=1 REX.W=1 REX.R=0 REX.X=0 REX.B=1
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

That's this

  2017c7: 49 0f c7 fb                   rdseedq %r11

and rdrand

paulf@freebsd:~/valgrind $ ./vg-in-place ./none/tests/amd64/rdrand
==78572== Memcheck, a memory error detector
==78572== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==78572== Using Valgrind-3.25.0.GIT and LibVEX; rerun with -h for copyright info
==78572== Command: ./none/tests/amd64/rdrand
==78572==
vex amd64->IR: unhandled instruction bytes: 0x49 0xF 0xC7 0xF3 0x41 0xF 0x92 0xC4 0x4C 0x89
vex amd64->IR:   REX=1 REX.W=1 REX.R=0 REX.X=0 REX.B=1
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

That's

  2017c7: 49 0f c7 f3                   rdrandq %r11

My guess is that clang is emitting a slight variation of the opcode which VEX doesn't decode.
Comment 1 Paul Floyd 2025-01-10 20:03:17 UTC
Linux / GCC generates the same opcode. So this is more likely to be related to something like 
Bool VG_(machine_get_hwcaps)( void )
Comment 2 Paul Floyd 2025-01-11 07:06:09 UTC
This was on a VirtualBox instance. I hadn't realized just how bad the VB virtualization is on a modern amd64 PC.

CPU flags in VB
Flags:                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 cflsh mmx fxsr sse sse2 htt sse3 pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes rdrnd syscall nx mmxext fxsr_opt rdtscp lm lahf_lm cmp_legacy cr8_legacy lzcnt sse4a misalignsse 3dnowprefetch

And natively
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmuldq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw wdt topoext perfctr_core mwaitx cpb hw_pstate ssbd ibpb ibrs stibp fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves user_shstk avx_vnni avx512_bf16 clzero xsaveerptr rdpru wbnoinvd cppc overflow_recov succor smca sme

That's less than half.

In gdb I see that CPUID is not setting either rdrand or rdseed. If I set them in gdb then at least rdseed runs OK.
Comment 3 Paul Floyd 2025-01-11 08:01:17 UTC
Closing this as it looks like a VB limitation.