https://bugs.kde.org/show_bug.cgi?id=422601
Bug ID: 422601
Summary: valgrind throwns 'has_nonempty_rw' assertion failure
on dlopen() if other mappings exist
Product: valgrind
Version: 3.15 SVN
Platform: Gentoo Packages
OS: Linux
Status: REPORTED
Severity: crash
Priority: NOR
Component: general
Assignee: jsew...@acm.org
Reporter: laurent.pinch...@ideasonboard.com
Target Milestone: ---
Created attachment 129131
--> https://bugs.kde.org/attachment.cgi?id=129131=edit
Test case that exhibits the issue
SUMMARY
When processing the mmap() calls from dlopen(), valgrind loads debug symbols
from the ELF library being opened. If conflicting other mappings were
previously created, a 'has_nonempty_rw' assertion failure is thrown.
STEPS TO REPRODUCE
1. Compile the attached test case with 'gcc -o valgrind-test -lm
valgrind-test.c'
2. Run 'valgrind ./valgrind-test'
OBSERVED RESULT
==23177== Memcheck, a memory error detector
==23177== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==23177== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h
for copyright info
==23177== Command: ./valgrind-test
==23177==
--23177-- Valgrind options:
--23177---v
--23177-- Contents of /proc/version:
--23177-- Linux version 5.4.28-gentoo (root@pendragon) (gcc version 8.3.0
(Gentoo 8.3.0-r1 p1.1)) #1 SMP PREEMPT Fri Apr 17 17:51:31 EEST 2020
--23177--
--23177-- Arch and hwcaps: AMD64, LittleEndian,
amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand
--23177-- Page sizes: currently 4096, max supported 4096
--23177-- Valgrind library directory: /usr/lib64/valgrind
--23177-- Reading syms from /home/laurent/src/test/valgrind-test
--23177-- Reading syms from /lib64/ld-2.30.so
--23177-- Considering /usr/lib/debug/lib64/ld-2.30.so.debug ..
--23177-- .. CRC is valid
--23177-- Reading syms from /usr/lib64/valgrind/memcheck-amd64-linux
--23177-- Considering
/usr/lib/debug/usr/lib64/valgrind/memcheck-amd64-linux.debug ..
--23177-- .. CRC is valid
--23177--object doesn't have a dynamic symbol table
--23177-- Scheduler: using generic scheduler lock implementation.
--23177-- Reading suppressions file: /usr/lib64/valgrind/default.supp
==23177== embedded gdbserver: reading from
/tmp/vgdb-pipe-from-vgdb-to-23177-by-laurent-on-???
==23177== embedded gdbserver: writing to
/tmp/vgdb-pipe-to-vgdb-from-23177-by-laurent-on-???
==23177== embedded gdbserver: shared mem
/tmp/vgdb-pipe-shared-mem-vgdb-23177-by-laurent-on-???
==23177==
==23177== TO CONTROL THIS PROCESS USING vgdb (which you probably
==23177== don't want to do, unless you know exactly what you're doing,
==23177== or are doing some strange experiment):
==23177== /usr/lib64/valgrind/../../bin/vgdb --pid=23177 ...command...
==23177==
==23177== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==23177== /path/to/gdb ./valgrind-test
==23177== and then give GDB the following command
==23177== target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=23177
==23177== --pid is optional if only one valgrind process is running
==23177==
--23177-- REDIR: 0x401e290 (ld-linux-x86-64.so.2:strlen) redirected to
0x580c9122 (vgPlain_amd64_linux_REDIR_FOR_strlen)
--23177-- REDIR: 0x401e070 (ld-linux-x86-64.so.2:index) redirected to
0x580c913c (vgPlain_amd64_linux_REDIR_FOR_index)
--23177-- Reading syms from /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
--23177-- Considering
/usr/lib/debug/usr/lib64/valgrind/vgpreload_core-amd64-linux.so.debug ..
--23177-- .. CRC is valid
--23177-- Reading syms from
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
--23177-- Considering
/usr/lib/debug/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so.debug ..
--23177-- .. CRC is valid
==23177== WARNING: new redirection conflicts with existing -- ignoring it
--23177-- old: 0x0401e290 (strlen ) R-> (.0) 0x580c9122
vgPlain_amd64_linux_REDIR_FOR_strlen
--23177-- new: 0x0401e290 (strlen ) R-> (2007.0) 0x04839db0
strlen
--23177-- REDIR: 0x401aab0 (ld-linux-x86-64.so.2:strcmp) redirected to
0x483ae00 (strcmp)
--23177-- REDIR: 0x401e7d0 (ld-linux-x86-64.so.2:mempcpy) redirected to
0x483e6d0 (mempcpy)
--23177-- Reading syms from /lib64/libdl-2.30.so
--23177-- Considering /usr/lib/debug/lib64/libdl-2.30.so.debug ..
--23177-- .. CRC is valid
--23177-- Reading syms from /lib64/libc-2.30.so
--23177-- Considering /usr/lib/debug/lib64/libc-2.30.so.debug ..
--23177-- .. CRC is valid
--23177-- REDIR: 0x4940660 (libc.so.6:memmove) redirected to 0x482c1b0
(_vgnU_ifunc_wrapper)
--23177-- REDIR: 0x493f9e0 (libc.so.6:strncpy) redirected to 0x482c1b0
(_vgnU_ifunc_wrapper)
--23177-- REDIR: 0x4940970 (libc.so.6:strcasecmp) redirected to 0x482c1b0
(_vgnU_ifunc_wrapper)
--23177-- REDIR: 0x493f320 (libc.so.6:strcat) redirected to 0x482c1b0
(_vgnU_ifunc_wrapper)
--23177--