Unrecognised Instruction when using Valgrind

I’m trying to get a look at my programs memory usage using valgrind’s ‘massif’ tool. I built my program in ReleaseFast mode.

$ valgrind --tool=massif ./zig-out/bin/trie
==25613== Massif, a heap profiler
==25613== Copyright (C) 2003-2024, and GNU GPL'd, by Nicholas Nethercote et al.
==25613== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==25613== Command: ./zig-out/bin/trie
==25613==
vex amd64->IR: unhandled instruction bytes: 0x62 0xF2 0x7D 0x28 0x7A 0xC6 0x4E 0x8D 0x4 0x8
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=NONE
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==25613== valgrind: Unrecognised instruction at address 0x1036f71.
==25613==    at 0x1036F71: memset (memset.zig:21)
==25613==    by 0x100A5B5: prepareArea (tls.zig:462)
==25613==    by 0x100A5B5: initStatic (tls.zig:528)
==25613==    by 0x100A5B5: start.posixCallMainAndExit (start.zig:547)
==25613==    by 0x100A20D: (below main) (start.zig:271)
==25613== Your program just tried to execute an instruction that Valgrind
==25613== did not recognise.  There are two possible reasons for this.
==25613== 1. Your program has a bug and erroneously jumped to a non-code
==25613==    location.  If you are running Memcheck and you just saw a
==25613==    warning about a bad jump, it's probably your program's fault.
==25613== 2. The instruction is legitimate but Valgrind doesn't handle it,
==25613==    i.e. it's Valgrind's fault.  If you think this is the case or
==25613==    you are not sure, please let us know and we'll try to fix it.
==25613== Either way, Valgrind will now raise a SIGILL signal which will
==25613== probably kill your program.
==25613==
==25613== Process terminating with default action of signal 4 (SIGILL): dumping core
==25613==  Illegal opcode at address 0x1036F71
==25613==    at 0x1036F71: memset (memset.zig:21)
==25613==    by 0x100A5B5: prepareArea (tls.zig:462)
==25613==    by 0x100A5B5: initStatic (tls.zig:528)
==25613==    by 0x100A5B5: start.posixCallMainAndExit (start.zig:547)
==25613==    by 0x100A20D: (below main) (start.zig:271)
==25613==
Illegal instruction (core dumped)

Can anyone tell why this is happening and/or how to get it working?

==25613== Your program just tried to execute an instruction that Valgrind
==25613== did not recognise.  There are two possible reasons for this.
==25613== 2. The instruction is legitimate but Valgrind doesn't handle it,
==25613==    i.e. it's Valgrind's fault.  If you think this is the case or
==25613==    you are not sure, please let us know and we'll try to fix it.

Valgrind doesn’t implement support for your fancy new CPU yet.

In the meantime, you can work around it by asking Zig to target an older CPU profile, for example -target x86_64-linux -mcpu=x86_64_v3.

4 Likes

Well at least there’s a silver lining. :sweat_smile:

Building with those flags gets rid of that error, but now I get

--31135:0: aspacem Valgrind: FATAL: VG_N_SEGMENTS is too low.
--31135:0: aspacem   Increase it and rebuild.  Exiting now.

Looks like I have to build my own Valgrind. Maybe it’s time for bed…

never seen that one before :eyes:

Possibly has to do with my program using 570MiB of memory :).