364 Commits

Author SHA1 Message Date
Paul Floyd
a821780d8c solaris: aligned allocation issues
Solaris 11.3 doesn't have aligned_alloc - add a configure time test
memalign does not accept either a size or an alignment of zero
2023-04-23 13:51:37 +02:00
Paul Floyd
a2af9adec4 Bug 397083 - Likely false positive "uninitialised value(s)" for __wmemchr_avx2 and __wmemcmp_avx2_movbe 2023-04-20 22:11:31 +02:00
Paul Floyd
ab6d3928a5 regtest: warning cleanup
All for clang and mostly Apple clang
There are still numerous deprecated warnings on macOS 10.13
(sem* functions, syscall, sbrk, i386, PIEi, OSSpinLocki, swapcontext, getcontext)
2023-04-10 10:33:54 +02:00
Paul Floyd
5fd3b8947e Regtest: put back a glibc version ofr memalign_args test
I forgot that glibc aligned_alloc really is memalign, which
changes the callstack.
2023-03-26 17:05:25 +02:00
Paul Floyd
95ac41bc58 Regtest: add a filter for aligned alloc uninit args tests
These tests generate a varying number of errors per argument
depending on the platform and compiler.

The filter just prints the first unique error stanza which
allows 8 expecteds to be removed.
2023-03-26 16:37:56 +02:00
Paul Floyd
3eaac58827 Regtest: clean aligned alloc tests on FreeBSD x86
Add a filter for size_t (unsigned long on 64bit platforms and unsigned
int on 32bit ones).

Add another expected for x86.
2023-03-25 19:52:41 +01:00
Paul Floyd
8532c8b5e4 regtest: add an s390 expected for sized_aligned_new_delete_args 2023-03-12 08:20:57 +01:00
Paul Floyd
50bded71b2 Bug 436413 - Warn about realloc of size zero
Adds a new warning to memcheck when realloc is used with a size of 0.
For a long time this has been "implementation defined" and so
non-portable. With C23 it will become UB.

Also adds a switch to turn off the error generation and a
second switch to select between the most common
"implementation" behaviours. The defaults for this second
switch are baked in at build time.
2023-03-10 21:55:14 +01:00
Paul Floyd
4af62304d9 Rename memcheck/tests/sized_aligned_new_delete_args.stderr.exp-glibc
It's for GCC / libstdc++ really
2023-03-10 18:41:26 +01:00
Paul Floyd
28e4efb2b1 Mised one aligned alloc wrapper on Linux
Need different expected for GCC / libstdc++

And I think that the 32bit expected will also need updating.
2023-03-10 08:40:40 +01:00
Paul Floyd
d4affb0ab7 Make operator new aligned more like the standalone versions
If the alignment is not a power of two return nullptr for the
nothrow overload and bomb for the throwing overload.
2023-03-08 23:10:22 +01:00
Paul Floyd
bb5e8df560 regtest: add an arm expected for memalign_args 2023-03-08 21:34:25 +01:00
Paul Floyd
a7d86da0f6 regtest: fix warning in memalign_args and add debug info to sized_aligned_new_delete_args 2023-03-08 08:59:38 +01:00
Paul Floyd
114c528dab Add 32bit version of sized_aligned_new_delete_args expected
Asl add some parens to shut up clangd
2023-03-07 22:58:57 +01:00
Paul Floyd
ceee3e8922 Add checks to all new / delete overload arguments 2023-03-07 22:47:19 +01:00
Paul Floyd
663bb2ed65 Linux PPC regtest: add a specific expected for memalign_args
The number of errors for arguments that gets triggered depends
on how GCC optimzes and generates code for the vg_replace_malloc.c
wrappers. PPC seems to trigger more than amd64.
2023-03-01 08:18:09 +01:00
Paul Floyd
e862c6f3d2 Make memalign behave more like the underlying platform memalign
This is the first part of
Bug 466104 aligned_alloc problems, part 1

The bulk of this change is try try to get memalign to be more
platform aware. Previously the Valgrind implementation only
reflected the glibc implementation. That meant non-power of
two alignment values would silently get bumped up to the
next largest power of two. Most other platforms return NULL
and set errno to EINVAL.

There are a few other changes. A couple of the other aligned alloc
functions like valloc were caling the Valgrind memalign. This meant
that there weould be an extra Valgrind memalign in any error
callstacks. Now these functions call the allocator directly.

