gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:37:34 27 4
gpt4 key购买 nike

我试图了解在 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)

这是什么原因?

最佳答案

Valgrind 调用特殊的 glibc 函数在进程退出时释放内存(而通常情况下,glibc 只是让内核这样做)。 Musl 可能没有那个,因为它膨胀得很差。

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

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

关于c 编程 - 在 Ubuntu 中编译和在 Alpine 中编译的区别 - gcc - valgrind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47455189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com