|
Message-ID: <20200329004418.GQ11469@brightrain.aerifal.cx> Date: Sat, 28 Mar 2020 20:44:18 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Cc: Andrew McKinlay <mckinlay.andrew@...il.com> Subject: Re: Valgrind errors when running simple program On Sat, Mar 28, 2020 at 04:39:38PM -0700, Andrew McKinlay wrote: > Running > > ``` > int main(void) { > } > ``` > > through Valgrind produces errors: > > ``` > ubuntu@...mary:~/env_stuff$ valgrind --leak-check=full > --show-leak-kinds=all -v ./a.out > ==3492== Memcheck, a memory error detector > ==3492== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. > ==3492== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info > ==3492== Command: ./a.out > ==3492== > --3492-- Valgrind options: > --3492-- --leak-check=full > --3492-- --show-leak-kinds=all > --3492-- -v > --3492-- Contents of /proc/version: > --3492-- Linux version 4.15.0-91-generic (buildd@...01-amd64-013) > (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #92-Ubuntu SMP Fri > Feb 28 11:09:48 UTC 2020 > --3492-- > --3492-- Arch and hwcaps: AMD64, LittleEndian, > amd64-cx16-lzcnt-sse3-avx-avx2-bmi > --3492-- Page sizes: currently 4096, max supported 4096 > --3492-- Valgrind library directory: /usr/lib/valgrind > --3492-- Reading syms from /home/ubuntu/env_stuff/a.out > --3492-- Reading syms from /lib/x86_64-linux-musl/libc.so > --3492-- object doesn't have a symbol table > --3492-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux > --3492-- Considering /usr/lib/valgrind/memcheck-amd64-linux .. > --3492-- .. CRC mismatch (computed 41ddb025 wanted 9972f546) > --3492-- object doesn't have a symbol table > --3492-- object doesn't have a dynamic symbol table > --3492-- Scheduler: using generic scheduler lock implementation. > --3492-- Reading suppressions file: /usr/lib/valgrind/default.supp > ==3492== embedded gdbserver: reading from > /tmp/vgdb-pipe-from-vgdb-to-3492-by-ubuntu-on-??? > ==3492== embedded gdbserver: writing to > /tmp/vgdb-pipe-to-vgdb-from-3492-by-ubuntu-on-??? > ==3492== embedded gdbserver: shared mem > /tmp/vgdb-pipe-shared-mem-vgdb-3492-by-ubuntu-on-??? > ==3492== > ==3492== TO CONTROL THIS PROCESS USING vgdb (which you probably > ==3492== don't want to do, unless you know exactly what you're doing, > ==3492== or are doing some strange experiment): > ==3492== /usr/lib/valgrind/../../bin/vgdb --pid=3492 ...command... > ==3492== > ==3492== TO DEBUG THIS PROCESS USING GDB: start GDB like this > ==3492== /path/to/gdb ./a.out > ==3492== and then give GDB the following command > ==3492== target remote | /usr/lib/valgrind/../../bin/vgdb --pid=3492 > ==3492== --pid is optional if only one valgrind process is running > ==3492== > --3492-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so > --3492-- Considering /usr/lib/valgrind/vgpreload_core-amd64-linux.so .. > --3492-- .. CRC mismatch (computed 50df1b30 wanted 4800a4cf) > --3492-- object doesn't have a symbol table > --3492-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so > --3492-- Considering /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so .. > --3492-- .. CRC mismatch (computed f893b962 wanted 95ee359e) > --3492-- object doesn't have a symbol table > --3492-- REDIR: 0x402a660 (NONE:free) redirected to 0x4cb3cd0 (free) > ==3492== Invalid free() / delete / delete[] / realloc() > ==3492== at 0x4CB3D3B: free (in > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==3492== by 0x40717F3: ??? (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF000FAB: ??? > ==3492== by 0x1FFF00022F: ??? > ==3492== by 0x1FFEFFFE9F: ??? > ==3492== by 0x4072D1E: ??? (in /lib/x86_64-linux-musl/libc.so) > ==3492== Address 0x4ebe160 is in a rw- mapped file > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so segment > ==3492== > --3492-- REDIR: 0x4029f10 (NONE:calloc) redirected to 0x4cb4a70 (calloc) > Error relocating /usr/lib/valgrind/vgpreload_core-amd64-linux.so: > __libc_freeres: symbol not found > ==3492== Jump to the invalid address stated on the next line > ==3492== at 0x556: ??? > ==3492== by 0x406F8B8: _exit (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF0006FE: ??? > ==3492== Address 0x556 is not stack'd, malloc'd or (recently) free'd > ==3492== > ==3492== > ==3492== Process terminating with default action of signal 11 (SIGSEGV) > ==3492== Bad permissions for mapped region at address 0x556 > ==3492== at 0x556: ??? > ==3492== by 0x406F8B8: _exit (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF0006FE: ??? > ==3492== > ==3492== HEAP SUMMARY: > ==3492== in use at exit: 404 bytes in 1 blocks > ==3492== total heap usage: 1 allocs, 1 frees, 404 bytes allocated > ==3492== > ==3492== Searching for pointers to 1 not-freed blocks > ==3492== Checked 32,584 bytes > ==3492== > ==3492== 404 bytes in 1 blocks are still reachable in loss record 1 of 1 > ==3492== at 0x4CB4B25: calloc (in > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==3492== by 0x40729D9: ??? (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x4073933: __dls3 (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF0006FE: ??? > ==3492== > ==3492== LEAK SUMMARY: > ==3492== definitely lost: 0 bytes in 0 blocks > ==3492== indirectly lost: 0 bytes in 0 blocks > ==3492== possibly lost: 0 bytes in 0 blocks > ==3492== still reachable: 404 bytes in 1 blocks > ==3492== suppressed: 0 bytes in 0 blocks > ==3492== > ==3492== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) > ==3492== > ==3492== 1 errors in context 1 of 2: > ==3492== Jump to the invalid address stated on the next line > ==3492== at 0x556: ??? > ==3492== by 0x406F8B8: _exit (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF0006FE: ??? > ==3492== Address 0x556 is not stack'd, malloc'd or (recently) free'd > ==3492== > ==3492== > ==3492== 1 errors in context 2 of 2: > ==3492== Invalid free() / delete / delete[] / realloc() > ==3492== at 0x4CB3D3B: free (in > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==3492== by 0x40717F3: ??? (in /lib/x86_64-linux-musl/libc.so) > ==3492== by 0x1FFF000FAB: ??? > ==3492== by 0x1FFF00022F: ??? > ==3492== by 0x1FFEFFFE9F: ??? > ==3492== by 0x4072D1E: ??? (in /lib/x86_64-linux-musl/libc.so) > ==3492== Address 0x4ebe160 is in a rw- mapped file > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so segment > ==3492== > ==3492== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) > ``` It looks like you're running valgrind from a glibc host with dynamic-linked musl program as guest, and it's loading valgrind libraries from the host (glibc) ecosystem into the musl-linked program's memory space. This is almost certainly going to blow up badly. It also looks like you didn't build with -g for anything, so it's hard to tell where the crash is happening. Presumably it doesn't happen when you just execute the program, only under valgrind? > I am attempting to set up Valgrind to find bugs in musl's environment > functions, but I can't even get a basic program to validate. Any ideas > for what I need to do next? I missed the conversation but this sounds like something that was on IRC earlier. If so, I think the hypothesis that something's wrong in the environment functions is mistaken. They track which entries were allocated by setenv and passing to free is conditional on the entry being allocated by setenv. If there's an actual problem you're encountering you should probably start from there with a minimal test case to reproduce what's happening. > Versions: > > ``` > ubuntu@...mary:~/env_stuff$ /lib/x86_64-linux-musl/libc.so > musl libc (x86_64) > Version 1.1.19 > Dynamic Program Loader > Usage: /lib/x86_64-linux-musl/libc.so [options] [--] pathname [args] This is from before there was support for malloc interposition, so that might be a factor in valgrind blowing up. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.