The memcheck memalign2 testcase has been redone. The memalign
parts moved out to per-platform versions and the tescase
itdelf renamed to posix_memalign, since that is all that is left.
I also modified the testcase so that it checks that the
memalign calls check for non-NULL returns, and on platforms
that set errno that it is correctly set. Previously the
test only worked on non-glibc because NULL & alignment is
zero.  The platform versions have been tested on glibc,
MUSL, FreeBSD and OpenIndiana and should hopefully run OK
both under memcheck and standalone.

There is stil quite a lot that is NOT done

1. I'm not certain that implementations allocate more memory
   and/or use a wider alignment. It doesn't help that almost
   universally the memalign implementations are badly
   documented, undocumented or buggy.
2. We don't handle very large alignment requests well.
   Most implementations will fail and set EINVAL if the
   alignment is over half the memory space. Valgrind will
   core panic if an aligmnt of over 16Mbytes is requested.
3. We don't generate any memcheck errors for invalid values
   of alignment. That's planned in Part 2.
4. The code is static and fixed at compile time. That means that
   if you are using MUSL with a glibc-built Valgrind you
   will still get glibc memalign behaviour.
   I'll wait to see if there are any requests before trying
   to make the behaviour selectable at runtime.
2023-02-28 13:46:08 +01:00
Paul Floyd
a6101db692 Try to correct configure script for warning flags with values
Some -W flags come with and without an =
(usually for warning levels)
But some only have the form -Wfoo=42 and -Wno-foo
2023-02-21 22:05:13 +01:00
Paul Floyd
fe008c8739 regtest: remove compiler warnings with clang 2023-02-19 10:10:59 +01:00
Paul Floyd
9fb974c359 Regtest: rationalize filters for new/delete 2023-02-05 12:50:13 +01:00
Paul Floyd
a4e5942b32 Remove warning caused by D demangle testcase 2023-01-30 21:13:13 +01:00
Paul Floyd
82282a6676 Bug 464969 - D language demangling
Patch from witold.baryluk@gmail.com

(also added a testcase)
2023-01-29 22:07:52 +01:00
Paul Floyd
c15993dcb4 FreeBSD: start adding more checks for /proc
Also add a couple of expecteds.
2023-01-22 21:48:51 +01:00
Paul Floyd
99dfad28a5 Cleanup warnings
Now no warnings on Fedora 36
For a short while
2023-01-09 23:57:01 +01:00
Paul Floyd
1cea0e151b Cleanup of warnings, mostly -Wno-unused-but-set-variable 2023-01-08 17:51:37 +01:00
Mark Wielaard
74e180e3c4 Add memmem memcheck tests
Ensure that memmem behaves as expected and doesn't yield memcheck false
positives.
2022-07-07 14:24:39 +02:00
Paul Floyd
7844752299 Bug 452802 Handle lld 9+ split RW PT_LOAD segments correctly
Many changes mostly related to modifying VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
so that instead of triggering debuginfo reading after seeing one RX PT_LOAD and 1 RW PT_LOAD it
can handle either 1 or 2 RW PT_LOADs.
2022-06-09 22:03:04 +02:00
Paul Floyd
036a55f77d Remove expected from EXTRA_DIST 2022-06-02 21:02:59 +02:00
Paul Floyd
776c38e30b Add another expected for memcheck/tests/leak_cpp_interior
There is a difference between the outputs when using
32bit and 64bit with clang++/libc++

Running the test in a shell with the output piped through c++filt I see
64bit:
--2153-- operator new[](unsigned long)(32) = 0x55AB040
--2153-- malloc(31) = 0x55AB0A0
--2153-- operator new[](unsigned long)(8) = 0x55AB100
--2153-- operator new(unsigned long)(16) = 0x55AB150
--2153-- operator new(unsigned long)(16) = 0x55AB1A0
--2153-- operator new(unsigned long)(32) = 0x55AB1F0
--2153-- operator new(unsigned long)(32) = 0x55AB250

32bit:
--55024-- operator new[](unsigned int)(28) = 0x7D41030
--55024-- malloc(31) = 0x7D41090
--55024-- operator new[](unsigned int)(4) = 0x7D410F0
--55024-- operator new(unsigned int)(8) = 0x7D41140
--55024-- operator new(unsigned int)(8) = 0x7D41190
--55024-- operator new(unsigned int)(16) = 0x7D411E0
--55024-- operator new(unsigned int)(16) = 0x7D41230
--55024-- operator new(unsigned int)(32) = 0x7D41280

Note the extra 32 byte allocation at the end. This is because of

  str2 += " rocks (str2)\n"; // interior ptr.

at the end of void doit(void)

