|
From: Andrejs B. <sin...@gm...> - 2014-05-21 11:15:02
|
Hi there! I'm quite new to Linux and was trying to use Valgrind for
finding leaks on 32-bit Linux ARMv7 (3.6.0, armv7l).
I crosscompiled Valgrind using non-stripped version of uClibc library.
I tried Valgrind version 3.9.0 and then newest from SVN (13985).
ldd's output for valgrind:
/# ldd /usr/bin/valgrind
ldd: can't open cache '/etc/ld.so.cache'
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb6f27000)
libc.so.0 => /lib/libc.so.0 (0xb6ed2000)
ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0xb6f3a000)
I tried detecting obvious leak in an example:
/* leak.c */
#include <stdlib.h>
int main()
{
int *x = malloc(10 * sizeof(int));
return 0;
}
On Linux/x86-64 leak was detected.
On Linux/ARM using --trace-redir=yes option I've found that
vgpreload_core-arm-linux.so and vgpreload_memcheck-arm-linux.so files
are not being read.
Using strace on Valgrind I found that vgpreload_memcheck-arm-linux.so
is accessed, but not used
(access("/usr/lib/valgrind/vgpreload_memcheck-arm-linux.so", R_OK) = 0).
I've checked ld-uClibc-0.9.33.2.so, libuClibc-0.9.33.2.so and
Valgrind's *.so files using 'file' and 'readelf'. They are not
stripped.
Also, have checked libuClibc-0.9.33.2.so for 'malloc' with 'readelf -a
libuClibc-0.9.33.2.so | grep malloc'. It's there.
Have checked sonames. They are same as shown in Valgrind's log.
Full Valgrind log on Linux/ARM:
/# valgrind --trace-redir=yes ./leak
==3526== Memcheck, a memory error detector
==3526== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==3526== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==3526== Command: ./leak
==3526==
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_initialise) ------
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
--3526-- Reading syms from /transit/misc/leak
--3526-- svma 0x0000008338, avma 0x0000008338
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--3526-- TOPSPECS of soname NONE filename /transit/misc/leak
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
--3526-- Reading syms from /lib/ld-uClibc-0.9.33.2.so
--3526-- svma 0x0000000dc0, avma 0x0004000dc0
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--3526-- TOPSPECS of soname ld-uClibc.so.0 filename
/lib/ld-uClibc-0.9.33.2.so
--3526-- TOPSPECS of soname NONE filename /transit/misc/leak
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
--3526-- Reading syms from /usr/lib/valgrind/memcheck-arm-linux
--3526-- svma 0x00380000c0, avma 0x00380000c0
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--3526-- TOPSPECS of soname NONE filename
/usr/lib/valgrind/memcheck-arm-linux
--3526-- TOPSPECS of soname ld-uClibc.so.0 filename
/lib/ld-uClibc-0.9.33.2.so
--3526-- TOPSPECS of soname NONE filename /transit/misc/leak
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
--3526-- Reading syms from /lib/libgcc_s.so.1
--3526-- svma 0x0000003c58, avma 0x0004812c58
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--3526-- TOPSPECS of soname libgcc_s.so.1 filename /lib/libgcc_s.so.1
--3526-- TOPSPECS of soname NONE filename
/usr/lib/valgrind/memcheck-arm-linux
--3526-- TOPSPECS of soname ld-uClibc.so.0 filename
/lib/ld-uClibc-0.9.33.2.so
--3526-- TOPSPECS of soname NONE filename /transit/misc/leak
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
--3526-- Reading syms from /lib/libuClibc-0.9.33.2.so
--3526-- svma 0x000000a7b0, avma 0x000482c7b0
--3526-- <<
--3526-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--3526-- TOPSPECS of soname libc.so.0 filename /lib/libuClibc-0.9.33.2.so
--3526-- TOPSPECS of soname libgcc_s.so.1 filename /lib/libgcc_s.so.1
--3526-- TOPSPECS of soname NONE filename
/usr/lib/valgrind/memcheck-arm-linux
--3526-- TOPSPECS of soname ld-uClibc.so.0 filename
/lib/ld-uClibc-0.9.33.2.so
--3526-- TOPSPECS of soname NONE filename /transit/misc/leak
--3526-- TOPSPECS of soname (hardwired)
--3526-- ld-linux-armhf.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux.so.3 memcpy R->
(0000.0) 0x38075c50
--3526-- ld-linux-armhf.so.3 strlen R->
(0000.0) 0x38075c24
--3526-- ld-linux.so.3 strlen
R-> (0000.0) 0x38075c24
--3526-- ------ ACTIVE ------
--3526-- >>
==3526== Invalid read of size 4
==3526== at 0x4005550: _dl_get_ready_to_run (in /lib/ld-uClibc-0.9.33.2.so)
==3526== Address 0xbde78a9c is just below the stack ptr. To
suppress, use: --workaround-gcc296-bugs=yes
==3526==
==3526== Invalid read of size 4
==3526== at 0x4864C34: __uClibc_main (in /lib/libuClibc-0.9.33.2.so)
==3526== Address 0xbde78c6c is just below the stack ptr. To
suppress, use: --workaround-gcc296-bugs=yes
==3526==
==3526== Invalid read of size 4
==3526== at 0x4864A30: __uClibc_fini (in /lib/libuClibc-0.9.33.2.so)
==3526== Address 0xbde78c4c is just below the stack ptr. To
suppress, use: --workaround-gcc296-bugs=yes
==3526==
==3526== Invalid read of size 4
==3526== at 0x4000E1C: ??? (in /lib/ld-uClibc-0.9.33.2.so)
==3526== Address 0xbde78c34 is just below the stack ptr. To
suppress, use: --workaround-gcc296-bugs=yes
==3526==
==3526==
==3526== HEAP SUMMARY:
==3526== in use at exit: 0 bytes in 0 blocks
==3526== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==3526==
==3526== All heap blocks were freed -- no leaks are possible
==3526==
==3526== For counts of detected and suppressed errors, rerun with: -v
==3526== ERROR SUMMARY: 32 errors from 4 contexts (suppressed: 0 from 0)
On Linux/x86-64 using --trace-redir=yes I've found, that functions
from libc.so.0 are being redirected after
vgpreload_memcheck-amd64-linux.so is being read.
Excerpt from log:
>>
--6671-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
--6671-- svma 0x0000002f10, avma 0x0004c28f10
--6671-- <<
--6671-- ------ REDIR STATE after VG_(redir_notify_new_DebugInfo) ------
--6671-- TOPSPECS of soname NONE filename
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
--6671-- libc.so* setenv W->
(0000.0) 0x04c2f8a0
--6671-- libc.so* unsetenv W->
(0000.0) 0x04c2f800
--6671-- libc.so* putenv W->
(0000.0) 0x04c2f760
--6671-- libc.so* wcslen R->
(2037.0) 0x04c2f740
--6671-- libc.so* strcasestr R->
(2035.0) 0x04c2f680
--6671-- libc.so* strspn R->
(2034.0) 0x04c2f600
Also hardwired sonames are redirected on x86-64, but not on ARM.
But that's maybe cause soname 'ld-uClibc.so.0' differs from
'ld-linux.so.3' and 'ld-linux-armhf.so.3'.
Thank you very much in advance!
Best regards,
Andrejs
|