WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Compiling valgrind profiling tool on RPi 3  (Read 4908 times)

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Compiling valgrind profiling tool on RPi 3
« on: July 12, 2017, 05:31:56 AM »
I downloaded the latest source code for valgrind (version 3.13.0 currently at the writing of this post) and compiled on the raspberry pi successfully after installing perl5 and modyfing the first line of link_tool_exe_linux to `#!/usr/bin/perl`. However, after compilation running valgrind fails with the following message:

Code: [Select]
==3715== Memcheck, a memory error detector
==3715== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3715== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==3715== Command: ls -l
==3715==

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:      strcmp
valgrind:  in an object with soname matching:   ld-linux-armhf.so.3
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-armhf.so.3
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.

I don't find any equivalent of libc6-dbg in the tcz repositories and I don't know where I can get the source code to compile the package myself. Is there perhaps a way to get a unstripped version of /lib/ld-2.25.so?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Compiling valgrind profiling tool on RPi 3
« Reply #1 on: July 12, 2017, 09:59:44 AM »
You would need to compile glibc without stripping the debug symbols - there is an example here:

http://tinycorelinux.net/6.x/armv6/tcz/src/glibc/

Note that you can find the glibc shource at:

http://ftp.gnu.org/gnu/glibc/

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: Compiling valgrind profiling tool on RPi 3
« Reply #2 on: July 17, 2017, 08:28:02 AM »
You would need to compile glibc without stripping the debug symbols - there is an example here:

http://tinycorelinux.net/6.x/armv6/tcz/src/glibc/

Note that you can find the glibc shource at:

http://ftp.gnu.org/gnu/glibc/


I built glibc for the raspberry pi and did a rsync to the root after unpacking 9.0.2v7.gz but it was 17 MB in size and the FAT32 partition didn't have enough space to fit the modified 9.0.2v7.gz file so I tried to expand it to 54 MB but parted could not change the partition to that size for some reason. Do I need to change the size of the mmcblk0p1 partition and if so, how?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Compiling valgrind profiling tool on RPi 3
« Reply #3 on: July 17, 2017, 09:07:47 AM »
from the error message above, it looked like you only needed ld-linux-armhf.so.3 with debug symbols - you should be able to overwrite the original after boot to be able to compile valgrind

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: Compiling valgrind profiling tool on RPi 3
« Reply #4 on: July 18, 2017, 03:21:44 AM »
from the error message above, it looked like you only needed ld-linux-armhf.so.3 with debug symbols - you should be able to overwrite the original after boot to be able to compile valgrind

I overwrote the ld-linux-armhf.so.3 symlink with ld-2.25.so with debug symbols and I got multiple errors when trying to execute programs:
```
ls: error while loading shared libraries: libcap.so.2: cannot open shared object file: No such file or directory
sudo: error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory
```
The original system does not contain libcap.so.2 or libcrypt.so.1 it seems so I think that the configure command is not the same as the original ld that is stripped.
« Last Edit: July 18, 2017, 03:32:01 AM by Linkan »

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: Compiling valgrind profiling tool on RPi 3
« Reply #5 on: July 18, 2017, 04:26:32 AM »
Nevermind, the libcap.so file exist in "/usr/local/lib/libcap.so", so I think the problem is ld-2.25.so is not looking in the /usr/local/lib folder.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Compiling valgrind profiling tool on RPi 3
« Reply #6 on: July 18, 2017, 05:53:32 AM »
did you overwrite ld.so.conf as well?

Code: [Select]
$ cat /etc/ld.so.conf
/usr/local/lib
« Last Edit: July 18, 2017, 06:00:35 AM by Juanito »

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: Compiling valgrind profiling tool on RPi 3
« Reply #7 on: July 18, 2017, 06:21:10 AM »
did you overwrite ld.so.conf as well?

Code: [Select]
$ cat /etc/ld.so.conf
/usr/local/lib

All I did was overwrite the ld-linux-armhf.so.3 file with ld-2.25.so file and didn't modify ld.so.conf. Maybe I need to do a export LD_LIBRARY_PATH = usr/local/lib

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Compiling valgrind profiling tool on RPi 3
« Reply #8 on: July 18, 2017, 07:34:23 AM »
I don't have an RPi to hand at the moment, but if you followed the instructions here:

http://tinycorelinux.net/6.x/armv6/tcz/src/glibc/glibc.build

..wouldn't the file be named ld-linux-armhf.so.3 and not ld-2.25.so?

What do you get from:
Code: [Select]
$ ldd /usr/local/lib/libcap.so

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: Compiling valgrind profiling tool on RPi 3
« Reply #9 on: July 19, 2017, 04:39:30 AM »
I don't have an RPi to hand at the moment, but if you followed the instructions here:

http://tinycorelinux.net/6.x/armv6/tcz/src/glibc/glibc.build

..wouldn't the file be named ld-linux-armhf.so.3 and not ld-2.25.so?

What do you get from:
Code: [Select]
$ ldd /usr/local/lib/libcap.so

I did indeed follow the provided instructions but ld-linux-armhf.so.3 is a symlink to ld-2.25.so.

Running ldd on my raspberry pi gives me this:
Code: [Select]
tc@box:~$ ldd /usr/local/lib/libcap.so
ldd: warning: you do not have execution permission for `/usr/local/lib/libcap.so'
        linux-vdso.so.1 (0x7ef6f000)
        libc.so.6 => /lib/libc.so.6 (0x76df4000)
        /lib/ld-linux-armhf.so.3 (0x54b97000)