Details of the mechaism here
https://stackoverflow.com/questions/21694302/what-are-the-mechanics-of-short-string-optimization-in-libc

str2 starts containing 9 characters "Valgrind"
Catenating to it makes it "Valgrind rocks (str2)\n" which is exactly 22 characters.

The 64bit SSO has a capacity of 22 chars, so there is no need to switch from
SSO in the stack variable to using heap allocation.

The 32bit SSO only has a capacity of 10, so there there is space
in the SSO for the initial string but the catenation expands it
beyond the SSO capacity and there is a heap allocation
via the std::basic_string allocator, which calls raw ::operator new.
2022-05-27 13:27:58 +02:00
Paul Floyd
a17b8d0198 Add FreeBSD-specific expected for memcheck/tests/gone_abrt_xml
The difference is in the si_code. Linux has a value of 0, FreeBSD has
65537. This is correct.

From vki-freebsd.h

/*
 * si_code values
 */

and indeed this signal gets sent by kill()
2022-05-09 09:47:12 +02:00
Paul Floyd
8b2cf214af Fix warning building memcheck/tests/memalign2
Was getting warnings with clang like

memalign2.c:62:17: warning: requested alignment is not a power of 2 [-Wnon-power-of-two-alignment]
   p = memalign(0, 100);      assert(0 == (long)p % 8);
2022-04-19 22:36:36 +02:00
Paul Floyd
7d47865aa7 No longer need FreeBSD expected for C++ demangle test 2021-11-13 00:25:43 +01:00
Julian Seward
530df882b8 Bug 444399 - disInstr(arm64): unhandled instruction 0xC87F2D89 (LD{,A}XP and ST{,L}XP).
This is unfortunately a big and complex patch, to implement LD{,A}XP and
ST{,L}XP.  These were omitted from the original AArch64 v8.0 implementation
for unknown reasons.

(Background) the patch is made significantly more complex because for AArch64
we actually have two implementations of the underlying
Load-Linked/Store-Conditional (LL/SC) machinery: a "primary" implementation,
which translates LL/SC more or less directly into IR and re-emits them at the
back end, and a "fallback" implementation that implements LL/SC "manually", by
taking advantage of the fact that V serialises thread execution, so we can
"implement" LL/SC by simulating a reservation using fields LLSC_* in the guest
state, and invalidating the reservation at every thread switch.

(Background) the fallback scheme is needed because the primary scheme is in
violation of the ARMv8 semantics in that it can (easily) introduce extra
memory references between the LL and SC, hence on some hardware causing the
reservation to always fail and so the simulated program to wind up looping
forever.

For these instructions, big picture:

* for the primary implementation, we take advantage of the fact that
  IRStmt_LLSC allows I128 bit transactions to be represented.  Hence we bundle
  up the two 64-bit data elements into an I128 (or vice versa) and present a
  single I128-typed IRStmt_LLSC in the IR.  In the backend, those are
  re-emitted as LDXP/STXP respectively.  For LL/SC on 32-bit register pairs,
  that bundling produces a single 64-bit item, and so the existing LL/SC
  backend machinery handles it.  The effect is that a doubleword 32-bit LL/SC
  in the front end translates into a single 64-bit LL/SC in the back end.
  Overall, though, the implementation is straightforward.

* for the fallback implementation, it is necessary to extend the guest state
  field `guest_LLSC_DATA` to represent a 128-bit transaction, by splitting it
  into _DATA_LO64 and DATA_HI64.  Then, the implementation is an exact
  analogue of the fallback implementation for single-word LL/SC.  It takes
  advantage of the fact that the backend already supports 128-bit CAS, as
  fixed in bug 445354.  As with the primary implementation, doubleword 32-bit
  LL/SC is bundled into a single 64-bit transaction.

Detailed changes:

* new arm64 guest state fields LLSC_DATA_LO64/LLSC_DATA_LO64 to replace
  guest_LLSC_DATA

* (ridealong fix) arm64 front end: a fix to a minor and harmless decoding bug
  for the single-word LDX/STX case.

* arm64 front end: IR generation for LD{,A}XP/ST{,L}XP: tedious and
  longwinded, but per comments above, an exact(ish) analogue of the singleword
  case

* arm64 backend: new insns ARM64Instr_LdrEXP / ARM64Instr_StrEXP to wrap up 2
  x 64 exclusive loads/stores.  Per comments above, there's no need to handle
  the 2 x 32 case.

* arm64 isel: translate I128-typed IRStmt_LLSC into the above two insns

* arm64 isel: some auxiliary bits and pieces needed to handle I128 values;
  this is standard doubleword isel stuff

