Valgrind errors when linked with -static — Why?

懵懂的女人 提交于 2019-12-01 03:28:27

Does valgrind just not work with -static?

It does. The problem is not in Valgrind, it's in glibc, which is not Valgrind clean. The glibc developers refused to fix these problems (because the problems are of a "don't care" nature, and fixing them costs (a few) cycles).

When you link dynamically, these errors come from libc.so.6, and can be easily suppressed, which is what Valgrind does by default.

But when you link statically, these errors come from your executable (which now includes code from libc.a), and so the default Valgrind suppressions don't suppress them.

You could write new suppressions (see Valgrind --gen-suppressions=yes documentation).

Or you could install and use glibc-audit.

If the library causes problems in valgrind, you can only ignore those problems by writing suppression files.

One of problems I encountered is alocating something on the heap, like this :

// library
int * some = new int;

// main links the library
int main()
{
}

This example would report an error about leak.

EDIT : if you have the library's source, you can fix the error (use of uninitialized variable), and recompile it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!