17128 Commits

Author SHA1 Message Date
Paul Floyd
c821499df3 Add suppresions for DRD and Helgrind, guard variables on FreeBSD 14.0
This is a change probably related to clang 13.

guard variables make the initialization of function static variables
thread safe (only the initialization, not other accesses).
2022-05-31 22:18:13 +02:00
Paul Floyd
0c0acce7fa Add a DRD suppression for thread local data on FreeBSD 14.0 2022-05-31 22:05:28 +02:00
Paul Floyd
7788bc4fee Add some filtering to massif C++ tests with GCC on FreeBSD
I should perhaps just delete these expected. The testcases don't
work well with the stripped libstc++ without debuginfo on FreeBSD.
That means that the --ignore-fn= options don't work to remove
exception handling and iostream allocations and just leave the
tesatcase allocations.
2022-05-31 20:36:18 +02:00
Paul Floyd
2b370744e5 Indent and add more comments for FreeBSD syscall code
After working on an issue that turns out to seem to be with the
FreeBSD kernel sched_uler I played a lot with the Valgrind
syscall and scheduler code. I've kept the comments and the
reformatting.
2022-05-30 22:57:34 +02:00
Paul Floyd
807ea10a5c Fix typo in added EXTRA_DIST expected 2022-05-27 15:45:25 +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
2d97f34c82 Add a suppression For FreeBSD DRD
Occurs with clang++13
2022-05-27 14:50:15 +02:00
Paul Floyd
b8eddd0226 Forgot to push Makefile.am with EXTRA_DIST for new expecteds 2022-05-27 14:49:25 +02:00
Paul Floyd
60d2018d7c Add new expecteds for drd/tests/annotate_trace_memory[_xml]
With clang13 x86 there is a code gen difference wrt GCC:

gcc:
  i64 = 9;
 8048a6f:       c7 05 68 9f 04 08 09    movl   $0x9,0x8049f68
 8048a76:       00 00 00
 8048a79:       c7 05 6c 9f 04 08 00    movl   $0x0,0x8049f6c
 8048a80:       00 00 00
  i64 += 0x12345678ULL;
 8048a83:       a1 68 9f 04 08          mov    0x8049f68,%eax
 8048a88:       8b 15 6c 9f 04 08       mov    0x8049f6c,%edx
 8048a8e:       05 78 56 34 12          add    $0x12345678,%eax
 8048a93:       83 d2 00                adc    $0x0,%edx
 8048a96:       a3 68 9f 04 08          mov    %eax,0x8049f68
 8048a9b:       89 15 6c 9f 04 08       mov    %edx,0x8049f6c

 clang:
   i64 = 9;
  401ae2:       c7 05 64 3f 40 00 00    movl   $0x0,0x403f64
  401ae9:       00 00 00
  401aec:       c7 05 60 3f 40 00 09    movl   $0x9,0x403f60
  401af3:       00 00 00
  i64 += 0x12345678ULL;
  401af6:       8b 15 60 3f 40 00       mov    0x403f60,%edx
  401afc:       81 c2 78 56 34 12       add    $0x12345678,%edx
  401b02:       83 15 64 3f 40 00 00    adcl   $0x0,0x403f64
  401b09:       89 15 60 3f 40 00       mov    %edx,0x403f60
  401b0f:       8d 85 1c ff ff ff       lea    -0xe4(%ebp),%eax

This inversion of the order of the low and high 32bits
of the 64bit word causes a difference in traced loads
and stores reported by DRD.
2022-05-27 14:18:18 +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
034e5d2242 Fixes for FreeBSD pdkill syscall wrapper 2022-05-24 23:40:42 +02:00
Paul Floyd
a4151207a2 Add small sleep to none/tests/pth_2sig to help prevent hanging
On FreeBSD 13.0 x86 this testcase was hanging on some systems.
It seems like the SIGTERM signals were not being recieved
before the child exited, which left the parent hanging in the
pause() waiting to be killed.

Reported, patch provided and tested by Nick Briggs.
2022-05-23 21:27:58 +02:00
Paul Floyd
90763ca763 Change coredump note names for FreeBSD
Was not able to load vgcore files with lldb on FreeBSD.

