Paul Floyd [Sun, 17 Sep 2023 09:50:54 +0000 (11:50 +0200)]
FreeBSD: add syscall wrapper for membarrier (added in FreeBSD 15)
I also noticed that the Linux membarrier syscall wrapper
is out of date. It only takes one argument. Depending on the kernel
version it can also take 2 or 3 arguments (3 being the latest).
Paul Floyd [Sun, 10 Sep 2023 13:05:57 +0000 (15:05 +0200)]
Bug 474332 - aligned_alloc under Valgrind returns nullptr when alignment is not a multiple of sizeof(void *)
At configure time use glibc version to set a HAVE flag for C17 aligned_alloc.
The use the HAVE flag to select which redir macro to use.
Also make the (normally unused) glibc ALIGNED_ALLOC macro
the same as MEMALIGN, just in case.
Paul Floyd [Sun, 10 Sep 2023 08:39:34 +0000 (10:39 +0200)]
FreeBSD: close_range versioning issues
I mixed up a bit the syscall wrapper versioning.
Also for some reason the syscall has been backported to FreeBSD 12.2
but not the CLOEXEC flag. So I had to modify the testcase for that.
Andreas Arnez [Thu, 7 Sep 2023 15:00:42 +0000 (17:00 +0200)]
s390x regtest: Reduce test output for vector test cases
The s390x test cases `vector', `vector_integer', `vector_float' and
`vector_string' generate a lot of unnecessary output, because for each
tested instruction they usually dump more registers than the instruction
modifies.
Without changing the test approach itself and without losing information,
the output can still be reduced significantly by comparing the register
states before and after the tested instruction and then only dumping the
changed parts.
Andreas Arnez [Thu, 7 Sep 2023 14:43:25 +0000 (16:43 +0200)]
s390x regtest: Build DFP test cases unconditionally
Now that the DFP test cases no longer depend on the compiler's support for
`_Decimal*' types, they can be enabled unconditionally. Do this in the
"Makefile.am".
Andreas Arnez [Thu, 7 Sep 2023 14:43:25 +0000 (16:43 +0200)]
s390x regtest: Rework pfpo
The pfpo test case relies on `_Decimal*' type support, which currently
excludes Clang. Rework the test to avoid this. Also, fix a typo that
causes conversions to 64-bit decimal types to be shown as "-> d6" instead
of "-> d64" in the output. Adjust the output file accordingly.
Andreas Arnez [Thu, 7 Sep 2023 14:43:25 +0000 (16:43 +0200)]
s390x regtest: Rework dfpext
The dfpext test case uses `_Decimal*' types and thus cannot be compiled
with Clang. Avoid this. Also, remove a duplicate in the set of tested
values and adjust the output file accordingly.
Andreas Arnez [Thu, 7 Sep 2023 14:43:25 +0000 (16:43 +0200)]
s390x regtest: Rework dfpconv
The dfpconv test case has two major issues:
* It truncates certain 64-bit integers to 32 bits when using them as
inputs or outputs to inline assemblies. In particular this leads to
wrong output.
* It uses `_Decimal*' types and thus cannot be compiled with Clang.
Fix both. Also, remove a duplicate from the set of tested numbers, remove
the dependency on "opcodes.h", and fix indentation. Since the test output
file dfpconv.stdout.exp is affected by these changes, adjust it
accordingly.
Andreas Arnez [Thu, 7 Sep 2023 14:43:25 +0000 (16:43 +0200)]
s390x regtest: Rework dfp-2
The dfp-2 test case has two issues:
* It doesn't test the rounding modes correctly. Since the inline assembly
uses a "d" constraint to pass the rounding mode, a random register
number is placed into the instruction's rounding mode field instead of
the intended rounding mode.
* It cannot be compiled with Clang. (See Bug 465782.)
Fix these with a rewrite. Fixing the first issue also requires adjusting
the test case output `dfp-2.stdout.exp', while fixing the second requires
avoiding `_Decimal*' data types. Also reduce some code duplication.
Andreas Arnez [Thu, 7 Sep 2023 14:43:24 +0000 (16:43 +0200)]
Bug 472875 - s390x regtest: Rework dfp-1
The dfp-1 test case has two main issues:
* It doesn't initialize the condition code before executing the DFP
instructions for "multiply" and "divide", but asserts a certain value
afterwards. (See Bug 472875.)
* It doesn't compile with Clang. (See Bug 465782.)
Fix these with a rework. The first issue can be fixed by initializing the
condition code before executing the DFP instructions. The second issue
requires avoiding any `_Decimal*' types, since they are not supported by
Clang.
Andreas Arnez [Thu, 7 Sep 2023 14:43:24 +0000 (16:43 +0200)]
s390x regtest: Reduce pfpo test case output
The `pfpo' test case prints floating-point values with the "%f" and "%Lf"
formats. Sometimes also "%lf" is used, but that's equivalent to "%f"
since the "l" length modifier doesn't affect floating-point formatting.
These "f"-style formats are not well suited for such a test case:
* They generate excessively long output for numbers with large absolute
values. This makes `pfpo.stdout.exp' difficult to handle.
* They can lose precision, in particular for numbers close to zero, where
they just print zeros.
Use the formats "%a" and "%La" instead and adjust pfpo.stdout.exp
accordingly.
Paul Floyd [Sat, 2 Sep 2023 15:33:35 +0000 (17:33 +0200)]
regtest: silence some more warnings
A massif test that checks that --ignore-fn
Sadly neither C nor C++ has a standard way of specifying functons
to _never_ inline, and GCC and LLVM seem to have different extensions.
GCC complains about __attribute__((optnone)).
Paul Floyd [Sat, 2 Sep 2023 15:12:23 +0000 (17:12 +0200)]
regtest: silence a few warnings
A couple of testcases that use 'new' that will throw an
uncaught exception. The variable doesn't get used, there
is only an assert to check that nothing is reached after the
new expressions.
Paul Floyd [Sun, 12 Mar 2023 07:26:04 +0000 (08:26 +0100)]
Add memcheck errors for aligned and sized allocations and deallocations
Bug 433857 Add validation to C++17 aligned new/delete alignment size
Bug 433859 Add mismatched detection to C++ 17 aligned new/delete
Bug 466105 aligned_alloc problems, part 2
Bug 467441 Add mismatched detection to C++ 14 sized delete
Memcheck now tests and warns about the values used for
alignment and size. These apply to various functions: memalign,
posix_memalign and aligned_alloc in C and various overloads
of operators new and delete in C++. The kinds of error that can
be detected are
- invalid alignment, for instance the alignment is usually required
to be a power of 2
- mismatched alignment between aligned allocation and aligned
deallocation
- mismatched size when sized delete is used
- bad size for functions that have implementation defined behaviour
when the requested size is zero
An example of the new errors is:
int *pi = memalign(31, 100);
which will generate the following error
==96206== Invalid alignment value: 31 (should be power of 2)
==96206== at 0x485195E: memalign (vg_replace_malloc.c:1886)
==96206== by 0x20200E: main (memalign.c:59)
Mark Wielaard [Fri, 1 Sep 2023 17:10:17 +0000 (19:10 +0200)]
Explicitly load libc and any sonames that contain mandatory specs
We really need symtab for glibc and ld.so libraries early for redir.
Some distros move these into separate debuginfo files, which means
we need to fully load them early.
Aaron Merey [Wed, 30 Aug 2023 18:49:09 +0000 (14:49 -0400)]
Fix lazy debuginfo loading on ppc64le
Lazy debuginfo loading introduced in commit 60f7e89ba32 assumed that
either describe_IP or find_DiCfSI will be called before stacktrace
printing. describe_IP and find_DiCfSI cause debuginfo to be lazily
loaded before symtab lookup occurs during stacktraces.
However this assumption does not hold true on ppc64le, resulting
in debuginfo failing to load in time for stacktraces. Fix this
by loading debuginfo during get_StackTrace_wrk on ppc arches.
Condition to consider segments will be merged has to be more specific
than just having a page rounded file offset p_offset.
Regtested on debian, somewhat poorly due to the amount of tests
failing due to:
473745 must-be-redirected function - strlen - for valgrind 3.22 but not 3.21
Paul Floyd [Sun, 27 Aug 2023 16:29:30 +0000 (18:29 +0200)]
FreeBSD: Add a new testcase for FreeBSD 14 _umtx_op set timeout
Uses an existing testcase with pthread APIs that use timeouts
and sets LIBPTHREAD_UMTX_MIN_TIMEOUT to 100 (ns, so almost no
effect other than exercising the syscall).
Paul Floyd [Sun, 27 Aug 2023 07:35:03 +0000 (09:35 +0200)]
Allow spaces in .valgrindrc files
The patch for m_commandline.c comes from the Debian package files.
Also add a regtest and allow --command-line-only=no to override
--command-line-only=yes
Mark Wielaard [Thu, 17 Aug 2023 13:40:30 +0000 (15:40 +0200)]
gdb --multi mode stdout redirecting to stderr
When in stdio mode (talking to gdb through stdin/stdout, not
through a socket), redirect stdout to stderr and close stdin
for the inferior. That way at least some output can be seen,
but there will be no input.
This is workaround till we have real terminal handling.
* coregrind/vgdb.c (main): Pass in_port to do_multi_mode.
(do_multi_mode): Pass in_port to fork_and_exec_valgrind.
(fork_and_exec_valgrind): Close stdin, redirect stdout to
stderr if in_port <= 0.
Paul Floyd [Sat, 19 Aug 2023 19:37:33 +0000 (21:37 +0200)]
Always cleanup on exit from ML_(read_elf_object)
I'm still a but baffled as to why this wasn't seen earlier.
A FreeBSD testcase started failing with kernel 13.2 patch 2,
which is quite a minor change. The testcase gets an fd from
pdfork and the parent does a printf with the fd then zaps the
process with pdkill. Standalone the fd is 3, and that's what
the expected contains. However, when it started failing I saw
with lsof that fds 3 and 4 were associated with the guest exe
and ld-elf.so.1.
Aaron Merey [Fri, 30 Jun 2023 22:31:42 +0000 (18:31 -0400)]
Support lazy reading and downloading of DWARF debuginfo
Currently valgrind attempts to read DWARF .debug_* sections as well
as separate debuginfo files for ELF binaries as soon as a shared library
is loaded. This might also result in the downloading of separate debuginfo
files via debuginfod.
This is inefficient when some of this debuginfo never ends up being used
by valgrind while running the client process.
This patch adds support for lazy reading and downloading of DWARF
debuginfo. When an ELF shared library is loaded, the reading of .debug_*
sections as well as separate or alternate debuginfo is deferred until
valgrind handles an instruction pointer corresponding to a text segment
of the shared library. At this point the deferred sections and separate
debug files are loaded.
This feature is only supported on ELF platforms.
https://bugs.kde.org/show_bug.cgi?id=471807
ChangeLog
* debuginfo.c (di_notify_ACHIEVE_ACCEPT_STATE): Replace
read_elf_debug_info with read_elf_object.
(addr_load_di): New function. Attempts to load deferred debuginfo
associated with a given address.
(load_di): New function. Attempts to load a given deferred
debuginfo associated with a given address.
(describe_IP): Add calls to load_di and addr_load_di.
(find_DiCfSI): Add call to load_di.
* priv_readelf.h (read_elf_object): New declaration.
(read_elf_debug): Ditto.
* priv_storage.h (struct _DebugInfo): New field 'bool deferred'.
* readelf.c (read_elf_debug_info): Split into read_elf_object and
read_elf_debug.
(read_elf_object): Read non .debug_* section from an ELF binary.
(read_elf_debug): Read .debug_* sections from an ELF binary as
as well any separate/alternate debuginfo files.
* storage.c (canonicaliseSymtab): Remove assert in order to support
canonicalization of deferred _DebugInfo.
(finish_CFSI_arrays): Add early return if _DebugInfo is
deferred in order to avoid freeing memory that will be needed
when reading debuginfo at a later time.
(canonicaliseTables): Ditto.
* pub_core_debuginfo.h (addr_load_di): New declaration.
(load_di): New declaration.
Andreas Arnez [Mon, 22 May 2023 17:49:08 +0000 (19:49 +0200)]
Bug 470132 - s390x: Increase test coverage for VGM
Add more tests for the VGM instruction, to verify the fix for the VGM
wrap-around case. Also test setting unused bits in the I2 and I3 fields,
to check that Valgrind ignores them as it should.
Andreas Arnez [Mon, 22 May 2023 16:57:35 +0000 (18:57 +0200)]
Bug 470132 - s390x: Fix the wrap-around case in VGM
Valgrind's implementation of VGM is incomplete:
* It doesn't support generating a wrap-around bit mask. Such a mask
should result when the ending bit position is smaller than the starting
bit position. Valgrind runs into an assertion failure instead.
* It doesn't ignore unused bits in the I2 and I3 fields of the
instruction, as it should.
Fix this by re-implementing the main logic in s390_irgen_VGM().
Paul Floyd [Sun, 2 Jul 2023 10:59:40 +0000 (12:59 +0200)]
FreeBSD: add default to configure.ac FreeBSD 13 versions
Also add comment to README.freebsd about ensuring that
jails set "uname -r" to be something compatible with the
normal RELEASE/STABLE/CURRENT releases.
Andreas Arnez [Thu, 15 Jun 2023 15:24:53 +0000 (17:24 +0200)]
Bug 470978 - s390x: Link the tools with -Wl,--s390-pgste
Programs that require the PGSTE mode to be enabled may currently fail
under Valgrind. In particular this affects qemu-kvm.
While it is also possible to enable the PGSTE mode globally with
sysctl vm.allocate_psgte=1
the problem can more easily be prevented by linking the Valgrind tools
with -Wl,--s390-pgste. Add a configure check if the linker supports this,
and activate the flag if it does.
To verify the intended result, the following shell command can be used to
list the executables having this flag set:
The bne instruction expects an absolute target address and it isn't
best-suited for implementing a short range jump, such as the one in
XCHG_M_R().
Replace it with jne which expects a relative address that can be
correctly computed a link time.
Interestingly, the jump is almost never taken. If it would, this would
crash the test. However, linkers may complain when relacating the
target address used in bne.
Paul Floyd [Wed, 7 Jun 2023 20:27:08 +0000 (22:27 +0200)]
Bug 470713 - Failure on the Yosys project: valgrind: m_libcfile.c:1802 (Bool vgPlain_realpath(const HChar *, HChar *)): Assertion 'resolved' failed
When using sysctl kern proc pathname with the pid of the guest or -1
we need to intercept the call otherwise the syscall will return the path
of the memcheck tool and not the path of the guest.
This uses VG_(realpath), which asserts if it doesn't get valid
input pointers.
sysctl kern proc pathname can use a NULL pointer in order to
determine the length of the path (so users can allocate the minumum
necessary). The NULL pointer was being passed on to VG_(realpath)
without being checked, resulting in an assert.
Mark Wielaard [Thu, 1 Jun 2023 14:10:56 +0000 (16:10 +0200)]
memcheck: Handle Err_ReallocSizeZero in MC_(eq_Error)
When an realloc size zero error is emitted MC_(eq_Error) is called to
see if the errors can be deduplicated. This crashed since
Err_ReallocSizeZero wasn't handled. Handle it like Err_Free.
Also add a testcase for this case and test with both
--realloc-zero-bytes-frees=yes and
--realloc-zero-bytes-frees=no.
Which will report a different number of errors.
Mark Wielaard [Sun, 14 May 2023 21:34:05 +0000 (23:34 +0200)]
Add --with-gdbscripts-dir=PATH configure option
Currently the gdb valgrind scripts are installed under VG_LIBDIR
which is normally pkglibexecdir which is likely not in the default
gdb safe-path (a list of directories from which it is safe to
auto-load files). So users will have to add the directory to their
.gdbinit file.
This patch adds a --with-gdbscripts-dir=PATH configure option that
sets VG_GDBSCRIPTS_DIR to the given PATH (${libexecdir}/valgrind if
not given). A user can also configure --without-gdbscripts-dir to
disable adding a .debug_gdb_scripts section to the vgpreload library
and installing the valgrind-monitor python scripts completely.
Use VG_GDBSCRIPTS_DIR as gdbscriptsdir to install the valgrind-monitor
python files and pass it with CPPFLAGS when building vg_preloaded.c
and vgdb.c to use instead of VG_LIBDIR.