gpt4 book ai didi

c++ - Valgrind 'uninitialised value' 依赖不引用我的代码

转载 作者:行者123 更新时间:2023-11-28 02:47:46 25 4
gpt4 key购买 nike

这个 valgrind 输出让我感到困惑,因为它似乎没有引用我的代码,而且我在使用 STL 编写的多个程序中都得到了它,尽管没有 HEAP SUMMARY 错误:

$ valgrind -v --leak-check=full --track-origins=yes ./hellostl

...

==7989== Conditional jump or move depends on uninitialised value(s)
==7989== at 0x4017AA6: index (in /lib64/ld-2.17.so)
==7989== by 0x4007A12: expand_dynamic_string_token (in /lib64/ld-2.17.so)
==7989== by 0x4008304: _dl_map_object (in /lib64/ld-2.17.so)
==7989== by 0x400181D: map_doit (in /lib64/ld-2.17.so)
==7989== by 0x400E985: _dl_catch_error (in /lib64/ld-2.17.so)
==7989== by 0x40010EF: do_preload (in /lib64/ld-2.17.so)
==7989== by 0x40039D7: dl_main (in /lib64/ld-2.17.so)
==7989== by 0x40152B7: _dl_sysdep_start (in /lib64/ld-2.17.so)
==7989== by 0x4004E94: _dl_start (in /lib64/ld-2.17.so)
==7989== by 0x4001637: ??? (in /lib64/ld-2.17.so)
==7989== Uninitialised value was created by a stack allocation
==7989== at 0x4003961: dl_main (in /lib64/ld-2.17.so)
==7989==
==7989== Conditional jump or move depends on uninitialised value(s)
==7989== at 0x4017AAB: index (in /lib64/ld-2.17.so)
==7989== by 0x4007A12: expand_dynamic_string_token (in /lib64/ld-2.17.so)
==7989== by 0x4008304: _dl_map_object (in /lib64/ld-2.17.so)
==7989== by 0x400181D: map_doit (in /lib64/ld-2.17.so)
==7989== by 0x400E985: _dl_catch_error (in /lib64/ld-2.17.so)
==7989== by 0x40010EF: do_preload (in /lib64/ld-2.17.so)
==7989== by 0x40039D7: dl_main (in /lib64/ld-2.17.so)
==7989== by 0x40152B7: _dl_sysdep_start (in /lib64/ld-2.17.so)
==7989== by 0x4004E94: _dl_start (in /lib64/ld-2.17.so)
==7989== by 0x4001637: ??? (in /lib64/ld-2.17.so)
==7989== Uninitialised value was created by a stack allocation
==7989== at 0x4003961: dl_main (in /lib64/ld-2.17.so)

有没有可能是我使用了某个过时版本的东西(例如编译器、valgrind...)?

编辑:触发错误的简单代码:

#include <vector>
#include <iostream>
using namespace std;

int main ()
{
vector<int> foo;
for (int i = 0; i < 50; ++i)
foo.push_back( i );

for (auto it = foo.begin();
it != foo.end();
++it)
{
cout << *it << endl;
}
}

最佳答案

动态链接库因导致 Valgrind 警告而臭名昭著。您观察到的实际上是一种非常常见的。您无法修复此警告,但如果它让您烦恼,您可以添加抑制规则。

更详细地说,这里发生的是在您的程序运行之前动态链接 C++ 标准库。如果您使用 ldd 检查您的二进制文件,您应该看到这样一行:

    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fa0e2f72000)

如果您要静态链接此库,您的程序将在没有动态链接的情况下运行,并且警告将消失。

关于c++ - Valgrind 'uninitialised value' 依赖不引用我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23844850/

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