2241 Commits

Author SHA1 Message Date
Paul Floyd
4fb52a67b5 Cleanup of str* and mem* functions
Add function checks to configure.ac
Use the configure HAVE_ macro rather than OS-dependent tests.
I suspect that a lot of the tests hve been obsolete for many
years. Add wrappers to FreeBSD.
:w
2022-06-01 22:09:50 +02:00
Paul Floyd
7289e2639c Remove alignment warning from a FreeBSD regtest 2022-06-01 21:54:19 +02:00
Paul Floyd
9d72116c9d Second attempt at new expected
Not sure what I did wrong, but it failed straight away.
Might have been playing with the .cpp file?
2022-05-27 15:19:12 +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
98774bffd2 Clobber ecx for clang x86 leak tests
The assembler for leak-cases.c on x86 with clang for f() ends with

  40198b:       c7 04 24 00 00 00 00    movl   $0x0,(%esp)
  401992:       e8 c9 fe ff ff          call   401860 <mk>
  401997:       89 04 24                mov    %eax,(%esp)
  40199a:       e8 c1 fe ff ff          call   401860 <mk>
  40199f:       a3 74 40 40 00          mov    %eax,0x404074
  4019a4:       a1 74 40 40 00          mov    0x404074,%eax
  4019a9:       8b 08                   mov    (%eax),%ecx
  4019ab:       83 c1 08                add    $0x8,%ecx
  4019ae:       89 08                   mov    %ecx,(%eax)
  4019b0:       c7 05 74 40 40 00 00    movl   $0x0,0x404074
  4019b7:       00 00 00
  4019ba:       83 c4 04                add    $0x4,%esp
  4019bd:       5d                      pop    %ebp
  4019be:       c3                      ret

If I've read that correctly, at the enc ECX contains the pointer
to allocated memory returned by mk() plus 8.

main() doesn't clobber ECX either, so this shows up in the
leak checks.

Clobbering ECX fixes the following testcases on FreeBSD 13.1 x86 with clang 13

< gdbserver_tests/mcblocklistsearch        (stderrB)
< memcheck/tests/leak-cases-full           (stderr)
< memcheck/tests/leak-cases-summary        (stderr)
< memcheck/tests/leak-cycle                (stderr)
< memcheck/tests/leak-tree                 (stderr)
< memcheck/tests/lks                       (stderr)
2022-05-19 22:40:03 +02:00
Paul Floyd
c10e4e864f Add filter for size of stat structure 2022-05-19 21:28:35 +02:00
Paul Floyd
1fa46af2d4 Make regtest memcheck/tests/amd64/insn-pmovmskb clang friendly
Clang 13 on FreeBSD 13.1 emits a cmov which changes the error
messages. Use an 'if' instead which works with both clang and GCC.
2022-05-19 21:21:18 +02:00
Paul Floyd
c065867e55 Add attribute noinline to memcheck/tests/wrap6.c
With clang 13 this testcase was failing due to inlining/optimization of fn_12.
2022-05-19 20:58:10 +02:00
Paul Floyd
6b7cd3b4e4 Update FreeBSD (f)stat tests for FreeBSD 13.1
Somewhat annoyingly, libc is using tail call optimization
which alters our callstacks.

FreeBSD 13 and earlier had something like

{compatibility API check}
  1372e0:       48 8d 95 08 fe ff ff    lea    -0x1f8(%rbp),%rdx
  1372e7:       bf 8d 01 00 00          mov    $0x18d,%edi
  1372ec:       44 89 f6                mov    %r14d,%esi
  1372ef:       31 c0                   xor    %eax,%eax
  1372f1:       e8 8a c5 09 00          call   1d3880 <syscall@plt>

{compatibility API check}
  1342b9:       3d 9f 4f 12 00          cmp    $0x124f9f,%eax
  1342be:       7c 25                   jl     1342e5 <_fstatfs+0x55>
  1342c0:       49 8b 07                mov    (%r15),%rax
  1342c3:       48 3b 45 e0             cmp    -0x20(%rbp),%rax
  1342c7:       0f 85 51 01 00 00       jne    13441e <_fstatfs+0x18e>

