Valgrind在使用helgrind(未定义的符号)时失败

时间:2017-11-28 22:51:00

标签: valgrind

创建最基本的程序:

int main(){ return 1; }

编译:

g++ -std=c++17 test.c -o test.out

试图运行helgrind:

valgrind --tool=helgrind ./test.out

==5269== Helgrind, a thread error detector
==5269== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al.
==5269== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==5269== Command: ./test.out
==5269==
./test.out: symbol lookup error: /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so: undefined symbol: pthread_mutexattr_gettype
==5269==
==5269== For counts of detected and suppressed errors, rerun with: -v
==5269== Use --history-level=approx or =none to gain increased speed, at
==5269== the cost of reduced accuracy of conflicting-access information
==5269== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

我的系统:

Completely updated to the latest version. 

Linux station 4.10.13-1-ARCH #1 SMP PREEMPT Thu Apr 27 12:15:09 CEST 2017 x86_64 GNU/Linux

local/glibc 2.26-6 (base)
    GNU C Library

local/valgrind 3.13.0-3
    A tool to help find memory-management problems in programs

ldd valgrind
        linux-vdso.so.1 (0x00007ffd577c5000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f538e16b000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000055f1d6602000)

为什么呢?你能重现这种行为吗?

修改 我尝试了另一个版本的vagrant,但速度很快(因为我有很多程序/库,取决于libc-2.26)。我安装了valgrind 3.12.0(删除了所需的libc-2.26 dep),并将libc-2.25复制到/ usr / lib。现在,它运行valgrind --tool=helgrind ls没有该错误,但另一个二进制文件(我想与valgrind一起使用的真正程序)失败并出现同样的错误:

valgrind --tool=helgrind ./build/openclprog

==31334== Helgrind, a thread error detector
==31334== Copyright (C) 2007-2015, and GNU GPL'd, by OpenWorks LLP et al.
==31334== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright
info
==31334== Command: ./build/openclprog
==31334== Selected platform: Intel(R) OpenCL sel_device changed to: 0
(to fit number of devices) Selected device: Intel(R) Core(TM) i5-2300
CPU @ 2.80GHz ./build/openclprog : symbol lookup error:
/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so: undefined symbol:
pthread_mutexattr_gettype
==31334==
==31334== For counts of detected and suppressed errors, rerun with: -v
==31334== Use --history-level=approx or =none to gain increased speed,
at ==31334== the cost of reduced accuracy of conflicting-access information
==31334== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

ls和openclprog之间ldd的差异:

的/ usr /斌/ LS:

linux-vdso.so.1 (0x00007ffd9f936000)
libcap.so.2 => /usr/lib/libcap.so.2 (0x00007ff40d2a3000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007ff40ceeb000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ff40d6d3000)

openclprog:

linux-vdso.so.1 (0x00007ffc78bde000)
libOpenCL.so.1 => /usr/lib/libOpenCL.so.1 (0x00007fc5e5173000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fc5e4deb000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007fc5e4a9b000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fc5e4883000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fc5e44cb000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fc5e42c3000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2
(0x00007fc5e55bb000)

我尝试在C ++ 11和C ++ 17中构建openclprog,并且在两种情况下都失败了。

另外,我尝试了另一台具有不同CPU和GPU的计算机(但是 仍然AMD)并给出相同的错误(valgrind 3.12.0)。

1 个答案:

答案 0 :(得分:0)

应该发生什么

  • Valgrind设置LD_PRELOAD以加载helgrind vgpreload
  • 然后将替换系统malloc和pthread函数
  • 之类的东西

根据strace(运行strace -o vg.log ./tools/valgrind/bin/valgrind --tool=helgrind ./test.out然后过滤open调用),libpthread不会被打开。

ldd说vgpreload没有链接到任何其他共享库

ldd /home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so
        statically linked

nm表示在vgpreload中未定义pthread_mutexattr_gettype

nm
/home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so | grep pthread_mutexattr_gettype
                 U pthread_mutexattr_gettype

好的,所以符号未定义但在我的系统上加载正常。

我只是用LD_PRELOAD做了一些讨论,更多的谷歌搜索和阅读ld.so手册页。根据此联机帮助页,函数在引用之前不会得到解决。如果我运行

,我可以在valgrind之外重现加载错误
LD_BIND_NOW=1 LD_PRELOAD=/home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so /home/paulf/test.out
/home/paulf/test.out: symbol lookup error: /home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so: undefined symbol: pthread_mutexattr_gettype

所以,最后,你能否检查一下你没有设置“LD_”环境变量,特别是LD_BIND_NOW。