创建最基本的程序:
int main(){ return 1; }汇编:
g++ -std=c++17 test.c -o test.out试着跑到地狱:
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)为什么?你能复制这种行为吗?
编辑:-我尝试了另一个版本的迷航器,但以一种快速的方式(因为我有许多程序/库依赖于libc-2.26)。我安装了val差3.12.0(删除所需的libc-2.26dep),并将libc-2.25复制到/usr/lib。现在,它运行valgrind --tool=helgrind ls时没有出现该错误,但是另一个二进制程序(我想使用的真正的程序)在相同的错误中失败了:
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/bin/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)开瓶器:
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),并给出相同的错误(val差3.12.0)。
发布于 2017-11-29 21:06:47
应该发生的是
根据strace (运行strace -o vg.log ./tools/valgrind/bin/valgrind --tool=helgrind ./test.out然后对open调用进行过滤),libp线程不会被打开。
ldd表示vgpreload不链接到任何其他共享库。
ldd /home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so
statically linkednm说pthread_mutexattr_gettype在vgpreload中没有定义。
nm
/home/paulf/tools/valgrind/lib/valgrind/vgpreload_helgrind-amd64-linux.so | grep pthread_mutexattr_gettype
U pthread_mutexattr_gettype好的,所以符号是未定义的,但是它在我的系统上加载OK。
我只是在LD_PRELOAD上做了一下,更多地搜索和阅读了ld.so手册页面。根据这个手册,函数在被引用之前是不会被解析的。如果我运行,我可以在val差外再现负载错误。
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。
https://stackoverflow.com/questions/47542259
复制相似问题