Andreas Arnez [Thu, 19 Oct 2023 12:17:35 +0000 (14:17 +0200)]
s390x regtest: Fix memcheck tests for cu21 and cu42 with Clang
When compiled with Clang, the s390x memcheck tests for cu21 and cu42 yield
different line number information for the inline assemblies. Using gcc,
the inline assemblies do not receive updated line number information
because they are phrased as if they were data, not code. See also the
discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=30206
Fix this by rephrasing the inline assemblies in cu21 and cu42 to normal
instructions, using the respective mnemonics. Since this affects the line
number information, adjust the expected test output files as well.
Andreas Arnez [Tue, 16 May 2023 18:29:33 +0000 (20:29 +0200)]
s390x: Fix memcheck false positives with certain comparisons
Consider this structure definition:
struct s {
unsigned b : 1;
unsigned c : 1;
} x;
Then certain compiler optimizations for a big-endian system may transform
the test
if (x.b || x.c)
...
into a comparison `> 0x3f' of the structure's first byte. Indeed, the
result of this comparison only depends on the two highest bits of the
byte. Thus, even if the lower bits are undefined, memcheck shouldn't
complain, but it does.
For certain cases this can be fixed. Do this by detecting comparisons
like this in the condition code helper for S390_CC_OP_UNSIGNED_COMPARE and
transforming them to a test for the selected bits instead. Add a small
test to verify the fix.
Paul Floyd [Mon, 16 Oct 2023 21:14:39 +0000 (23:14 +0200)]
Bug 475652 - Missing suppression for __wcsncpy_avx2 (strncpy-avx2.S:308)?
Adds a replace strmem wrapper for wcsncpy
Whilst doing this I noticed that
memcheck/tests/filter_memcheck
wasn't filtering memcheck/tests/freebsd/timingsafe properly.
That's because before filtering vg_replace_strmem.c and
vg_replace_malloc.c there's a check that the test exe filename
does not match the line. In this case the test exe was "timingsafe",
but line contained "timingsafe_memcmp", which matched leaving
vg_replace_strmem.c unfiltered. So I just renamed the testcase.
Paul Floyd [Mon, 9 Oct 2023 20:54:30 +0000 (22:54 +0200)]
DHAT: only handle own user reqs, ignore others
Make other tools consistent with this as well
(using memcheck as the model). Also refactored
the DRD user req names to make it clearer which
are Valgrind user reqs, which are DRD public
user reqs and which are DRD internal user reqs.
Paul Floyd [Fri, 29 Sep 2023 20:45:32 +0000 (22:45 +0200)]
coverity: lots of checks that unsigned are >= 0 which is always true
Also put back the isFF flag initialization (used for FreeBSD
non-fixed RO ELF segmentd) . I had intended to delete it but
in the end kept it for traces but had already deleted the init code.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x: Make z16 machine model known to Valgrind
The z16 machine model hasn't been fully introduced to Valgrind yet. Add
the missing support:
* Add z16 to the list of machine models in each of `libvex.h',
`tests/s390x_features.c', and `s390-check-opcodes.pl'.
* Starting with z16, the "store facility list extended" (STFLE)
instruction can write four instead of three words. Reflect this in the
STFLE-helper and in the `stfle' test case.
* Pass the new STFLE-bits unchanged, except for the vector-packed-decimal
facility, which is unsupported by Valgrind.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x regtest: Adjust vec2_float for Clang
The vec2_float test case doesn't compile with Clang, due to two issues:
* Clang doesn't correctly support `long double' vectors, as documented in
this GitHub issue: https://github.com/llvm/llvm-project/issues/61291
* llvm-as behaves differently from gas for the reserved field in the
`.insn vrr' directive. Instead of inserting the given data from the
first operand, it initializes the reserved field with zeros.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x regtest: Additional test case fixes
While fixing Clang compilation issues, I noticed additional problematic
constructs in s390x test cases, some of which are uncovered with compiler
optimization options such as -O3:
* `bic.c' relies on an int to be sign-extended when passing it in a
register to an inline-assembly.
* `cksm.c' clobbers a register in an inline assembly without specifying
that.
* `cu12.c' and `cu14.c' read the variable `pattern1' beyond its size.
* `mvst.c' modifies input operands in inline assemblies.
* `srnmb.c' relies on Valgrind's error message for a bad rounding mode to
point to the line number where get_rounding_mode() is called, not to the
function itself.
* `stfle.c' has a code path with an uninitialized variable that may cause
a compiler warning.
* `stmg.c' modifies r15 in an inline assembly and doesn't expect the
compiler to use r15 as the base address for an input operand.
* Various inline assemblies use the "=m" constraint even when the
instruction only supports more restricted address operands.
Fix all of the above. For consistency and clarity, avoid the "=m"
constraint even when it would be applicable.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x regtest: Refactor mul test cases for Clang support
The mul test case crashes when compiled with clang because of register
clashes in some inline assemblies. Obviously clang does not treat
register clobbers as "early clobbers", but sometimes uses the same
registers for inputs as well.
Rewrite the inline assemblies in mul.h to avoid this issue. Also, reduce
the code duplication in the process. Adjust mul_GE.c accordingly. Keep
the expected output for all mul test cases the same as before.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x regtest: Adjust op00 and op_exception tests for Clang
As part of fixing Bug 465782, adjust the op00 and op_exception tests.
The op00 test case doesn't compile with clang because the .hword assembler
directive is not known to llvm-as. When replacing it with .short, the
test case fails because clang/llvm-as generates different line number
information from gcc/gas. Using gcc, Valgrind's error message locates the
unrecognised instruction
at 0x........: main (op00.c:3)
whereas with clang, it shows:
at 0x........: main (op00.c:4)
The asm statement in op00.c is indeed located at line 4, so when compiling
with gcc, the indicated line number is just wrong. This is because gas
only updates line number information for instruction directives, not for
directives like `.short' as used here. See also the discussion in
https://sourceware.org/bugzilla/show_bug.cgi?id=30206
The same applies to the op_exception test case, where `.long' is used to
emit illegal instructions.
Make these test cases independent from this difference, by replacing the
`.short' and `.long' directives by equivalent `.insn' directives. Also
drop the unnecessary duplication of op00.stderr.exp.
Andreas Arnez [Fri, 29 Sep 2023 14:11:31 +0000 (16:11 +0200)]
s390x regtest: Adjust various test cases for Clang
There are various issues when compiling the s390x test cases with
Clang (see Bug 465782):
* Bugs in inline assemblies tolerated/obscured by GCC:
- "d" (or "r") constraint instead of "a" where a register from 1-15 is
needed
- mix-up between vector register and general register in inline assembly
- too unspecific constraints such as "m" or "g"
- use of input operand for output
- missing register clobber declaration
* Missing Clang features:
- "%R" (register) and "%O" (offset) modifiers with address constraints
in inline assemblies
- variable-length array within a struct
* Use of the -mlong-double-128 command line option -- has been redundant
for some time with GCC, and Clang only supports 128-bit long double
* Bad definition of _FPU_SETCW/_FPU_GETCW in <fpu_control.h>
(See https://sourceware.org/bugzilla/show_bug.cgi?id=30130)
* Use of pow() function without linking libm -- GCC optimizes the call
away, while Clang keeps a reference to pow()
Perform appropriate changes to the test cases such that they can be
compiled both with Clang and with GCC.
Paul Floyd [Sat, 23 Sep 2023 14:11:55 +0000 (16:11 +0200)]
FreeBSD: fix reading debuginfo of the tool itself
Not sure if this was ever functional since I started working on it,
but FreeBSD parse_procselfmaps doesn't handle the RW PT_LOAD
correctly. Also since FreeBSD was ignoring non-fixed RO PT_LOAD
mappings ML_(read_elf_object) didn't see the right number of
debuginfo mappings compared to the ELF header.
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