Reputation: 57
I want to use valgrind to see if my program has memory errors.
I want to run the program on Alpine linux which has different standard c library (musl vs glibc).
Here is and example output on "echo" command with valgrind on the Alpine linux:
/ # valgrind echo "hi"
==480== Memcheck, a memory error detector
==480== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==480== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==480== Command: echo hi
==480==
hi
==480==
==480== HEAP SUMMARY:
==480== in use at exit: 0 bytes in 0 blocks
==480== total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==480==
==480== All heap blocks were freed -- no leaks are possible
==480==
==480== For lists of detected and suppressed errors, rerun with: -s
==480== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
As expected there are no problems in "echo" program.
When I run my program with valgrind on Alpine (passing--track-origins=yes, --leak-check=full doesn't cause any change):
/ # valgrind work/test_lib
==481== Memcheck, a memory error detector
==481== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==481== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==481== Command: work/test_lib
==481==
Please pass path to lib + config + (optional data_json) (optional output path)
/ #
The summary is missing. I don't see any errors. The program itself is very simple - just prints the lines after checking the program didn't receive 2 input parameters. Also when I run the program with arguments, it runs correctly and prints the right output result. There is no valgrind summary output after program ends in both cases.
In the other machine (Centos) valgrind indeed print valgrind summary output in the end (which is clean of problems).
The program was complied with gcc-4.8 and glibc, but without any special dependencies:
g++ -Wall --std=c++11 -ldl -march=x86-64 -msse2 -msse3 -msse4 test_lib.cpp -o test_lib
/ # ldd work/test_lib
/lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fc52c0cd000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc52c0af000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
I was expecting to see valgrind summary report after running my program with valgrind on Alpine linux.
Upvotes: 1
Views: 190
Reputation: 57
OK, The code that is being executed is:
if (argc <= 2) { printf("Please pass path to lib + ...\n"); return -1; }
I don't see a reason to add "--trace-children=yes" to cause valgrind to work in this case.
But Alpine (since it was compiled with glibc) causes this to create a child process. Adding "--trace-children=yes" solves the problem in Alpine for programs that were compiled with glibc.
I tried to track the "child" process using ps -ef | more
valgrind --trace-children=yes /lib/ld-musl-x86_64.so.1 --argv0 ./test_lib --preload /lib/libgcompat.so.0 /usr/libexec/valgrind/vgpreload_core-amd64-linux.so:/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so -- /work/test_lib
when running "valgrind echo hi", I don't see all those "--preload"
Upvotes: 1