【问题标题】:valgrind giving fatal error at launching timevalgrind 在启动时给出致命错误
【发布时间】:2022-06-14 00:04:50
【问题描述】:

我已经为嵌入式设备编译了 valgrind,并执行了以下命令来检查泄漏。

./valgrind --leak-check=full --xml=yes --xml-file=<xml file path> <application>

但它给出了以下错误。

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld-linux-x86-64.so.2
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-x86-64.so.2
valgrind:
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:
valgrind:  Cannot continue -- exiting now.  Sorry.

有一个与 valgrind 一起构建的库“ld-2.19.so”,如果我将此库复制到 /lib/(将 /lib/ 下现有的 ld-2.19.so 替换为与 valgrind 一起构建的相同库)然后 valgrind 运行良好。相同的工具链用于为嵌入式设备和 valgrind 构建 rootfs。用与 valgrind 一起构建的库替换现有的“ld-2.19.so”不会影响 valgrind 生成的报告?

【问题讨论】:

  • 这到底是什么平台?你应该从一些简单的东西开始(--tool=none 和一个小的可执行文件,如 pwdls/bin/echo
  • @PaulFloyd 这是一个英特尔平台(原子处理器)。我已经执行了./valgrind --tool=none ls,但它给出了错误valgrind: failed to start tool 'none' for platform 'amd64-linux': No such file or directory
  • @PaulFloyd,如果我们将工具设为无,那么它会给出上述评论中更新的错误。
  • 你能告诉你是否有完整的 Valgrind 安装吗?你应该有 [install dir]/libexec/valgrind/none-amd64-linux (对于 AMD64 上的 Linux,对于其他操作系统和硬件会有所不同)
  • 我已将所有 valgrind 文件复制到一个路径并在 VALGRIND_LIB 中导出该路径,之后它工作正常。

标签: embedded-linux valgrind


【解决方案1】:

“Valgrind 的工作原理”是一个很长的故事。我会尽量保持简短。

  • 启动器valgrind 可执行文件将 LD_PRELOAD 设置为指向一两个 Valgrind 库,然后执行工具可执行文件(默认为 memcheck)
  • 该工具不使用 libc。相反,它从汇编程序开始,并且必须设置自己的堆栈和堆。
  • 然后它将来宾可执行文件和 ld.so 加载到内存中。
  • 如果他们有 debuginfo,它会读取它,也会读取它自己。 *****
  • 然后它开始 JIT 解释客户机器代码。这将经历来宾启动过程,加载共享库,然后执行“main”。
  • 启动时还会加载 LD_PRELOAD 库,这会触发一些与重定向相关的特殊操作。

由于 Valgrind 正在重定向所有 malloc 函数,它可以跟踪该内存。 memcheck 维护“影子”内存,它告诉 Valgrind 相应的客户内存是否已初始化。它还具有所有已分配(和已解除分配)内存的映射,可用于判断内存是否可寻址。

你的问题似乎出在我放 ***** 的地方。 Valgrind 无法找到 ld.so 的任何调试信息,因此无法重定向 strlen

我不知道你在做什么来构建 ld.so。它当然不是标准 Valgrind 构建的一部分,所以我无法对此发表评论。

如果您的 ld.so 构建正确,那么您应该没有问题。

【讨论】:

    猜你喜欢
    • 2018-07-06
    • 2018-05-27
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多