首页 > 解决方案 > 使用 valgrind 时在 _dl_start 的堆栈指针下方写入无效

问题描述

我正在学习在嵌入式 ARM (rockchip rk3288) 平台上使用 valgrind:

valgrind /tmp/a.out 

我不断收到这些错误:

==252== Memcheck, a memory error detector
==252== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==252== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==252== Command: /tmp/a.out
==252==
==252== Invalid write of size 4
==252==    at 0x4001598: _dl_start (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6d3c is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x4019174: _dl_sysdep_start (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6cf4 is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x40184FC: __GI___tunables_init (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6c8c is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x4002038: dl_main (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6c8c is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x401D3AC: bcmp (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6a9c is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x400278C: dl_main (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6a9c is on thread 1's stack
==252==  36 bytes below stack pointer
==252==
==252== Invalid write of size 4
==252==    at 0x4019BEC: rtld_malloc (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6a84 is on thread 1's stack
==252==  12 bytes below stack pointer
==252==
==252== Conditional jump or move depends on uninitialised value(s)
==252==    at 0x400C610: _dl_new_object (in /lib/ld-2.32.so)
==252==
==252== Invalid write of size 4
==252==    at 0x40027B8: dl_main (in /lib/ld-2.32.so)
==252==  Address 0xbdbc6aa0 is on thread 1's stack
==252==  32 bytes below stack pointer
==252==
==252== Use of uninitialised value of size 4
==252==    at 0x400C258: _dl_add_to_namespace_list (in /lib/ld-2.32.so)
........

我正在使用内核 5.13.13 和 buildroot 2021.05.1(它构建了我的工具链,我也用它来编译我的内核)。

这是我的代码(t.cpp):

  1 #include <cstdlib>
  2 #include <iostream>
  3
  4 int main() {
  5
  6         std::cout << "allocating..." << std::endl;
  7         void* p = malloc(1000);
  8
  9         std::cout << "freeing..." << std::endl;
 10         free(p);
 11         free(p);
 12
 13         return 0;
 14 }

我正在使用这个 bash 脚本进行编译:

#!/bin/sh

export BUILDROOT_HOME=/home/user/buildroot
export SYSROOT=$BUILDROOT_HOME/output/staging
export PATH=$PATH:$BUILDROOT_HOME/output/host/usr/bin

arm-linux-g++ --sysroot=$SYSROOT t.cpp

我得到的错误似乎与我的代码无关。有什么想法可能是错的吗?

谢谢

标签: linuxarmg++valgrindbuildroot

解决方案


推荐阅读