0

I am able to check a certain SW with Valgrind on my PC (Ubuntu) but for more realistic results I also want to check the same SW on OpenWRT (21.02.0-rc4).

Basicly Valgrind runs in OpenWRT but currently there are several issues:

1- I'm running

valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./my_SW

On the PC this works but on OpenWRT the --track-origins=yes parameter causes a "Killed" message right after start of Valgrind.

2- When I skip the track-origins parameter Valgrind is able to run my SW but in the report at the end:

==12462== HEAP SUMMARY:
==12462==     in use at exit: 0 bytes in 0 blocks
==12462==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==12462== 
==12462== All heap blocks were freed -- no leaks are possible

On the PC, Valgrind reports thousands of allocs and the same amount of frees, but on OpenWRT it seems it can't detect any Heap usage.

3- On OpenWRT I get many errors like the one below, whereas the same SW runs on the PC error free:

==12462== Conditional jump or move depends on uninitialised value(s)
==12462==    at 0x4079058: ??? (in /lib/libc.so)
==12462==    by 0x408A4B4: ??? (in /lib/libc.so)

I thought my problems may be related with the issue below:

cross-compiled Valgrind does not detect obvious leaks

So I tried to apply the suggested solution and use an unstripped version of my SW, Valgrind and libc. I did this for my SW and Valgrind, but I don't know how to build an unstripped version of libc in OpenWRT. I couldn't find the related makefile. Any ideas?

UPDATE: @Paul Floyd I tried your recommendation but it seems my valgrind is not even working for pwd:

root@OpenWrt:/opt# valgrind --tool=none pwd
==2919== Nulgrind, the minimal Valgrind tool
==2919== Copyright (C) 2002-2017, and GNU GPL'd, by Nicholas Nethercote.
==2919== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==2919== Command: pwd
==2919== 
vex mips->IR: unhandled instruction bytes: 0xE8 0x67 0x25 0xB3
==2919== 
==2919== Process terminating with default action of signal 4 (SIGILL)
==2919==    at 0x43B405: ??? (in /bin/busybox)
==2919==    by 0x4021A0C: ??? (in /lib/libc.so)
==2919== 
Illegal instruction
root@OpenWrt:/opt# 
AfterFray
  • 1,751
  • 3
  • 17
  • 22
eagle1903
  • 31
  • 5
  • What exactly is the killed message? – Paul Floyd Nov 14 '21 at 20:44
  • root@OpenWrt:/opt# valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./my_SW ==12453== Memcheck, a memory error detector ==12453== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==12453== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info ==12453== Command: ./my_SW ==12453== Killed root@OpenWrt:/opt# – eagle1903 Nov 15 '21 at 18:52

1 Answers1

0

My advice is to start simple.

Get 'valgrind --tool=none pwd' or something similar working.

Don't add '--track-origins=yes' unless you have an error such as a "Conditional jump or move depends on uninitialised value(s)" and you can't find the problem from the error message.

Again you don't need the 'leak' options to begin with. Run without them, then add them as needed if the summary says that there are leaks.

You shouldn't need libc debuginfo. It will make the error callstacks a bit clearer but Valgrind should work OK without it.

You could compare the output with " --tool=none --trace-redir=yes " on both your Ubuntu box and the OpenWRT box.

You should see somethinglike

paulf> ./vg-in-place --tool=none --trace-redir=yes pwd 2>&1 | grep Reading
--42969-- Reading syms from /bin/pwd
--42969-- Reading syms from /libexec/ld-elf.so.1
--42969-- Reading syms from /usr/home/paulf/scratch/valgrind/none/none-amd64-freebsd
--42969-- Reading syms from /usr/home/paulf/scratch/valgrind/coregrind/vgpreload_core-amd64-freebsd.so
--42969-- Reading syms from /lib/libc.so.7
--42969-- Reading syms from /lib/libc.so.

The paths and filenames may differ, but it should always be

  1. executable
  2. dynamic loader lib
  3. valgrind tool
  4. valgrind core
  5. dynamic libraries linked to executable

If you don't see "Reading syms from libc.so" then Valgrind will not be able to intercept calls to malloc and free.

Lastly you can look at the output with --trace-symtab=yes. That will be very long, but again there should not be any inexplicable majosr differences between the two platforms.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
  • On Ubuntu the command output is very similar to yours but on OpenWRT: root@OpenWrt:/opt# valgrind --tool=none --trace-redir=yes pwd 2>&1 | grep Reading --2893-- Reading syms from /usr/lib/valgrind/none-mips32-linux --2893-- Reading syms from /usr/lib/valgrind/vgpreload_core-mips32-linux.so Illegal instruction root@OpenWrt:/opt# – eagle1903 Nov 15 '21 at 18:54
  • If Valgrind itself is generating a SIGILL then there is either some issue with compiling Valgrind or some hardware problem. – Paul Floyd Nov 15 '21 at 22:56
  • By the way I first thought the problem may be related with my self-built openWRT and Valgrind. So I flashed the pre-built OpenWRT image provided on the OpenWRT website into my target and then installed the standard Valgrind package. But the same problems are still there! The issues are either target-specific (TP-Link Archer C7) or CPU architecture-specific (MIPS). I think Valgrind should be working on some other OpenWRT platforms because they provided a package for it :) I'll use Valgrind only on Ubuntu for now... – eagle1903 Nov 27 '21 at 13:23