c/c++语言开发共享Valgrind报告空C程序的未初始化值

我用gcc test.cclang test.c编译了这个C程序:

 int main (void) { return 0; } 

valgrind ./a.out给了我这个:

 ==9232== Memcheck, a memory error detector ==9232== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==9232== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==9232== Command: ./a.out ==9232== ==9232== Conditional jump or move depends on uninitialised value(s) ==9232== at 0x4017876: index (in /usr/lib/ld-2.16.so) ==9232== by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so) ==9232== by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so) ==9232== by 0x400180D: map_doit (in /usr/lib/ld-2.16.so) ==9232== by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so) ==9232== by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so) ==9232== by 0x4004546: dl_main (in /usr/lib/ld-2.16.so) ==9232== by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so) ==9232== by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so) ==9232== by 0x4001627: ??? (in /usr/lib/ld-2.16.so) ==9232== ==9232== Conditional jump or move depends on uninitialised value(s) ==9232== at 0x401787B: index (in /usr/lib/ld-2.16.so) ==9232== by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so) ==9232== by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so) ==9232== by 0x400180D: map_doit (in /usr/lib/ld-2.16.so) ==9232== by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so) ==9232== by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so) ==9232== by 0x4004546: dl_main (in /usr/lib/ld-2.16.so) ==9232== by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so) ==9232== by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so) ==9232== by 0x4001627: ??? (in /usr/lib/ld-2.16.so) ==9232== ==9232== ==9232== HEAP SUMMARY: ==9232== in use at exit: 0 bytes in 0 blocks ==9232== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9232== ==9232== All heap blocks were freed -- no leaks are possible ==9232== ==9232== For counts of detected and suppressed errors, rerun with: -v ==9232== Use --track-origins=yes to see where uninitialised values come from ==9232== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) 

GCC版本4.7.1和Clang版本3.1。 这怎么了? 我的记忆有问题吗? 自从我上次使用valgrind以来有一段时间,但我认为这不是正常行为。 喊叫?


解决方案 :我从@Shawn学到的东西可以使用valgrind .supp文件来抑制这些链接器错误。 我做的是使用--gen-suppressions=all选项在我的程序上运行valgrind:

 valgrind --gen-suppressions=all ./a.out 

然后我提取括在括号中的新块,并将它们直接放入my.supp文件中:

 {  Memcheck:Cond fun:index fun:expand_dynamic_string_token fun:_dl_map_object fun:map_doit fun:_dl_catch_error fun:do_preload fun:dl_main fun:_dl_sysdep_start fun:_dl_start obj:/usr/lib/ld-2.16.so } 

现在我可以使用--suppressions选项运行valgrind以指向我的新文件,并且将禁止消息:

 valgrind --suppressions=/home/foo/my.supp ./a.out 

    这是valgrind的一个已知 问题 ,通常使用valgrind抑制来解决 。 假设已经为您的发行版报告了问题,则抑制列表应该很快更新,并在下次更新时消失。

    现在,忽略该消息是安全的。

    如果它困扰你,你可以维护你自己的抑制文件并使用它直到你的发行版更新默认文件(通常是/var/lib/valgrind/default.supp )。

    这是动态链接器中的“问题”并且很常见。 它出现在main()被调用之前。 您可以忽略该消息。

    需要了解更多c/c++开发分享Valgrind报告空C程序的未初始化值,也可以关注C/ C++技术分享栏目—计算机技术网(www.ctvol.com)!

      以上就是c/c++开发分享Valgrind报告空C程序的未初始化值相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/978881.html

      (0)
      上一篇 2021年12月12日
      下一篇 2021年12月12日

      精彩推荐