c编程 - 在Ubuntu中编译和在Alpine中编译之间的区别 - gcc - valgrind

时间:2017-11-23 12:05:13

标签: c ubuntu gcc valgrind alpine

我正在尝试理解在Ubuntu(规范的ubuntu)和Alpine(一个docker容器)上使用gcc编译简单的C程序时我注意到的一些差异。

该计划如下:

int main(void)
{
  printf("test\n");
  return 0;
}

用于编译的命令对于每个终端(Ubuntu和Alpine)都是相同的。

Valgrind在Ubuntu上检测不到错误,在Alpine上检测到1错误:

==311== Invalid free() / delete / delete[] / realloc()
==311==    at 0x4C939EA: free (vg_replace_malloc.c:530)
==311==    by 0x4057B69: ??? (in /lib/ld-musl-x86_64.so.1)
==311==  Address 0x4e9b180 is in a rw- mapped file 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so segment
==311==
test
==311==
==311== HEAP SUMMARY:
==311==     in use at exit: 404 bytes in 1 blocks
==311==   total heap usage: 1 allocs, 1 frees, 404 bytes allocated
==311==
==311== LEAK SUMMARY:
==311==    definitely lost: 0 bytes in 0 blocks
==311==    indirectly lost: 0 bytes in 0 blocks
==311==      possibly lost: 0 bytes in 0 blocks
==311==    still reachable: 404 bytes in 1 blocks
==311==         suppressed: 0 bytes in 0 blocks
==311== Rerun with --leak-check=full to see details of leaked memory
==311==
==311== For counts of detected and suppressed errors, rerun with: -v
==311== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

对此有何解释?

1 个答案:

答案 0 :(得分:2)

Valgrind调用特殊的glibc函数来在进程退出时释放内存(通常,glibc只让内核执行此操作)。穆斯尔可能没有这个,因为它是臃肿的。

Valgrind还有抑制文件来处理来自系统库的误报或无用的报告。创建它们需要一些移植工作,看起来Alpine还没有这样做,或者由于进一步的开发,文件已经过时了。

有时,抑制文件需要debuginfo符号,而valgrind在你引用的运行中找不到它们,所以这是另一回事。