{compatibility not needed}
  1342cd:       44 89 f7                mov    %r14d,%edi
  1342d0:       48 89 de                mov    %rbx,%rsi
  1342d3:       48 81 c4 e8 01 00 00    add    $0x1e8,%rsp
  1342da:       5b                      pop    %rbx
  1342db:       41 5e                   pop    %r14
  1342dd:       41 5f                   pop    %r15
  1342df:       5d                      pop    %rbp

{tail call optimization}

  1342e0:       e9 bb a0 09 00          jmp    1ce3a0 <__sys_fstatfs@plt>

{compatibility API call}

So I've updated the expecteds and added a filter for 13.0 and older.
2022-05-19 19:52:57 +02:00
Paul Floyd
f6316d1b68 Fix memcheck/tests/freebsd/fexecve
This contained a stupid mistake, and had been working by luck.
2022-05-19 10:10:32 +02:00
Paul Floyd
6cb8e52c34 More changes for FreeBSD 13.1
These concern auxv, swapoff and fcntl F_KINFO

I wanted to use the new fcntl K_INFO to replace the existing
horrible implementation of resolve_filename, but it seems to
have change the behaviour for redirected files. Several
fdleak regtests fail because stdout resolves to an empty
string.
2022-05-14 16:46:03 +02:00
Paul Floyd
277f10d523 Try again for FreeBSD errno_aligned_allocs on x86
Harder than I thought to trigger ENOMEM on x86, so just fake it.
2022-05-10 21:01:01 +02:00
Paul Floyd
d7944c09f5 Update FreeBSD memcheck/tests/freebsd/errno_aligned_allocs.c for x86
Size to force an ENOMEM on 64bit too big for 32bit.
2022-05-10 20:23:27 +02:00
Paul Floyd
978eb7f1ab Bug 446754 Improve error codes from alloc functions under memcheck
I've made these changes only for FreeBSD and Solaris for the moment.

I don't know what should be done on Linux for aligned_alloc/memalign.
The current Valgrind code refects the glibc implementation, but not
what the documentation says.
2022-05-09 22:57:06 +02:00
Paul Floyd
35fcf875c6 FreeBSD shm_open2 also accepts first argument as SHM_ANON
Add an extra test to scalar
2022-05-09 21:27:36 +02:00
Paul Floyd
d99b369c09 FreeBSD shm_open2 arg5 seems to be optional
This syscall doesn't have a libc interface and manpage so
the documentation is skimpy.
2022-05-09 11:58:45 +02:00
Paul Floyd
3a883a6c1d Add FreeBSD shm_open2 syscall wrapper 2022-05-09 11:05:49 +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
1ec5d23e73 Make memcheck/tests/clientperm clang-friendly
The use of the ternary operator was causing diffs compared to
GCC output. Switching to use two 'ifs' should remove this
difference.
2022-05-09 09:16:48 +02:00
Paul Floyd
54ee45d208 Update clang version of insn-pmovmskb expected.
I'm not sure when this output changed.

This expected differs from the main GCC expected due to clang emitting
a cmovne for the ternary expression in 'use':
fprintf(stderr, "%d: Invalid value is %s\n", index, invalid ? "true" : "false");
2022-05-09 08:15:06 +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
acdef43dce memcheck/tests/amd64/shr_edx builds fine with clang
Make it build unconditionally
2022-04-19 22:27:59 +02:00
Paul Floyd
cdd98111c7 Updates to FreeBSD syscalls for FreeBSD 14
3 new syscalls, and swapoff has a COMPAT13 version.
2022-04-13 23:00:44 +02:00
Paul Floyd
6c51e110a2 Update FreeBSD scalar for x86
Missed one execve diff.
2022-04-13 22:59:09 +02:00
Paul Floyd
2b33a318d8 Update Solaris execve with checks for NULL argv
Also requires 2 expected to be updated
2022-04-10 23:02:13 +02:00
Mark Wielaard
7959d0661b Update mc_main Copyright message to include 2022
We haven't ran auxprogs/change-copyright-year since we switched to git.
This means most Copyright year ranges still say 2017. The script also
doesn't work for years >= 2020. Instead of trying to figure out how to
correctly update the per file Copyright year ranges just update the
main copyright notice that the program outputs on startup.
2022-04-07 22:02:12 +02:00
Paul Floyd
19584a93d1 Update FreeBSD [f]execve expecteds
As requested by Mark, for https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-07 07:56:27 +02:00
Di Chen
6a35b364c5 memfd test should be memfd_create test
Currently, syscall memfd_create was tested by this:

