Valgrind交叉编译

发布时间:2024年01月03日

????????Valgrind下载地址:https://valgrind.org/downloads/

????????下载到linux之后执行如下命令:

./configure CC=/opt/hisi-linux/x86-arm/aarch64-himix200-linux/bin/aarch64-himix200-linux-gcc CXX=/opt/hisi-linux/x86-arm/aarch64-himix200-linux/bin/aarch64-himix200-linux-g++ AR=/opt/hisi-linux/x86-arm/aarch64-himix200-linux/bin/aarch64-himix200-linux-ar --host=aarch64-himix200-linux --prefix=/home/teddy/project_app/software/valgrind-3.22.0/_install
make
make install

????????注意:在执行./configure执行的时候,有很多博主说需要修改configure文件将 armv7*改为armv7* |arm 或者将configure的参数使用:--host=armv7-linux;其实没必要,只需要使用交叉编译工具给定的架构即可;

????????例如我是用的交叉编译工具为:aarch64-himix200-linux-gcc则将host指定为aarch64-himix200-linux:

--host=aarch64-himix200-linux#去掉最后面的-gcc即可

????????Valgrind支持很多平台,给出交叉编译工具的架构即可自动匹配合适的指令集;对于有的编译器而言使用--host=armv7-linux可能会报错:

//使用aarch64-himix200-linux-gcc编译器就会出现该问题
aarch64-himix200-linux-gcc: error: unrecognized command line option '-marm'; did you mean '-fasm'?

????????如果出现以下问题:

/xxx/aarch64-linux-gnu/bin/ld: vbit_test-unary.o: Relocations in generic ELF (EM: 62)

????????这可能时你之前使用了--host=armv7-linux或者其他编译器没有清理make生成的文件,执行make而导致的;如果之前报错,修改后最好make clean或者重新解压工具包按照正确的方法重新编译。

????????正确编译后就会在指定的目录_install目录生成可执行文件,库文件等可移植文件。会生成如下资源:

bin  include  lib  libexec  share

????????其中lib中是静态库,可以不用移植到开发板;将bin,libexec两个目录移植到板子上,假设路径是:/mmc_data/tools/valgrind;将bin,libexec两个目录放到该目录下,然后设置环境变量:

//设置可执行文件的环境变量
export PATH=/mmc_data/tools/valgrind/bin:$PATH
//添加libexec库环境变量,VALGRIND_LIB是用户自定义的宏;
//它指向 Valgrind 工具的库的路径。这样设置环境变量后,系统中的程序可以通过使用 
//$VALGRIND_LIB 这个变量来引用 Valgrind 的库路径,以确保正确地使用 Valgrind 工具和功能。
//libexec是valgrind工具所需的动态库
export VALGRIND_LIB=/mmc_data/tools/valgrind/libexec/valgrind

????????运行指令:

valgrind --tool=memcheck --leak-check=full ./test

????????如果出现以下错误:

==22742== Memcheck, a memory error detector
==22742== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==22742== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==22742== Command: /app/meta8k/meta8k_mat_server
==22742==

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld-linux-aarch64.so.1
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-aarch64.so.1
valgrind:
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:
valgrind:  Cannot continue -- exiting now.  Sorry.

==22742== Memcheck, a memory error detector;这行是没事的,只是工具的打印信息;

7-15行是错误的:需要安装libc6-dbg;

????????由于我是在海思3531上运行的,没有找到合适的libc6-dbg,所以就没向大家展示正确用法;但是编译过程是正确的,说实话这个工具对于arm系统不太友好,不知道是不是只是海思芯片有这问题。

文章来源:https://blog.csdn.net/qq_39466755/article/details/135370040
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。