valgrind arm-linux cross-compilation

Publisher:捡漏来了Latest update time:2020-02-09 Source: eefocusKeywords:valgrind  arm-linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Valgrind is an instrumentation framework for building dynamic analysis tools. It comes with a set of tools, each of which performs some kind of debugging, profiling, or similar task that helps you improve your programs.


Valgrind's architecture is designed to be modular, so new tools can be created easily without disturbing the existing structure.


Before starting work, there are two pieces of information that you must read, that is, the platform and tool overview. Although Baidu has checked some, it is not as accurate as the official one:


Platform support, my ARM-v7 is supported


http://valgrind.org/info/platforms.html

Tool Overview:


http://valgrind.org/info/tools.html

 

Many useful tools are provided as standard.


Memcheck is a memory error detector. It can help you make your programs, especially those written in C and C++, more correct.


Cachegrind is a cache and branch prediction profiler. It can help you make your program run faster.


Callgrind is a call graph generating cache profiler. It has some overlap with Cachegrind, but also collects some information that Cachegrind does not.


Helgrind is a thread error detector. It can help you make your multithreaded programs more correct.


DRD is also a thread error detector. It is similar to Helgrind, but uses different analysis techniques, so may find different problems.


Massif is a heap profiler. It can help you make your program use less memory.


DHAT is a different type of heap analyzer. It helps you understand issues with block lifespan, block utilization, and layout inefficiencies.


SGcheck is an experimental tool that detects overflows of the stack and global arrays. Its functionality is complementary to that of Memcheck: SGcheck finds problems that Memcheck cannot, and vice versa.


BBV is an experimental SimPoint Basic Block Vector generator. It is useful for people doing computer architecture research and development.


The official explanation is:


Memcheck detects memory management problems, primarily for C and C++ programs. Memcheck runs programs about 10-30 times slower than normal


Cachegrind runs your program about 20-100 times slower than normal.


Massif runs programs 20 times slower than normal


1. Download source code

http://valgrind.org/

 


2 After decompression, configure:

./configure --prefix=/home/sun/share/install --host=arm-buildroot-linux-uclibcgnueabi

Configuration error:


checking for a supported CPU... no (arm)

configure: error: Unsupported host architecture. Sorry

Check the official website homepage and find that ARM-LINUX is supported


 It runs on the following platforms: X86/Linux, AMD64/Linux, ARM/Linux, ARM64/Linux, PPC32/Linux, PPC64/Linux, PPC64LE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, X86/Solaris, AMD64/Solaris, ARM/Android (2.3.x and later), ARM64/Android, X86/Android (4.0 and later), MIPS32/Android, X86/Darwin and AMD64/Darwin (Mac OS X 10.12).

Modify the configure file:


Change armv7a* to arm* and configure again without error


before fixing:

After modification:

3. Compile

make -j4

make install

Four directories will be generated: bin lib share include


4. My board space is very small, so I need to delete unnecessary tools and only leave the memory check tool.

You need to delete the files in the lib/valgrind directory and the entire share directory, and finally reduce it to about 12M:


sun@machine:~/share/install$ du -sh bin include/ lib/

520K bin

2.1M include/

10M lib/

 

All files in the streamlined lib/valgrind directory:


Copy code

32bit-core-valgrind-s1.xml 32bit-sse.xml arm-with-vfpv3.xml

32bit-core-valgrind-s2.xml arm-core-valgrind-s1.xml default.supp

32bit-core.xml arm-core-valgrind-s2.xml getoff-arm-linux

32bit-linux-valgrind-s1.xml arm-core.xml memcheck-arm-linux

32bit-linux-valgrind-s2.xml arm-vfpv3-valgrind-s1.xml vgpreload_core-arm-linux.so

32bit-linux.xml arm-vfpv3-valgrind-s2.xml vgpreload_memcheck-arm-linux.so

32bit-sse-valgrind-s1.xml arm-vfpv3.xml

32bit-sse-valgrind-s2.xml arm-with-vfpv3-valgrind.xml

Copy code

File information with the name containing ARM-LINUX:


sun@machine:~/share/install/lib/valgrind$ file *arm-linux*

getoff-arm-linux: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, with debug_info, not stripped

memcheck-arm-linux: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped

vgpreload_core-arm-linux.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped

vgpreload_memcheck-arm-linux.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped

5. Requirements for the operating environment:

http://valgrind.org/docs/manual/dist.readme-packagers.html

 View Code

Five important points are mentioned:


Copy code

1 - If your toolchain (compiler, linker) supports lto, using the configure option --enable-lto=yes will produce a smaller/faster valgrind


2 - Do not use a completely stripped Linux distribution /lib/ld.so. (For example, the getoff-arm-linux above links to /lib/ld-uClibc.so.0, which requires that /lib/ld-uClibc.so.0 in the root directory of our development board must be not stripped)


3 The directory running on the development board must be exactly the same as the directory specified by --prefix =

 

4 - Do not strip debug information from lib/valgrind/$platform/vgpreload*.so (such as vgpreload_core-arm-linux.so and vgpreload_memcheck-arm-linux.so above must be not stripped)