* arm64 isel: (ridealong fix): Ist_CAS: check for endianness of the CAS!

* arm64 isel: (ridealong) a couple of formatting fixes

* IR infrastructure: add support for I128 constants, done the same as V128
  constants

* memcheck: handle shadow loads and stores for I128 values

* testcase: memcheck/tests/atomic_incs.c: on arm64, also test 128-bit atomic
  addition, to check we really have atomicity right

* testcase: new test none/tests/arm64/ldxp_stxp.c, tests operation but not
  atomicity.  (Smoke test).
2021-11-12 12:13:45 +01:00
Mark Wielaard
d151907e5d Add demangle-rust to check_PROGRAMS
The demangle-rust.vgtest would fail because the demangle-rust binary
wasn't build by default. Add it to check_PROGRAMS and define
demangle_rust_SOURCES to make sure it is always build.
2021-11-11 18:02:18 +01:00
Mark Wielaard
c1bfa115f9 Add demangle-rust.vgtest demangle-rust.stderr.exp to EXTRA_DIST 2021-11-10 09:02:36 +01:00
Paul Floyd
8c0f72667e Fix the ramaining easily fixable warnings with clang
There's one remaining
memalign2.c:29:9: warning: unused variable 'piece' [-Wunused-variable]
because of a block of #if FreeBSD for memalign that looks unnecessary

Otherwise all that is left is a few like

warning: unknown warning option '-Wno-alloc-size-larger-than'; did you mean '-Wno-frame-larger-than='? [-Wunknown-warning-option]

because there is no standard for compiler arguments.
2021-10-10 21:56:49 +02:00
Mark Wielaard
bfd28bb9f8 Remove more warnings from tests
GCC12 catches various issues in tests at compile time that we want to
catch at runtime. Also glibc 2.34 deprecated various mallinfo related
functions. Add the relevant -Wno-foobar flags to those tests.  In one
case, unit_oset.c, the warning was correct and the uninitialized
variable was explicitly set.
2021-10-10 17:19:34 +02:00
Mark Wielaard
4015813336 Remove some warnings from tests
Various tests do things which we want to detect at runtime, like
ignoring the result of malloc or doing a deliberate impossibly large
allocation or operations that would result in overflowing or
truncated strings, that generate a warning from gcc.

In once case, mq_setattr called with new and old attrs overlapping,
this was explicitly fixed, in others -Wno-foobar was added to silence
the warning. This is safe even for older gcc, since a compiler will
ignore any -Wno-foobar they don't know about - since they do know they
won't warn for foobar.
2021-10-10 15:56:50 +02:00
Paul Floyd
7c5d720a2b FreeBSD support, patch 10
memcheck
No code changes. A few modified tests. Adds new FreeBSD specific tests.
2021-10-09 12:37:17 +02:00
Paul Floyd
e2583c02a5 FreeBSD support, patch 2
Files in the root directory
Several Makefile.am files that have dependencies on FreeBSD autoconf
variables. Included a few new filter files to act as placeholders
to create new freebsd subdirectories.

Updated NEWS with the FreeBSD bugzilla items plus a couple of other
items fixed indirectly.
2021-10-07 08:18:47 +02:00
Paul Floyd
e42badd060 Bug 388787 - Support for C++17 new/delete
These over-aligned new and delete operators were added in C++ 17.
2021-03-02 13:32:22 +01:00
Paul Floyd
6e5213028c Make memcheck/tests/sized_delete conditional upon the compiler having -fsized-deallocators, add 384729 to NEWS 2020-11-10 14:52:19 +01:00
Paul Floyd
6faec425f1 Add testcase for C++14 sized delete 2020-11-09 09:37:17 +01:00
Philippe Waroquiers
3a803036f7 Allow the user to change a set of command line options during execution.
This patch changes the option parsing framework to allow a set of
core or tool (currently only memcheck) options to be changed dynamically.

Here is a summary of the new functionality (extracted from NEWS):
* It is now possible to dynamically change the value of many command
  line options while your program (or its children) are running under
  Valgrind.
  To have the list of dynamically changeable options, run
     valgrind --help-dyn-options
  You can change the options from the shell by using vgdb to launch
  the monitor command "v.clo <clo option>...".
  The same monitor command can be used from a gdb connected
  to the valgrind gdbserver.
  Your program can also change the dynamically changeable options using
  the client request VALGRIND_CLO_CHANGE(option).

Here is a brief description of the code changes.
* the command line options parsing macros are now checking a 'parsing' mode
  to decide if the given option must be handled or not.
  (more about the parsing mode below).

