Carl Love [Fri, 11 Jun 2021 15:59:53 +0000 (10:59 -0500)]
PPC64 Enable the MMA bit in the HWCAP.
The MMA bit should have been enabled when the last of the MMA instructions
were committed. Also, the header comments about filtering out the DARN
and SCV support should have been updated when DARN and SCV support was added.
Andreas Arnez [Mon, 7 Jun 2021 12:01:53 +0000 (14:01 +0200)]
s390x: Don't emit "vector or with complement" on z13
The z/Architecture instruction "vector or with complement" (VOC) can be
used as an optimization to combine "vector or" with "vector nor". This is
exploited in Valgrind since commit 6c1cb1a0128b00858b973e. However, VOC
requires the vector-enhancements facility 1, which is not installed on a
z13 CPU. Thus Valgrind can now run into SIGILL on z13 when trying to
execute vector string instructions.
Fix this by suppressing the VOC optimization unless the
vector-enhancements facility 1 is recognized on the host.
Andreas Arnez [Tue, 30 Mar 2021 15:45:20 +0000 (17:45 +0200)]
s390x: Fix/optimize Iop_64HLtoV128
In s390_vr_fill() in guest_s390_toIR.c, filling a vector with two copies
of a 64-bit value is realized with Iop_64HLtoV128, since there is no such
operator as Iop_Dup64x2. But the two args to Iop_64HLtoV128 use the same
expression, referenced twice. Although this hasn't been seen to cause
real trouble yet, it's problematic and potentially inefficient, so change
it: Assign to a temp and pass that twice instead.
In the instruction selector, if Iop_64HLtoV128 is found to be used for a
duplication as above, select "v-vdup" instead of "v-vinitfromgprs". This
mimicks the behavior we'd get if there actually was an operator
Iop_Dup64x2.
Andreas Arnez [Fri, 26 Mar 2021 18:27:47 +0000 (19:27 +0100)]
s390x: Rework insn "v-vdup" and add "v-vrep"
So far the only s390x insn for filling a vector with copies of the same
element is "v-vdup" (S390_VEC_DUPLICATE), which replicates the first
element of its vector argument. This is fairly restrictive and can lead
to unnecessarily long code sequences.
Redefine "v-vdup" to replicate any scalar value instead. And add
"v-vrep" (S390_INSN_VEC_REPLICATE) for replicating any given element of a
vector. Select the latter for suitable expressions like
Iop_Dup8x16(Iop_GetElem8x16(vector_expr, i))
This improves the generated code for some vector string instructions,
where a lot of element replications are performed.
Andreas Arnez [Tue, 23 Mar 2021 13:55:09 +0000 (14:55 +0100)]
s390x: Improve handling of amodes without base register
Addressing modes without a base or index register represent constants.
They can occur in some special cases such as shift operations and when
accessing individual vector elements. Perform some minor improvements to
the handling of such amodes.
Andreas Arnez [Fri, 16 Apr 2021 10:44:44 +0000 (12:44 +0200)]
Bug 434296 - s390x: Add memcheck test cases for vector string insns
Bug 434296 addresses memcheck false positives with the vector string
instructions VISTR, VSTRC, VFAE, VFEE, and VFENE. Add test cases that
verify the fix for that bug. Without the fix, memcheck yields many
complains with these tests, most of which are false positives.
Andreas Arnez [Tue, 27 Apr 2021 18:13:26 +0000 (20:13 +0200)]
Bug 434296 - s390x: Rework IR conversion of VISTR
The z/Architecture instruction VISTR is currently transformed to a dirty
helper that executes the instruction. This can cause false positives with
memcheck if the input string contains undefined characters after the
string terminator. Implement without a dirty helper and emulate the
instruction instead.
Andreas Arnez [Tue, 2 Mar 2021 13:12:29 +0000 (14:12 +0100)]
Bug 434296 - s390x: Rework IR conversion of VFENE
So far the z/Architecture instruction "vector find element not
equal" (VFENE) is transformed to a loop. This can cause spurious
"conditional jump or move depends on uninitialised value(s)" messages by
memcheck. Re-implement without a loop.
Andreas Arnez [Thu, 18 Mar 2021 17:01:10 +0000 (18:01 +0100)]
Bug 434296 - s390x: Rework IR conversion of VSTRC, VFAE, and VFEE
The z/Architecture instructions "vector string range compare" (VSTRC),
"vector find any element equal" (VFAE), and "vector find element
equal" (VFEE) are each implemented with a dirty helper that executes the
instruction. Unfortunately this approach leads to memcheck false
positives, because these instructions may yield a defined result even if
parts of the input vectors are undefined. There are multiple ways this
can happen: Wherever the flags in the fourth operand to VSTRC indicate
"match always" or "match never", the corresponding elements in the third
operand don't affect the result. The same is true for the elements
following the first zero-element in the second operand if the ZS flag is
set, or for the elements following the first matching element, if any.
Re-implement the instructions without dirty helpers and transform into
lengthy IR instead.
Andreas Arnez [Wed, 7 Apr 2021 14:48:29 +0000 (16:48 +0200)]
s390x: Support "expensive" comparisons Iop_ExpCmpNE32/64
Add support for Iop_ExpCmpNE32 and Iop_ExpCmpNE64 in the s390x instruction
selector. Handle them exactly like the "inexpensive" variants Iop_CmpNE32
and Iop_CmpNE64.
Andreas Arnez [Wed, 28 Apr 2021 16:52:30 +0000 (18:52 +0200)]
Bug 433863 - s390x: Remove memcheck test cases for cs, cds, and csg
The fix for bug 429864 - "s390x: C++ atomic test_and_set yields
false-positive memcheck diagnostics" changes the memcheck behavior at
various compare-and-swap instructions. The comparison between the old and
expected value now always yields a defined result, even if the input
values are (partially) undefined. However, some existing test cases
explicitly verify that memcheck complains about the use of uninitialised
values here. These test cases are no longer valid. Remove them.
Andreas Arnez [Tue, 30 Mar 2021 16:10:43 +0000 (18:10 +0200)]
s390x: Add missing UNOP insns to s390_insn_as_string
Some unary operator insns are not handled by s390_insn_as_string(). If
they are encountered while the appropriate trace flag is set, a vpanic
occurs. Fix this: add handling for the missing insns.
Yi Fan Yu [Thu, 1 Apr 2021 19:31:47 +0000 (15:31 -0400)]
drd/tests/swapcontext: Add SIGALRM handler to avoid stacktrace
During testing for oe-core build on QEMU,
SIGALRM can trigger during nanosleep.
This results a different stderr output than expected.
```
==277== Process terminating with default action of signal 14 (SIGALRM)
==277== at 0x36C74C3943: clock_nanosleep@@GLIBC_2.17 (clock_nanosleep.c:43)
==277== by 0x36C74C8726: nanosleep (nanosleep.c:25)
```
This stacktrace printing will not occur
if we add a handler that simply exits.
To improve its results, Callgrind does special handling for
the runtime linker entry point to resolve symbols. However,
it only used the exact symbol name "_dl_runtime_resolve",
as well as specific machine code templates (when the runtime
linker was stripped from symbol names) as basis.
Recent glibc added multiple similar symbol names as variants,
such as _dl_runtime_resolve_xsave.
The above-mentioned commit 86277041 solves this by extending
the check for machine code templates for specific Linux
distributions.
This patch extends this for more architectures and variants
by checking if a function starts with "_dl_runtime_resolve".
Furthermore, the original function names of the variants
still are visible in the output (and not forced to the prefix).
While the heuristic that every function symbol starting
with the prefix "_dl_runtime_resolve" as being an entry point
into the runtime linker for resolving a function address may
be a bit rough, this prefix is not expected to be used often in
other source code for anything else.
The worst case is a slightly misleading call graph only
visible in a very specific situation: if the wrongly-detected
function does a tail call (ie instead of returning, jumping
to another function), it will be shown as 2 calls in a row
from the original caller.
Bart Van Assche [Tue, 23 Mar 2021 02:12:20 +0000 (19:12 -0700)]
configure, drd: Only build the swapcontext test if swapcontext() is available
Add a configure test for swapcontext() since MUSL does not provide a
swapcontext() implementation. See also
https://bugs.kde.org/show_bug.cgi?id=434775 .
Julian Seward [Wed, 17 Mar 2021 07:10:49 +0000 (08:10 +0100)]
Bug 401416 - Compile failure with openmpi 4.0.
In short, use the missing symbol names only when compiling against OpenMPI
version 3 or below, or when compiling against a non-OpenMPI implementation.
Modified version of a patch originally from Mark Wielaard.
Julian Seward [Sat, 13 Mar 2021 18:20:50 +0000 (19:20 +0100)]
amd64 front end: try to avoid a Memcheck false positive related to CPUID. n-i-bz.
In the amd64 front end, CPUID is implemented by calling dirty helper. The way
the side-effects for this call are declared can lead to false positives from
Memcheck. This is a somewhat inelegant "fix", but it's the least-worst that
can be done without changing parameter-passing for the helper functions
involved. A big in-line comment explains the problem and fix.
Andreas Arnez [Fri, 5 Mar 2021 19:16:46 +0000 (20:16 +0100)]
s390x: Improve isel for Iop_V128to64 and friends
The existing instruction selector for Iop_V128to64, Iop_V128HIto64, and
Iop_V128to32 stores the vector register on the stack and then reads the
requested integer value back from the stack into the target GPR. This is
fairly inefficient.
Load the requested value directly from the vector register into the target
GPR instead, using S390_VEC_GET_ELEM.
Mark Wielaard [Tue, 9 Mar 2021 17:51:57 +0000 (18:51 +0100)]
vgdb might crash if valgrind is killed
This is an odd corner case, but happens specifically with the gdb
testcase make check TESTS=gdb.base/valgrind-infcall-2.exp. At the
end valgrind gets killed with SIGKILL (-9) which cannot be blocked.
But vgdb at the time is inside waitstopped. It sees the process wasn't
exited (WIFEXITED(status) is false) and so assumes the process was
stopped by a signal. Which it asserts:
assert (WIFSTOPPED(status));
signal_received = WSTOPSIG(status);
if (signal_received == signal_expected)
break;
But the assert fails and vgdb dumps core. The gdb testcase doesn't care,
because it already finished its test and just makes sure all processes
are gone. But it slowly fills your disk with core files (if you have
enabled them) when running the testsuite.
The fix is to simply check first whether the program has termined
normally or by getting a fatal signal.
Fix nlcontrolc.vgtest hanging on newer glibc and/or arm64
This test verifies that GDB can interrupt a process with all threads
blocked in a long select syscall.
The test used to terminate by having GDB modifying the select argument.
However, modifying the select argument works only for specific arch
and/or specific versions of glibc.
The test then blocks on other architectures/glibc versions.
The previous version of the test was:
* first launching sleepers so as to have all threads blocked in long select
* interrupting these threads
* changing the select time arg so that the threads burn cpu
* and then change variables to have the program exit.
The new version does:
* first launches sleepers so that all threads are burning cpu.
* interrupting these threads
* change the local variables of sleepers so that the threads will
block in a long select syscall
* interrupt these threads
* kill the program.
With this new version, we still check the behaviour of gdb+vgdbserver
for both burning and sleep threads, but without having the termination
depending on modifying select syscall argument.
Tested on debian amd64 and on ubuntu arm64 (to check the test does not hang
on an arm64 platform).
Carl Love [Sat, 2 May 2020 04:49:33 +0000 (23:49 -0500)]
ISA 3.1 VSX Mask Manipulation Operations
Add support for:
mtvsrbmMove to VSR Byte Mask
mtvsrbmiMove To VSR Byte Mask Immediate
mtvsrdmMove to VSR Doubleword Mask
mtvsrhmMove to VSR Halfword Mask
mtvsrqmMove to VSR Quadword Mask
mtvsrwmMove to VSR Word Mask
vcntmbbVector Count Mask Bits Byte
vcntmbdVector Count Mask Bits Doubleword
vcntmbhVector Count Mask Bits Halfword
vcntmbwVector Count Mask Bits Word
vexpandbmVector Expand Byte Mask
vexpanddmVector Expand Doubleword Mask
vexpandhmVector Expand Halfword Mask
vexpandqmVector Expand Quadword Mask
vexpandwmVector Expand Word Mask
vextractbmVector Extract Byte Mask
vextractdmVector Extract Doubleword Mask
vextracthmVector Extract Halfword Mask
vextractqmVector Extract Quadword Mask
vextractwmVector Extract Word Mask
Re-implemented the copy_MSB_bit_fields() function. It can be done similarly to
the implementation of the vgnb instruction leveraging the clean helpers
used for the vgnb instruction.
Reimplemented the vexpandXm instructions eliminating
the call to copy_MSB_bit_fileds() and the need for the
for(i = 0; i< max; i++) loop.
Reimplemented the mtvsrXm instructions to remove the
need for the for(i = 0; i< max; i++) loop.
The computations for vexpandXm and mtvsrXm instructions
can be done much more efficiently.
Mark Wielaard [Thu, 4 Mar 2021 18:24:06 +0000 (19:24 +0100)]
arm64: Handle sp, lr, fp as DwReg in CfiExpr
When copy_convert_CfiExpr_tree sees a DwReg on arm64 we simply call
I_die_here; This causes an issue in the case we really do have to handle
that case (see https://bugzilla.redhat.com/show_bug.cgi?id=1923493).
Handle the stack pointer (sp), link register (x30) and frame pointer (x29),
which we already keep in D3UnwindRegs, like we do for other architectures
in evalCfiExpr and copy_convert_CfiExpr_tree.
Paul Floyd [Wed, 3 Mar 2021 07:53:51 +0000 (08:53 +0100)]
Keep on churning.
Without #define _XOPEN_SOURCE macports clang 9.0.1 on OSX 10.7.5 was
giving me
In file included from swapcontext.c:12:
/usr/include/ucontext.h:43:2: error: The deprecated ucontext routines require
_XOPEN_SOURCE to be defined
^
swapcontext.
So I added #define _XOPEN_SOURCE
But that gives, on Solaris 11.3
In file included from /usr/include/limits.h:12:0,
from /usr/gcc/4.8/lib/gcc/i386-pc-solaris2.11/4.8.2/include-fixed/limits.h:168,
from /usr/gcc/4.8/lib/gcc/i386-pc-solaris2.11/4.8.2/include-fixed/syslimits.h:7,
from /usr/gcc/4.8/lib/gcc/i386-pc-solaris2.11/4.8.2/include-fixed/limits.h:34,
from swapcontext.c:7:
/usr/include/sys/feature_tests.h:354:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
^
So make the #define _XOPEN_SOURCE conditional on darwin.
Paul Floyd [Tue, 2 Mar 2021 16:48:14 +0000 (17:48 +0100)]
Modify cxx17_aligned_new testcase to accommdate clang.
Explicitly use ordinary scalar delete and update the expecteds.
Otherwise g++ uses sized scalar delete whilse clang uses
ordinary scalar delete which causes a diff.
Mark Wielaard [Sun, 28 Feb 2021 23:39:31 +0000 (00:39 +0100)]
Remove deep-D.post.exp-ppc64 from EXTRA_DIST.
massif/tests/deep-D.post.exp-ppc64 was remove in commit 24a94df73
"VG_(get_fnname_kind): Recognize gcc "optimized" below main functions."
but was still listed in massif/tests/Makefile.am (EXTRA_DIST). Causing
make dist to fail.
Mark Wielaard [Sun, 28 Feb 2021 23:26:00 +0000 (00:26 +0100)]
VG_(get_fnname_kind): Recognize gcc "optimized" below main functions.
The VG_(get_fnname_kind) function detects some special "below main"
function names. Specifically __libc_start_main and generic_start_main
both of which are used to call the actual main () function from the
application. We already recognized one variant, generic_start_main.isra.0,
but only for powerpc. Recognize all possibly specialed optimized variants
gcc can produce by simply checking for the function name with dot as
prefix. This fixes the memcheck/tests/supp_unknown.vgtest and
massif/tests/deep-D.vgtest with gcc 11.
We can now also get rid of the special cases in
massif/tests/deep-D.post.exp-ppc64 and memcheck/tests/supp_unknown.supp.
Mike Hommey [Fri, 26 Feb 2021 08:09:52 +0000 (17:09 +0900)]
sys_newfstatat: don't complain if |file_name| is NULL.
This is a followup to 2a7d3ae76, in the case rust code runs against a
glibc that supports statx but a kernel that doesn't, in which case glibc
falls back to fstatat.
Mark Wielaard [Fri, 19 Feb 2021 22:49:10 +0000 (23:49 +0100)]
Use pkglibexec as vglibdir.
vglibdir is the directory from where valgrind loads its internal tool
executables and vgpreloads. Currently vglibdir is pkglibdir, so those
internal tools are intermingeled with normal executables and libraries
that the user might use directly.
Make vglibdir equal to pkglibexecdir so the internal tools get installed
and loaded from libexec and don't get get stored under lib.
This leaves just the static archives and the mpiwrapper libraries that
the user would link/load themselves under pkglibdir.
This seems more in line with the FHS lib/libexec standard and makes it
slightly easier to combine the tools from a multilib target (say the
memcheck-amd64-linux and memcheck-x86-linux tools) because they would
be installed under the same directory, while the pkglibdir can differ
depending on arch/target (lib/lib64).
Mark Wielaard [Sat, 27 Feb 2021 16:44:30 +0000 (17:44 +0100)]
gdbserver_tests: filter out Download failed: messages.
gdb can also use debuginfod and is excessively chatty when downloads
fail (even when DEBUGINFOD_URLS isn't set). Filter those messages out
of the gdb output.
Mark Wielaard [Fri, 26 Feb 2021 01:34:32 +0000 (02:34 +0100)]
Make the dwarf3 reader more robust and less chatty when things go wrong
Skip some stuff when seeing an unknown language, be less chatty about
parser issues.
All the issues seem to come from the multi-file, that is the shared
(supplementary or alt) file containing debuginfo shared by all the
gcc/runtime libraries.
There are a couple of issues that this patch works around:
- The multifile contains entries for the 'D' language, which has some
constructs we don't expect.
- We don't read partial units correctly, which means we often don't know
the language we are looking at.
- The parser is very chatty about issues it didn't expect (even if they
are ignored, it will still output something)
It only shows up with --read-var-info=yes which some tests enable, but
which is disabled by default.
Also increate the timeout of drd/tests/pth_cleanup_handler.c because
DWARF reading is so slow.
Aaron Merey [Fri, 19 Feb 2021 03:58:25 +0000 (22:58 -0500)]
PR432215 Add debuginfod functionality
debuginfod is an HTTP server for distributing ELF/DWARF debugging
information. When a debuginfo file cannot be found locally, Valgrind
is able to query debuginfod servers for the file using its build-id.
readelf.c: Add debuginfod_find_debug_file(). Spawns a child process to
exec `debuginfod-find` in order to query servers for the debuginfo
file. Also add helper debuginfod_find_path().
pub_core_pathscan.h: Moved from priv_initimg_pathscan.h in order to use
VG_(find_executable)() in readelf.c.
docs: Add information regarding debuginfod to valgrind.1
memcheck/tests/linux: Add new test debuginfod-check.
tests/vg_regtest.in: Clear $DEBUGINFOD_URLS before running any tests.
vmodsq Vector Modulo Signed Quadword
vmoduq Vector Modulo Unsigned Quadword
vmulesd Vector Multiply Even Signed Doubleword
vmuleud Vector Multiply Even Unsigned Doubleword
vmulosd Vector Multiply Odd Signed Doubleword
vmuloud Vector Multiply Odd Unsigned Doubleword
vmsumcud Vector Multiply-Sum & write Carry-out Unsigned Doubleword
xscvqpsqz VSX Scalar Convert with round to zero Quad-Precision to Signed
Quadword
xscvqpuqz VSX Scalar Convert with round to zero Quad-Precision toUnsigned
Quadword
xscvsqqp VSX Scalar Convert Signed Quadword to Quad-Precision
xscvuqqp VSX Scalar Convert Unsigned Quadword to Quad-Precision
Bart Van Assche [Tue, 23 Feb 2021 19:49:14 +0000 (11:49 -0800)]
drd/tests/swapcontext: Improve the portability of this test further
- Remove the VALGRIND_STACK_REGISTER() invocation for the initial thread
stack since it is superfluous. Remove the pthread_attr_getstack() call
that became superfluous by this change.
- Change SIGINT into SIGALRM for FreeBSD since pthread_kill(..., SIGINT)
causes the application to return a SIGINT status.
- Reduce the stack size of the threads created by this test.
Mark Wielaard [Tue, 23 Feb 2021 15:19:26 +0000 (16:19 +0100)]
Filter out unsupported instructions from HWCAP2 on powerpc.
Valgrind currently doesn't support the DARN random number instruction
and the SCV syscall instruction. Filter them out of HWCAP2 so glibc
and applications don't try to use them when running under valgrind.
Also suppress printing a log message for scv instructions in the
instruction stream.
Reported by: Florian Weimer <fweimer@redhat.com>
DARN bug: https://bugs.kde.org/show_bug.cgi?id=411189
SCV bug: https://bugs.kde.org/show_bug.cgi?id=431157
Mark Wielaard [Tue, 23 Feb 2021 10:50:13 +0000 (11:50 +0100)]
gdbserver_tests/hgtls.vgtest: Make sure gdb is installed before running
The other gdbserver_tests that need to run gdb make sure it is actually
available before trying to run it, otherwise the test is skipped. Do the
same to hgtls.vgtest by adding test -e gdb to the prereq.
Mark Wielaard [Sun, 21 Feb 2021 21:45:51 +0000 (22:45 +0100)]
Fix typo in DWARF 5 line table readers
This typo meant the directory entry was most often zero, which
happened to be sometimes correct anyway (since zero is the compdir).
So for simple testcases it looked correct. But it would be wrong for
compilation units not in the current compdir. Like files compiled with
a relative of absolute path (and then combined into the same compilation
unit with LTO).
The same typo was in both readdwarf.c (read_dwarf2_lineblock) and
readdwarf3.c (read_filename_table). read_dwarf2_lineblock also had
an extra "dwarf" string in the --debug-dump=line output.
Mark Wielaard [Sun, 21 Feb 2021 14:18:54 +0000 (15:18 +0100)]
swapcontext.vgtest fails with glibc-debuginfo installed
With debuginfo installed the backtace contains the swapcontext.S
source file. Filter that out, like the clone.S source file is in
drd/tests/filter_stderr.
Mark Wielaard [Sat, 20 Feb 2021 19:05:31 +0000 (20:05 +0100)]
Fix valgrind.h include in drd/tests/swapcontext.c
In tree tests should include "valgrind.h" not <valgrind/valgrind.h>
the later might pick up the system installed valgrind.h and doesn't
work when srcdir != builddir.
Bart Van Assche [Mon, 15 Feb 2021 04:08:52 +0000 (20:08 -0800)]
core: Pass stack change user requests on to tools
Since DRD tracks the lowest and highest stack address that has been used,
it needs to know about stack registration events. Hence pass on stack
registration events to tools.
Mark Wielaard [Sat, 20 Feb 2021 15:56:33 +0000 (16:56 +0100)]
Update NEWS with some core and platform (s390) changes and bug fixes.
Mention the new DWARF version 5 support needed with GCC 11.
s390 now supports z14 vector instructions.
Add missing bugs fixed and sort them by bug number (n-i-bz last).
Pull in 3.16.1 release data.
Mark Wielaard [Fri, 12 Feb 2021 22:29:34 +0000 (23:29 +0100)]
PR217695 malloc/calloc/realloc/memalign failure doesn't set errno to ENOMEM
When one of the allocation functions in vg_replace_malloc failed
they return NULL, but didn't set errno. This is slightly tricky since
errno is implementation defined and might be a macro. In the case of
glibc ernno is defined as:
We can use the same trick as we use for __libc_freeres in
coregrind/vg_preloaded.c. Define the function as "weak". This means
it will only be defined if another library (glibc in this case)
actually provides a definition. Otherwise it will be NULL.
So we will only call it if it is defined and one of the allocation
functions failed, returned NULL.
Include a new linux only memcheck testcase, enomem.vgtest.