I think that there is a way to go for lldb / FreeBSD to be able to fully read vgcore files.
See
https://www.moritz.systems/blog/lldb-core-dump-support-improvements/
2022-05-22 13:05:10 +02:00
Paul Floyd
14df01dc4e Add expecteds to EXTRA_DIST 2022-05-20 22:13:16 +02:00
Mark Wielaard
2dad922aba Add cmdline{1,2}.stdout.exp-non-linux files
The new --enable-debuginfod=<yes|no> command line flag is only
available on GNU/Linux systems. Add new exp file for other systems.
2022-05-20 14:58:45 +02:00
Aaron Merey
8d4eb6be20 Add --enabled-debuginfod command line option
Currently debuginfod is enabled in Valgrind when the $DEBUGINFOD_URLS
environment variable is set and disabled when it isn't set.

This patch adds an --enable-debuginfod=<yes|no> command line option
to provide another level of control over whether Valgrind attempts
to download debuginfo. "yes" is the default value.

$DEBUGINFOD_URLS must still contain debuginfod server URLs in order
for this feature to work when --enable-debuginfod=yes.

https://bugs.kde.org/show_bug.cgi?id=453602
2022-05-20 02:48:53 +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
ed78405cd6 Make testcase myrandom() noinline.
With clang 13 none/tests/amd64/amd64locked fails because of what
looks like a clang optimization error. do_bt_G_E_tests is the
point of failure, and one factor is that clang 13 is inlining
myrandom().
2022-05-18 23:41:43 +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
7e5073f853 Changes to auxv for FreeBSD 13.1 2022-05-14 16:24:22 +02:00
Mike Crowe
947388eb04 Intercept strncmp for glibc ld.so v2.28+
In glibc 5aad5f617892e75d91d4c8fb7594ff35b610c042 (first released in
v2.28) a call to strncmp was added to dl-load.c:is_dst. This causes
valgrind to complain about glibc's highly-optimised strncmp performing
sixteen-byte reads on short strings in ld.so. Let's intercept strncmp in
ld.so too so we use valgrind's simple version to avoid this problem.
2022-05-14 00:41:18 +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
1f1abc9ec3 Add check for DRD OMP tests for FreeBSD 2022-05-10 20:08:43 +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
407c00c2e9 FreeBSD: only set osrel for executables. 2022-05-09 07:49:56 +02:00
Paul Floyd
e23f5b6a14 FreeBSD x86 small logging changes and add comments explaining why none/tests/manythreads fails 2022-05-07 17:30:23 +02:00
Paul Floyd
295ce0e643 Update FreeBSD struct vki_kinfo_vmentry 2022-05-07 17:28:08 +02:00
Paul Floyd
184e3ba052 Bug 453055 shared_timed_mutex drd test fails with "Lock shared failed" message
Patch submited by Jesus Checa jcheca@redhat.com
2022-04-27 21:13:45 +02:00
Paul Floyd
6af21da952 Bug 452779 Valgrind fails to build on FreeBSD 13.0 with llvm-devel (15.0.0)
Only link with libgcc-sup if the compiler is clang.
Still need -lgcc
2022-04-27 21:10:35 +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
8187a60ac3 Add a configure test for -ansi and use it for none/tests/ansi 2022-04-19 22:21:37 +02:00
Paul Floyd
1dbc46750f Bug 452779 Valgrind fails to build on FreeBSD 13.0 with llvm-devel (15.0.0)
This fixes building.

I may make the -lgcc and libgcc-sup conditonal on not using clang later.
2022-04-19 22:03:01 +02:00
Di Chen
fca4a3d8e5 Support new memfd_secret linux syscall (447)
memfd_secret is a new syscall in linux 5.14. memfd_secret() is
disabled by default and a command-line option needs to be added to
enable it at boot time.

$ cat /proc/cmdline
[...] secretmem.enable=y

https://bugs.kde.org/451878
https://lwn.net/Articles/865256/
2022-04-19 11:59:36 +02:00
Dario Binacchi
9c9fd9ae24 coregrind: fix compilation for uclibc
It fixes a known iusse whose details are described at [1] and more
generally it guarantees that Valgrind is properly compiled for ulibc.

[1] https://www.mail-archive.com/valgrind-users@lists.sourceforge.net/msg05295.html

Suggested-by Michael Trimarchi <michael@amarulasolutions.com>
Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
2022-04-19 10:44:07 +02:00
Paul Floyd
d6bcd3ba29 Some more auxv extensions for FreeBSD 14
New entries added to testcase and documented in initimg.
May need more work
2022-04-14 00:01:49 +02:00
Paul Floyd
60dd674e71 Missing defines for FreeBSD 14 swapoff
+1 typo
2022-04-13 23:32:55 +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