$ perl tests/vg_regtest memcheck/tests/linux/memfd.vgtest

Since memfd_secret introduced in kernel 5.14, valgrind should rename
the "memfd" test to "memfd_create" test to avoid the ambiguity, so that
user will not get confused with the "memfd_secret" test.

After this change, syscall memfd_create will be tested by:

$ perl tests/vg_regtest memcheck/tests/linux/memfd_create.vgtest
2022-04-07 00:36:41 +02:00
Mark Wielaard
8eb547054a Warn for execve syscall with argv or argv[0] being NULL.
For execve valgrind would silently fail when argv was NULL or
unadressable. Make sure that this produces a warning under memcheck.

The linux kernel accepts argv[0] being NULL, but most other kernels
don't since posix says it should be non-NULL and it causes argc to
be zero which is unexpected and might cause security issues.

This adjusts some testcases so they don't rely on execve succeeding
when argv is NULL and expect warnings about argv or argv[0] being
NULL or unaddressable.

https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-06 22:48:45 +02:00
Paul Floyd
4dd849e4ec Second go at memcheck/tests/freebsd/relapathat
Missed adding the argument to the C file
Needs more filtering
2022-04-03 22:28:26 +02:00
Paul Floyd
e816f4c44f Fixes for memcheck/tests/freebsd/realpathat
The syscall to realpathat was missing the buffer size argument.
By luck, no problem on amd64 but this failed on x86.
This adds the argument and a filter for the errors (size_t can be 4 or 8 bytes)
2022-04-03 22:00:09 +02:00
Paul Floyd
d6cdc6e523 Add filter to memcheck/tests/freebsd/fexecve for the size
Different size on x86 was causing a failure
2022-04-03 21:28:24 +02:00
Paul Floyd
bbc3bcab0a Bug 451843 - valgrind fails to start on a FreeBSD system which enforces W^X
Also add FreeBSD 13.1 to configure.ac
2022-04-03 15:50:38 +02:00
Mark Wielaard
29954981d8 Add power_ISA2_05.stdout.exp_Without_FPPO_2 to EXTRA_DIST 2022-02-16 23:03:00 +01:00
Carl Love
ac8f8e9039 Powerpc: Additional expected output for memcheck/tests/ppc64/power_ISA2_05 test.
Latest compiler is generating slightly different effective address.
2022-02-14 17:30:15 +00:00
Paul Floyd
536520cc1d Forgot to remove FreeBSD 13 i386 scalar expected 2021-12-11 16:20:58 +01:00
Paul Floyd
6db18baedb FreeBSD syswrap and scalar corrections for i386 and FreeBSD 12.2
There are still size/offset diffs on i386 for fexecve and realpathat.
2021-12-11 16:08:08 +01:00
Paul Floyd
bb178889c7 Bug 446823 FreeBSD - missing syscalls when using libzm4
Adds syscall wrappers for __specialfd and __realpathat.
Also remove kernel dependency on COMPAT_FREEBSD10.

This change also reorganizes somewhat the scalar test
and adds configure time checks for the FreeBSD version,
allowing regression tests to be compiled depending on the
FreeBSD release.

