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.
Andreas Arnez [Thu, 26 Jan 2023 16:41:18 +0000 (17:41 +0100)]
s390x: XC instruction: clear in 8-byte increments if possible
The XC instruction is frequently executed in many programs, mainly for
clearing memory. It can target from 1 to 256 bytes. If the size is
constant and XC is actually used for clearing memory, Valgrind implements
it as a byte-wise loop and rolls out the loop for <= 8 bytes.
Instead of clearing byte-wise, it is more efficient to clear in 64-bit
increments, so do this for sizes >= 8 bytes. Roll out the loop for up to
32 bytes. Overall, this reduces the number of insns by a few percent and
provides a slight performance improvement for some programs.
Andreas Arnez [Fri, 5 May 2023 15:48:31 +0000 (17:48 +0200)]
s390x: Optimize CLC for 1, 2, 4, and 8 bytes
The CLC instruction compares two memory areas with sizes from 1 up to 256
bytes. Currently Valgrind always implements it with a bytewise loop.
Add special handling for the sizes 1, 2, 4, and 8. Realize CLC with an
8-, 16-, 32-, and 64-bit integer comparison, respectively, in those cases.
Apart from a slight optimization this also improves the diagnostics for
uninitialized values since it avoids the manufactured conditional jump
that breaks out of the loop over the individual bytes.
Andreas Arnez [Wed, 15 Feb 2023 17:02:37 +0000 (18:02 +0100)]
Bug 465782 - s390x: Avoid __builtin_setjmp
Currently Clang doesn't support __builtin_setjmp() on s390x. Since
Valgrind already has an alternate implementation of setjmp/longjmp for
many other platforms, just add one for s390x as well, to get rid of this
dependency.
Andreas Arnez [Thu, 1 Sep 2022 13:03:01 +0000 (15:03 +0200)]
Bug 465782 - s390x: Drop -mzarch -march=z900 from assembler options
The -mzarch flag is unsupported by Clang, and it is redundant on 64-bit
build systems. Remove it.
Also remove '-march=z900', since it is unsupported by Clang as well. It
would only be needed on build systems with a default architecture lower
than z900. Such systems are out of service for some time now.
Paul Floyd [Fri, 5 May 2023 20:05:36 +0000 (22:05 +0200)]
Add Helgrind and DRD tests and suppressions for getaddrinfo on Linux
Bump version to 3.22.0.GIT
The testcase was posted on the freebsd-hackers mailing list.
I had time to get suppressions for FreeBSD into 3.21 but
ran out of time for the test and Linux suppressions.
I did take a look at how thread sanitizer handles this.
Basically it intercepts the call, turns off checking,
calls the resl function then turns checking back on.
I don't see many other similar examples. Might be worth
looking at dlopen and atexit.
Mark Wielaard [Fri, 28 Apr 2023 11:34:48 +0000 (13:34 +0200)]
Support SCV_FLAG also on VGP_ppc64be_linux
Running on a kernel that supports the SCV instruction (sets
PPC_FEATURE2_SCV in auxv AT_HWCAPS2) valgrind will assert: valgrind:
m_syswrap/syswrap-main.c:549 (getSyscallArgsFromGuestState): Assertion
'gst->guest_syscall_flag == SC_FLAG' failed.
Removing that assert makes most things work. But also filter out
PPC_FEATURE2_SCV from AT_HWCAPS2 for the client, so it shouldn't try
using the SCV instruction.