Valgrind Memcheck可以与CGo一起使用吗?

huangapple go评论78阅读模式
英文:

Can valigrind memcheck be used with CGo?

问题

我们有一个主要使用Go(1.17)编写的应用程序,通过CGo(GCC 7.5)在ARM处理器上调用了很多CUDA。我们偶尔会遇到类似于C端对堆进行了破坏的恐慌情况。我尝试在valgrind下运行整个应用程序,但是我得到了太多类似于下面的消息:

==14869== Thread 1:
==14869== Invalid read of size 8
==14869==    at 0x4783AC: runtime.startm (proc.go:2508)
==14869==    by 0x47890B: runtime.wakep (proc.go:2584)
==14869==    by 0x47CF8F: runtime.newproc.func1 (proc.go:4261)
==14869==    by 0x4A476B: runtime.systemstack (asm_arm64.s:230)
==14869==    by 0x4A465F: runtime.mstart (asm_arm64.s:117)
==14869==  Address 0x1fff0001a8 is on thread 1's stack
==14869==  8 bytes below stack pointer

无法看到任何有用的信息。我假设这些是误报,Go运行时实际上并没有存在未定义行为的问题。我找不到抑制此检查的标志。我错过了什么吗?还有其他方法来调查这个问题吗?我可以用C++编写测试工具,但这将改变我怀疑是问题关键的使用模式。

英文:

we have an application that is mostly Go (1.17) that makes a lot of calls through CGo (GCC 7.5) to CUDA on an ARM processor. We occasionally see panics that look like something has done bad things to the heap in the C side. I tried running the whole application under valgrind, but I get too many messages like

==14869== Thread 1:
==14869== Invalid read of size 8
==14869==    at 0x4783AC: runtime.startm (proc.go:2508)
==14869==    by 0x47890B: runtime.wakep (proc.go:2584)
==14869==    by 0x47CF8F: runtime.newproc.func1 (proc.go:4261)
==14869==    by 0x4A476B: runtime.systemstack (asm_arm64.s:230)
==14869==    by 0x4A465F: runtime.mstart (asm_arm64.s:117)
==14869==  Address 0x1fff0001a8 is on thread 1's stack
==14869==  8 bytes below stack pointer

to see anything useful. I am assuming these are false positives, and the Go runtime is not in fact riddled with undefined behaviour. I can't see a flag to suppress that check. Have I missed it? Is there some other way to investigate this problem? I could write test harnesses in C++ but that will change the use pattern which I suspect is key to the problem.

答案1

得分: 1

我使用以下命令将cgo软件构建为可执行文件:

go build

这将在当前目录下生成一个名为"mycgoprog"的可执行文件。然后,我使用以下命令在该可执行文件上运行valgrind:

G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log ./mycgoprog

valgrind.log文件将包含valgrind在链接的C代码中检测到的所有问题。

英文:

I build the cgo software to an executable with

  go build

which produces an executable by the name of the directory you are in. Let's say it's call "mycgoprog"
I then run valgrind against it with this command:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log ./mycgoprog

The valgrind.log then contains the all the indiscretions detected by valgrind in the linked c code.

huangapple
  • 本文由 发表于 2022年3月17日 00:03:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/71500390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定