5 - Do not strip symbols from lib/valgrind/* in the installation tree. (e.g. getoff-arm-linux and memcheck-arm-linux above must be not stripped)

Copy code

The 4th and 5th items require that any file in the lib/valgrind/ directory must be not stripped to ensure the reliability of the program.


Put all the streamlined directories into the specified directory of the development board (that is, the directory with --prefix=/home/sun/share/install). If you forget which directory you compiled in, please check lib/pkgconfig/valgrind.pc


 The file contains an absolute path description: such as prefix=/home/sun/share/install 


sun@machine:~/share/install/lib/pkgconfig$ cat valgrind.pc 

prefix=/home/sun/share/install

exec_prefix=${prefix}

libdir=${exec_prefix}/lib

includedir=${prefix}/include/valgrind

arch=arm

os=linux

platform=arm-linux

valt_load_address=0x58000000


Name: Valgrind

Description: A dynamic binary instrumentation framework

Version: 3.14.0

Requires:

Libs: -L${libdir}/valgrind -lcoregrind-arm-linux -lvex-arm-linux -lgcc

Cflags: -I${includedir}

 

Generally, it can run successfully. Occasionally, it cannot run after adb push. If you have confirmed that the path on the development board is exactly the same as the path specified by prefix, but still report the following error:


valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory


Then you need to specify the path to the library:


VALGRIND_LIB=/home/sun/share/install/lib ./valgrind /home/sun/share/install/bin/valgrind --help

 


If it works, set it to the environment variable. It is only valid in the current terminal. If you open another terminal, you need to set it again. If the terminal is closed or the board is restarted, you also need to set it again:


export VALGRIND_LIB=/home/test/valgrind/lib/valgrind

 


After setting, you can run it directly./valgrind/home/sun/share/install/bin/valgrind --help can be successfully run


./valgrind/home/sun/share/install/bin/valgrind ls reports an error


The error message is: Internal error, valgrind segmentation error exited


After several days of back and forth, the cross tool chain was rebuilt and the error still occurred with the new version of uclibc.


After replacing the kernel version, the error still occurs


Changing to several older versions of valgrind still reports errors


Finally, I checked valgrind's support for the platform's CPU architecture again, and found that I had missed important information due to negligence at the beginning.


current


Valgrind supports the following platforms:


x86/Linux: up to SSSE3 included, but no higher - no SSE4, AVX, AVX2. This target is now in maintenance mode..

AMD64/Linux: includes AVX2. This is the primary development target, and tends to be well supported.

PPC32/Linux, PPC64/Linux, PPC64LE/Linux: Including Power8.

S390X/Linux: Supported.

ARM/Linux: Supported since ARMv7.

ARM64/Linux: ARMv8 support.

MIPS32/Linux, MIPS64/Linux: Supported.

X86/Solaris, AMD64/Solaris, X86/illumos, AMD64/illumos: Supported since Solaris 11.

X86/Darwin (10.10, 10.11), AMD64/Darwin (10.10, 10.11): Supported.

ARM/Android, ARM64/Android, MIPS32/Android, X86/Android: supported.

 


On Linux, you must be running kernel 3.0 or later, and glibc 2.5.X or later. On Mac OS X, you must be running 10.9.x or later.


Transplantation Program

Valgrind 3.X has infrastructure to support multiple platforms. A platform is a specific (CPU, OS) pairing, such as x86/Linux or AMD64/Linux.


A lot of effort goes into maintaining each port, more than most other programs. Valgrind is fragile because it works at a very low level. Also, each platform port has CPU-specific code, OS-specific code, and platform-specific code, and it's hard to test all the combinations.


Therefore, we can only justify support for widely used platforms. Unlike NetBSD or GCC, we are not interested in having Valgrind work on every platform in the known universe: the maintenance burden would be too high. Therefore, porting Valgrind to a different platform is not just a technical exercise: you also need to make a convincing case that the effort is worthwhile and that the port will be properly supported, at least for the foreseeable future.


Windows is not under consideration, as porting to it would require so many changes that it would almost be a separate project. (However, Valgrind + Wine could be done with some effort.) Also, non-open source operating systems are difficult to work with; being able to see the OS and associated (libc) source code makes things easier. However, Valgrind can be used in conjunction with Wine, which means that it is possible to run Windows programs under Valgrind.

[1] [2]
Keywords:valgrind  arm-linux Reference address:valgrind arm-linux cross-compilation

Previous article:How to build an ARM cross-compilation environment under Linux
Next article:Cross-compile Python-2.7.13 to ARM (aarch32) platform

Recommended ReadingLatest update time:2024-11-16 12:43

Design of intelligent monitoring system based on ARM-linux
With the development and progress of society, people's pace of life has accelerated. In environments such as family life and work, there are often no people. At this time, security issues are worrying. It is very necessary to develop a suitable security monitoring system. However, most of the current intelligent monit
[Microcontroller]
Design of intelligent monitoring system based on ARM-linux
How is ARM-Linux development different from MCU development?
The development of ARM-Linux programs is mainly divided into three categories: application development, driver development, and system kernel development. Different types of software development have different characteristics. Today we will look at the differences between ARM-Linux development and MCU development, as
[Microcontroller]
ARM-Linux cross-compilation tool under Linux platform
The following is the compilation of ARM under Ubuntu platform: 1. Disassembly tools arm-linux-objdump -D -S hello log //View the assembly code of hello 2. ELF file viewing tool arm-linux-readelf -a hello log //View the hello file arm-linux-readelf -d hello log //View the dynamic library used by hello 3. De
[Microcontroller]
gdb+gdbserver debug arm-linux program
As an important element of struct file_operations, mmap mainly implements the mapping relationship between physical memory and virtual memory, so that virtual memory can be directly accessed without using device-related read and write operations. The basic process of mmap is to map files to virtual memory. In a previou
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号