Valgrind报告空C程序未初始化的值

Valgrind报告空C程序未初始化的值

本文介绍了Valgrind报告空C程序未初始化的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

  int main(void){
return 0;
}

valgrind ./a.out给我这个:

  == 9232 == Memcheck,一个内存错误检测器
== 9232 = =版权(C)2002-2011,以及Julian Seward等人的GNU GPL'd。
== 9232 ==使用Valgrind-3.7.0和LibVEX;使用-h获取版权信息
== 9232 ==命令:./a.out
== 9232 ==
== 9232 ==条件跳转或移动取决于未初始化的值( s)
== 9232 == at 0x4017876:index(in /usr/lib/ld-2.16.so)
== 9232 == by 0x4007902:expand_dynamic_string_token(在/ usr / lib / ld- 2.16.so)
== 9232 == by 0x4008204:_dl_map_object(in /usr/lib/ld-2.16.so)
== 9232 == by 0x400180D:map_doit(在/ usr / lib / (在/usr/lib/ld-2.16.so中)
== 9232 == by 0x40010DB: 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:?? ? (在/usr/lib/ld-2.16.so中)
== 9232 ==
== 9232 ==条件跳转或移动取决于未初始化的值
== 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(在/usr/lib/ld-2.16.so)
== 9232 == by 0x400E785:_dl_catch_error(在/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(在/usr/lib/ld-2.16.so中)
== 9232 == by 0x4004DFD:_dl_start(in /usr/lib/ld-2.16.so)
== 9232 == by 0x4001627:??? (在/usr/lib/ld-2.16.so中)
== 9232 ==
== 9232 ==
== 9232 == HEAP SUMMARY:
== 9232 ==退出时使用:0字节0块
== 9232 ==总堆使用情况:0分配,0释放,0字节分配
== 9232 ==
== 9232 ==所有的堆块都被释放 - 没有泄漏是可能的
== 9232 ==
== 9232 ==对于检测到的和被压缩的错误计数,重新运行:-v
== 9232 ==使用--track-origins = yes查看未初始化值来自何处
== 9232 ==错误摘要:来自2个上下文的2个错误(被抑制:0从0)

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




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

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

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

  {
< linker>
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
}

现在我可以运行valgrind并使用 - suppressions 选项指向我的新文件消息将被压制:

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


解决方案

这是 with valgrind,通常是的。假设已经为您的发行版报告了问题,抑制列表应该很快更新,并且会在下次更新中消失。



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



如果您困扰您,您可以保留并使用它,直到您的发行版更新默认文件(通常 /var/lib/valgrind/default.supp )。


I have this C program compiled with either gcc test.c or clang test.c:

int main (void) {
    return 0;
}

valgrind ./a.out gives me this:

==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 version 4.7.1 and Clang version 3.1. What is up with this? Is there something wrong with my memory? There's some time since I last used valgrind but this I think is not normal behaviour. Yelp?


Solution:It is possible from what I learned from @Shawn to suppress these linker errors using a valgrind .supp file. What I did was running valgrind on my program using the --gen-suppressions=all option:

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

Then I extract the new chunks enclosed in brackets and put them directly into a file my.supp:

{
   <linker>
   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
}

Now I can run valgrind with the --suppressions option to point to my new file and the messages will be suppressed:

valgrind --suppressions=/home/foo/my.supp ./a.out
解决方案

This is a know issue with valgrind which is typically addressed using valgrind suppressions. Assuming the issue has been reported for your distro, the suppressions list should be updated shortly and will disappear in the next update.

For now, it is safe to ignore the message.

If it bothers you, you can maintain your own suppressions file and use it until your distro updates the default file (usually /var/lib/valgrind/default.supp).

这篇关于Valgrind报告空C程序未初始化的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:52