You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gentoo环境下运行Valgrind检测内存泄漏失败求助

Valgrind运行失败:无法识别指令的故障原因分析

我在Gentoo系统上尝试用Valgrind检测基于C++11标准构建的程序的内存泄漏,执行命令valgrind --leak-check=full dbhandler时失败,报错信息如下:

igor@WaylandGnome ~/dbhandler/Debug/dbhandler $ valgrind --leak-check=full dbhandler
==32622== Memcheck, a memory error detector
==32622== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==32622== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==32622== Command: dbhandler
==32622== 
vex amd64->IR: unhandled instruction bytes: 0x8F 0xEA 0x78 0x10 0xD0 0x8 0x4 0x0 0x0 0x89
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
==32622== valgrind: Unrecognised instruction at address 0x40197cf.
==32622==    at 0x40197CF: get_common_indices.constprop.0 (in /lib64/ld-2.33.so)
==32622==    by 0x401ACB6: init_cpu_features.constprop.0 (in /lib64/ld-2.33.so)
==32622==    by 0x401BE1D: _dl_sysdep_start (in /lib64/ld-2.33.so)
==32622==    by 0x4001FDB: _dl_start (in /lib64/ld-2.33.so)
==32622==    by 0x4001057: ??? (in /lib64/ld-2.33.so)
==32622== Your program just tried to execute an instruction that Valgrind
==32622== did not recognise.  There are two possible reasons for this.
==32622== 1. Your program has a bug and erroneously jumped to a non-code
==32622==    location.  If you are running Memcheck and you just saw a
==32622==    warning about a bad jump, it's probably your program's fault.
==32622== 2. The instruction is legitimate but Valgrind doesn't handle it,
==32622==    i.e. it's Valgrind's fault.  If you think this is the case or
==32622==    you are not sure, please let us know and we'll try to fix it.
==32622== Either way, Valgrind will now raise a SIGILL signal which will
==32622== probably kill your program.
==32622== 
==32622== Process terminating with default action of signal 4 (SIGILL)
==32622==  Illegal opcode at address 0x40197CF
==32622==    at 0x40197CF: get_common_indices.constprop.0 (in /lib64/ld-2.33.so)
==32622==    by 0x401ACB6: init_cpu_features.constprop.0 (in /lib64/ld-2.33.so)
==32622==    by 0x401BE1D: _dl_sysdep_start (in /lib64/ld-2.33.so)
==32622==    by 0x4001FDB: _dl_start (in /lib64/ld-2.33.so)
==32622==    by 0x4001057: ??? (in /lib64/ld-2.33.so)
==32622== 
==32622== HEAP SUMMARY:
==32622==     in use at exit: 0 bytes in 0 blocks
==32622==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==32622== 
==32622== All heap blocks were freed -- no leaks are possible
==32622== 
==32622== For lists of detected and suppressed errors, rerun with: -s
==32622== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction

故障原因

  • Valgrind版本兼容问题:你使用的Valgrind 3.18.1版本过旧,无法识别系统glibc动态链接器(ld-2.33.so)中使用的新CPU指令。
  • CPU特性检测冲突:glibc的init_cpu_features函数在初始化时会执行CPU特性检测指令,这些指令是合法的,但旧版本Valgrind的LibVEX组件没有实现对它们的支持,因此触发了SIGILL非法指令错误。
  • Gentoo系统优化特性:Gentoo默认会启用针对当前CPU的优化编译选项,glibc编译时可能使用了Valgrind 3.18.1不支持的指令集扩展,加剧了版本不兼容问题。

解决办法

  • 升级Valgrind:在Gentoo中执行emerge --ask dev-util/valgrind升级到最新稳定版本(如3.20及以上),新版本会支持更多新指令,解决兼容性问题。
  • 临时规避方案:如果暂时无法升级,可以尝试添加--vex-iropt=join_loads=0参数运行Valgrind,不过这种方法不一定能完全解决所有指令兼容问题,升级版本是更可靠的选择。

内容的提问来源于stack exchange,提问作者Igor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 05:20:43