【问题标题】:new libstdc++ of gcc5.1 may allocate large heap memorygcc5.1的新libstdc++可能分配大堆内存
【发布时间】:2015-05-22 09:34:55
【问题描述】:

valgrind 在一个用 gcc5.1 编译的空程序中检测到“仍然可达泄漏”,g++ ./a.cpp

int main () {}

valgrind 说,valgrind ./a.out

==32037== HEAP SUMMARY:
==32037==     in use at exit: 72,704 bytes in 1 blocks
==32037==   total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==32037== 
==32037== LEAK SUMMARY:
==32037==    definitely lost: 0 bytes in 0 blocks
==32037==    indirectly lost: 0 bytes in 0 blocks
==32037==      possibly lost: 0 bytes in 0 blocks
==32037==    still reachable: 72,704 bytes in 1 blocks
==32037==         suppressed: 0 bytes in 0 blocks
==32037== Rerun with --leak-check=full to see details of leaked memory
==32037== 
==32037== For counts of detected and suppressed errors, rerun with: -v
==32037== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 5)

对于 c 程序,valgrinds 报告没有内存泄漏和内存分配。 此外,对于 gcc5.0 和 gcc4.9.2,valgrinds 也没有报告内存泄漏和内存分配。 那么,我猜是gcc5.1的新libstdc++造成的。

我的问题是如何减少可能在 libstdc++ 中的巨大内存分配。 确实,这个用-O3 编译的空c++ 程序的执行时间比一个空c 程序大几毫秒(没有systime)。

【问题讨论】:

  • 您的文件只有 int main () {} 吗?或者它有包含,等等?
  • 没有包含或链接用户指定的文件。 int main () {} 就是内容,g++ ./a.cpp 是我使用的编译命令。
  • 所以真的只有int main () {}...哇gcc...哇....
  • gcc -E a.cpp 给你什么? .o 长什么样子?
  • g++ -E a.cpp 说,#1“test.cpp”#1“”#1“”​​​#1“” }  我认为objfile似乎很平常。没有不熟悉的符号。无论如何,user657267 建议的链接可能会说明问题。

标签: c++ c gcc valgrind


【解决方案1】:

该空间在 libsup++ 中被分配为紧急异常缓冲区

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64535

开发人员谈论可能会抑制 Valgrind 中的踪迹,但最终可能什么也没做。现在从跟踪中消除它的唯一方法可能是禁用异常,但无论哪种方式看起来都没什么大不了的,并不是说在程序退出之前可以为其他东西回收内存。

【讨论】:

  • 这绝对需要 Valgrind 的压制,在我偶然发现这个 SO 线程之前浪费了半个小时寻找我的漏洞......
  • 看起来他们已经解决了这个问题,现在我们只需要等到我们的发行版赶上来!
  • @nic 你有关于你的评论的资源吗?
  • 我发现这篇文章 wiki.wxwidgets.org/Valgrind_Suppression_File_Howto 在告诉我如何创建 valgrind 抑制方面很有用。我的抑制(对于 gcc 5.4.0)是 { Memcheck:Leak match-leak-kinds:reachable fun:malloc obj:/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0 .21 fun:call_init.part.0 fun:call_init fun:_dl_init obj:/lib/x86_64-linux-gnu/ld-2.23.so }
猜你喜欢
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2014-08-14
  • 2022-11-23
  • 1970-01-01
  • 2013-12-02
  • 2011-12-01
相关资源
最近更新 更多