From now on, scalar.c will contain syscalls for FreeBSD 11 and 12
and subsequent releases will get their own scalar, starting with
scalar_13_plus.c.
2021-12-11 12:32:08 +01:00
Paul Floyd
d83f4c43e1 One more FreeBSD scalar fix
Using a 64 bit mask for an int argument was causing an
extra Conditional jump error
2021-12-10 22:11:16 +01:00
Paul Floyd
a56881fd7d FreeBSD scalar - filter didn't account for padding
Also forgot to remove deleted expected from EXTRA_DIST
2021-12-10 21:34:02 +01:00
Paul Floyd
0fe2799262 Correct some FreeBSD syswrap typos and simplify scalar
One typo affected scalar. Also add some more filtering
so that an extra expected is not needed for FreeBSD 13
2021-12-10 21:18:05 +01:00
Paul Floyd
de368522b8 Update FreeBSD 12 scalar 2021-12-10 21:04:25 +01:00
Paul Floyd
01048e33df FreeBSD sigreturn arg names again
Also make drd/tests/shared_timed_mutex more robust
Already not great using time delays, but the test seems
to fail intermittently due to spurious wakeups. So instead
of railing straight away, make it "three strikes and you're out".
2021-12-09 22:54:23 +01:00
Julian Seward
8ee1656165 Bug 446103 - Memcheck: --track-origins=yes causes extreme slowdowns for large mmap/munmap.
This patch rewrites the Level 2 origin-tracking cache (ocacheL2) so that
set-address-range-permissions (SARP) operations on it, for large ranges, are
at least a factor of 2.5 x faster.  This is primarily targeted at SARPs in the
range of hundreds to thousands of megabytes.  The Level 1 origin-tracking
cache covers 64MB address space, so SARPs that fit within it are mostly
unaffected.  There are extensive comments in-line.  Changes are:

* Change the Level 2 cache from a single AVL tree (OSet) into 4096 such trees,
  selected by middle bits of the tag, hence "taking out" 12 significant bits
  of search in any given tree.

* For the OCacheLine type, use a union so as to overlay the w32 and descr
  arrays with an array of 64-bit values.  This is used to speed up cases where
  those fields are to be set to zero, or checked against zero.

* Due to the various fast-paths added by this patch, OC_BITS_PER_LINE has
  pretty much been frozen at the current value, 5.

* ocache_sarp_Set_Origins, ocache_sarp_Clear_Origins: deal with large ranges
  in 32-byte steps instead of 4-byte steps.

* MC_(helperc_b_store32), MC_(helperc_b_store16): rewrite these to be (much)
  more efficient.

* fast-return cases for VG_(OSetGen_Lookup) and VG_(OSetGen_Remove) when the
  tree is empty

* a few extra inline hints
2021-12-08 07:52:09 +01:00
Paul Floyd
49fe0dc74a Anticipate testcase problems with GCC 12
There will be a lot more to come.

On amd64 Linux
In faultstatus was seeing the division by zero and emitting a ud2 opcode.
In wrap3 a pair of mutually recursive functions were being inlined.
When forced not to be inlined GCC merged them into a single function.
It cannot see that the client requests have diffeent behaviour.
2021-11-23 23:37:02 +01:00
Paul Floyd
e484eee0bd Bug 445300 [PATCH] Fix building tests with Musl
Patch contributed by
   Alyssa Ross <hi@alyssa.is>
2021-11-22 08:42:53 +01:00
Mark Wielaard
8ad4c01880 memcheck/tests/libstdc++.supp: rename suppression
The name malloc-leaks-cxx-stl-string-classes-debug was confusing
since the suppression wasn't a leak, not part of stl, string,
classes or debug. Rename it to libstdcxx-emergency-eh-alloc-pool
to indicate it is part of the emergency exception handling memory
pool.

Note that suppression is only needed for some test cases, normally
the pool is cleaned up as part of cxx_freeres.
2021-11-19 15:00:30 +01:00
Paul Floyd
f13667b1ef Bug 445607 Unhandled amd64-freebsd syscall: 247
I can't find much in the way of documentation for this.
Added to scalar, but no specific tests.
2021-11-17 23:15:23 +01:00
Paul Floyd
83dda2b71a Bug 444925 fexecve syscall wrapper not properly implemented
Implement fexecve and a few testcases on FreeBSD.
2021-11-14 22:06:14 +01:00
Paul Floyd
39b4bbe3a1 Bugs 435732 and 403802 again
This time with debuginfo removed.

Also update the vgtest files for a couple of massif tests
(and also the expected because of the commmand line change).
Not yet tested these two with debuginfo installed.
2021-11-13 12:31:41 +01:00