* the 'main' command option parsing code has been split in a function
  'process_option' that can be called now by:
     - early_process_cmd_line_options
        (looping over args, calling process_option in mode "Early")
     - main_process_cmd_line_options
        (looping over args, calling process_option in mode "Processing")
     - the new function VG_(process_dynamic_option) called from
       gdbserver or from VALGRIND_CLO_CHANGE (calling
        process_option in mode "Dynamic" or "Help")

* So, now, during startup, process_option is called twice for each arg:
   - once during Early phase
   - once during normal Processing
  Then process_option can then be called again during execution.

So, the parsing mode is defined so that the option parsing code
behaves differently (e.g. allows or not to handle the option)
depending on the mode.

// Command line option parsing happens in the following modes:
//   cloE : Early processing, used by coregrind m_main.c to parse the
//      command line  options that must be handled early on.
//   cloP : Processing,  used by coregrind and tools during startup, when
//      doing command line options Processing.
//   clodD : Dynamic, used to dynamically change options after startup.
//      A subset of the command line options can be changed dynamically
//      after startup.
//   cloH : Help, special mode to produce the list of dynamically changeable
//      options for --help-dyn-options.
typedef
   enum {
      cloE = 1,
      cloP = 2,
      cloD = 4,
      cloH = 8
   } Clo_Mode;

The option parsing macros in pub_tool_options.h have now all a new variant
*_CLOM with the mode(s) in which the given option is accepted.
The old variant is kept and calls the new variant with mode cloP.
The function VG_(check_clom) in the macro compares the current mode
with the modes allowed for the option, and returns True if qq_arg
should be further processed.

For example:

// String argument, eg. --foo=yes or --foo=no
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      if      VG_STREQ(val, "yes") (qq_var) = True;                     \
      else if VG_STREQ(val, "no")  (qq_var) = False;                    \
      else VG_(fmsg_bad_option)(qq_arg, "Invalid boolean value '%s'"    \
                                " (should be 'yes' or 'no')\n", val);   \
      True; }))

   VG_BOOL_CLOM(cloP, qq_arg, qq_option, qq_var)

To make an option dynamically excutable, it is typically enough to replace
    VG_BOOL_CLO(...)
by
    VG_BOOL_CLOM(cloPD, ...)

For example:
-   else if VG_BOOL_CLO(arg, "--show-possibly-lost", tmp_show) {
+   else if VG_BOOL_CLOM(cloPD, arg, "--show-possibly-lost", tmp_show) {

cloPD means the option value is set/changed during the main command
Processing (P) and Dynamically during execution (D).

Note that the 'body/further processing' of a command is only executed when
the option is recognised and the current parsing mode is ok for this option.
2019-08-31 14:41:10 +02:00
Mark Wielaard
5ecdecdcd3 memcheck: Allow unaligned loads of words on ppc64[le].
On powerpc partial unaligned loads of words from partially invalid
addresses are OK and could be generated by our translation of ldbrx.

Adjust partial_load memcheck tests to allow partial loads of words
on powerpc64.

Part of resolving bug #386945.
2018-12-20 22:46:59 +01:00
Mark Wielaard
0c701ba2a4 Fix sigkill.stderr.exp for glibc-2.28.
glibc 2.28 filters out some bad signal numbers and returns
Invalid argument instead of passing such bad signal numbers
the kernel sigaction syscall. So we won't see such bad signal
numbers and won't print "bad signal number" ourselves.

Add a new memcheck/tests/sigkill.stderr.exp-glibc-2.28 to catch
this case.
2018-12-07 14:05:15 +01:00
Mark Wielaard
1ca0fe21ab Include suppsrc_lineno.supp and suppsrc_sanlineno.supp in EXTRA_DIST.
These are test file that are needed in the dist tar.
2018-09-14 22:56:13 +02:00
Ivo Raisr
410d736a99 Ability to add suppressions based on source file name and line number.
Fixes BZ#390471.
Patch based on work by: Jeff Frontz <jeff.frontz@gmail.com> and Joseph M Link.
2018-06-26 06:36:12 +02:00
Philippe Waroquiers
cd65782db6 Add missing EXTRA_DIST file libstdc++.supp
Otherwise leak_cpp_interior test fails from a make dist tarball
2018-04-22 23:31:54 +02:00
Mark Wielaard
ea1c229392 Remove all extra -std=c99 flags from Makefiles.
Configure now makes sure we build everything in c99 mode already.
No need to have extra special cases in the Makefiles.
2018-01-19 13:52:29 +01:00