Bug 208531 - [PATCH]: FreeBSD support for valgrind
Summary: [PATCH]: FreeBSD support for valgrind
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.5.0
Platform: FreeBSD Ports FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
: 368873 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-09-25 18:22 UTC by Stanislav Sedov
Modified: 2021-10-09 13:10 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch (631.32 KB, patch)
2009-09-25 18:22 UTC, Stanislav Sedov
Details
Valgrind 3.5.0-4 FreeBSD diff (normal diff format) (588.03 KB, patch)
2010-10-21 19:20 UTC, Ed Maste
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stanislav Sedov 2009-09-25 18:22:40 UTC
Created attachment 37173 [details]
patch

Hello!

The patch attached adds FreeBSD support for valgrind.
It's now against version 3.5.0, but I can update it to HEAD at any
moment. Most of the tools testes and work fine, helgrind and drd
still needs some work (the first one gives excessive false positives,
and DRD doesn't work currently at all).

There're also some changes in the patch that will influence other platforms as well,  I can ifdef them if/when needed.
Comment 1 Bartosz Fabianowski 2009-09-25 22:18:18 UTC
At the very end of the patch, you have:


 #elif defined(VGO_darwin)
    if ( 0 == strcmp( OS, "darwin" ) ) return True;
 
+#elif defined(VGO_freebsd)
+   if ( 0 == strcmp( OS, "darwin" ) ) return True;
+


Should that not be:


 #elif defined(VGO_darwin)
    if ( 0 == strcmp( OS, "darwin" ) ) return True;
 
+#elif defined(VGO_freebsd)
+   if ( 0 == strcmp( OS, "freebsd" ) ) return True;
+


I know nothing about how the patch works but this just looked like a copy & paste error to me. Thanks for putting in the effort and porting Valgrind!
Comment 2 Ed Maste 2009-09-29 23:35:26 UTC
That change has been incorporated now:

http://p4db.freebsd.org/fileDiffView.cgi?FSPC=//depot/projects/valgrind/tests/os_test.c&REV=3&ACT=edit
Comment 3 Stanislav Sedov 2009-09-29 23:50:02 UTC
DRD should be also functional now, though gives a lot of false positives.  I still need to come up with a reasonable suppression file.

I'll attach the new patch with all changes incorporated later.
Comment 4 Raphael Kubo da Costa 2009-11-11 04:56:37 UTC
Stanislav, has there been any progress on this one lately?
Comment 5 Stanislav Sedov 2010-03-05 03:22:35 UTC
Sure, we're still working on it.
You can track the progress in FreeBSD perforce repository: http://p4web.freebsd.org/@md=d&cd=//depot/projects/&c=moY@//depot/projects/valgrind/?ac=83

I'll post the detailed status update soon.
Comment 6 Ed Maste 2010-10-21 19:20:18 UTC
Created attachment 52723 [details]
Valgrind 3.5.0-4 FreeBSD diff (normal diff format)

Formatting change to switch perforce diff to regular diff format.
Comment 7 Raphael Kubo da Costa 2010-10-27 02:57:09 UTC
Isn't it possible to split the patch into smaller, logically separate ones so that it is easier to review them (and hopefully commit them)?
Comment 8 Ed Maste 2010-10-27 16:22:54 UTC
FYI, work on the FreeBSD port has moved out of the FreeBSD Perforce repository to bitbucket.org to make it easier for others to follow the work: https://bitbucket.org/stass/valgrind-freebsd


For reference here are some details of the current state of the patch:

Added files:

README_FREEBSD
coregrind/m_coredumpcoredump-amd64-freebsd.c
coregrind/m_coredumpcoredump-x86-freebsd.c
coregrind/m_dispatchdispatch-amd64-freebsd.S
coregrind/m_dispatchdispatch-x86-freebsd.S
coregrind/m_initimginitimg-freebsd.c
coregrind/m_sigframesigframe-amd64-freebsd.c
coregrind/m_sigframesigframe-x86-freebsd.c
coregrind/m_syswrappriv_syswrap-freebsd.h
coregrind/m_syswrapsyscall-amd64-freebsd.S
coregrind/m_syswrapsyscall-x86-freebsd.S
coregrind/m_syswrapsyswrap-amd64-freebsd.c
coregrind/m_syswrapsyswrap-freebsd-variants.c
coregrind/m_syswrapsyswrap-freebsd.c
coregrind/m_syswrapsyswrap-x86-freebsd.c
coregrindlauncher-freebsd.c
coregrindlink_tool_exe_freebsd.in
freebsd.supp
getpath
include/vkivki-amd64-freebsd.h
include/vkivki-freebsd.h
include/vkivki-machine-types-amd64-freebsd.h
include/vkivki-machine-types-x86-freebsd.h
include/vkivki-scnums-freebsd.h
include/vkivki-x86-freebsd.h
memcheck/tests/amd64xor-undef-amd64.stderr.exp-freebsd
memcheck/testssigkill.stderr.exp-freebsd
none/testsshell.stderr.exp-freebsd
none/testsshell.stdout.exp-freebsd
none/testsshell_dir.stderr.exp-freebsd

Changes:

 Makefile.all.am                                         |   13 
 Makefile.am                                             |    1 
 Makefile.tool.am                                        |   24 +
 autogen.sh                                              |    2 
 cachegrind/tests/Makefile.am                            |    2 
 callgrind/tests/Makefile.am                             |    2 
 configure.in                                            |   93 ++++
 coregrind/Makefile.am                                   |   18 
 coregrind/m_aspacemgr/aspacemgr-common.c                |   64 ++-
 coregrind/m_aspacemgr/aspacemgr-linux.c                 |  115 +++++
 coregrind/m_coredump/coredump-elf.c                     |  143 +++++--
 coregrind/m_debugger.c                                  |    6 
 coregrind/m_debuginfo/d3basics.c                        |    4 
 coregrind/m_debuginfo/debuginfo.c                       |   14 
 coregrind/m_debuginfo/readdwarf.c                       |    8 
 coregrind/m_debuginfo/readdwarf3.c                      |    4 
 coregrind/m_debuginfo/readelf.c                         |   39 +
 coregrind/m_debuginfo/readpdb.c                         |    5 
 coregrind/m_debuginfo/readstabs.c                       |    7 
 coregrind/m_debuginfo/storage.c                         |    6 
 coregrind/m_debuglog.c                                  |   92 ++++
 coregrind/m_libcassert.c                                |    6 
 coregrind/m_libcfile.c                                  |   95 +++-
 coregrind/m_libcproc.c                                  |  105 +++++
 coregrind/m_libcsignal.c                                |  133 ++++++
 coregrind/m_machine.c                                   |   25 +
 coregrind/m_main.c                                      |   77 +++
 coregrind/m_redir.c                                     |    2 
 coregrind/m_scheduler/scheduler.c                       |    3 
 coregrind/m_signals.c                                   |   80 +++
 coregrind/m_stacktrace.c                                |    4 
 coregrind/m_syscall.c                                   |  128 ++++++
 coregrind/m_syswrap/priv_syswrap-generic.h              |   16 
 coregrind/m_syswrap/priv_types_n_macros.h               |   63 ++-
 coregrind/m_syswrap/syswrap-generic.c                   |   70 +++
 coregrind/m_syswrap/syswrap-main.c                      |  322 +++++++++++++++-
 coregrind/m_trampoline.S                                |   84 +++-
 coregrind/m_translate.c                                 |    3 
 coregrind/m_ume/elf.c                                   |  104 +++--
 coregrind/m_ume/main.c                                  |    2 
 coregrind/m_ume/priv_ume.h                              |    4 
 coregrind/m_vki.c                                       |    4 
 coregrind/m_vkiscnums.c                                 |   15 
 coregrind/pub_core_aspacemgr.h                          |    4 
 coregrind/pub_core_debuginfo.h                          |    2 
 coregrind/pub_core_initimg.h                            |   40 -
 coregrind/pub_core_libcproc.h                           |    8 
 coregrind/pub_core_machine.h                            |    4 
 coregrind/pub_core_mallocfree.h                         |    2 
 coregrind/pub_core_sigframe.h                           |    5 
 coregrind/pub_core_syscall.h                            |    2 
 coregrind/pub_core_trampoline.h                         |    8 
 coregrind/pub_core_vkiscnums.h                          |    3 
 coregrind/vg_preloaded.c                                |    2 
 drd/drd_main.c                                          |    2 
 drd/tests/Makefile.am                                   |    6 
 exp-ptrcheck/h_main.c                                   |    6 
 exp-ptrcheck/pc_main.c                                  |    5 
 exp-ptrcheck/tests/Makefile.am                          |    7 
 helgrind/hg_intercepts.c                                |  107 +++++
 helgrind/hg_main.c                                      |    3 
 helgrind/tests/tc07_hbl1.c                              |    9 
 helgrind/tests/tc08_hbl2.c                              |    9 
 helgrind/tests/tc11_XCHG.c                              |    9 
 helgrind/tests/tc17_sembar.c                            |   11 
 helgrind/tests/tc20_verifywrap.c                        |    2 
 helgrind/tests/tc23_bogus_condwait.c                    |   11 
 helgrind/tests/tc24_nonzero_sem.c                       |    9 
 include/Makefile.am                                     |    4 
 include/pub_tool_basics.h                               |   32 +
 include/pub_tool_basics_asm.h                           |    2 
 include/pub_tool_machine.h                              |    4 
 include/pub_tool_redir.h                                |   16 
 include/pub_tool_vki.h                                  |    2 
 include/pub_tool_vkiscnums.h                            |    5 
 include/pub_tool_vkiscnums_asm.h                        |    3 
 include/valgrind.h                                      |   16 
 lackey/Makefile.am                                      |    1 
 memcheck/mc_replace_strmem.c                            |   52 ++
 memcheck/tests/Makefile.am                              |    3 
 memcheck/tests/addressable.c                            |    4 
 memcheck/tests/addressable.stderr.exp                   |   49 --
 memcheck/tests/amd64/Makefile.am                        |    2 
 memcheck/tests/amd64/more_x87_fp.c                      |    4 
 memcheck/tests/badjump2.c                               |    3 
 memcheck/tests/buflen_check.c                           |    1 
 memcheck/tests/memalign2.c                              |    5 
 memcheck/tests/mempool.c                                |    6 
 memcheck/tests/noisy_child.stderr.exp                   |   17 
 memcheck/tests/pointer-trace.c                          |    4 
 memcheck/tests/pointer-trace.stderr.exp                 |    2 
 memcheck/tests/sh-mem-random.c                          |    2 
 memcheck/tests/str_tester.c                             |   26 -
 memcheck/tests/x86/more_x86_fp.c                        |    2 
 mpi/Makefile.am                                         |    6 
 none/tests/Makefile.am                                  |    4 
 none/tests/amd64/bug156404-amd64.c                      |    4 
 none/tests/amd64/insn_ssse3.vgtest                      |    2 
 none/tests/amd64/ssse3_misaligned.vgtest                |    2 
 none/tests/closeall.c                                   |    2 
 none/tests/execve.stderr.exp                            |    3 
 none/tests/faultstatus.c                                |    2 
 none/tests/fdleak_cmsg.c                                |    1 
 none/tests/fdleak_socketpair.c                          |    1 
 none/tests/map_unaligned.c                              |    4 
 none/tests/mq.c                                         |    1 
 none/tests/pth_atfork1.c                                |    4 
 none/tests/resolv.c                                     |    1 
 none/tests/rlimit_nofile.c                              |    1 
 none/tests/sem.c                                        |    1 
 none/tests/shell                                        |    3 
 none/tests/sigstackgrowth.c                             |    2 
 none/tests/x86/faultstatus.c                            |    4 
 none/tests/x86/insn_ssse3.vgtest                        |    2 
 none/tests/x86/ssse3_misaligned.vgtest                  |    2 
 perf/bigcode.c                                          |    2 
 perf/tinycc.c                                           |    2 
 tests/arch_test.c                                       |    4 
 tests/filter_discards                                   |    2 
 tests/malloc.h                                          |    4 
 tests/os_test.c                                         |    4 
 tests/sys_mman.h                                        |    2 

As mentioned before a lot of the small change counts are things like

-#if defined(VGO_linux) || defined(VGO_darwin)
+#if defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_freebsd)

All of that said - yes, in order to prepare this for committing upstream we will need to break this out into a form that's easier to review.
Comment 9 Stanislav Sedov 2011-04-30 02:27:34 UTC
JFYI,
we updated the FreeBSD version of valgrind to 3.6.1 and fixed some
minor and major issues found (unhandled syscalls, setcontext/getcontext
misbehavior, etc).

You can grab the new version in FreeBSD ports, or at https://bitbucket.org/stass/valgrind-freebsd, where our repository is hosted.  The diff agains the mainline
can be retrieved from there too.

Is anyone here interested in working with us to integrate our patches into the
mainline?  It's certianly stable enough (we can run big applications like
Firefox, ruby without any issues), and doesn't touch a lot in the common
code (mostly it's FreeBSD specific platform files).
Comment 10 Raphael Kubo da Costa 2011-05-01 05:34:09 UTC
What kind of help do you need? I'm just a FreeBSD user with no contact with the valgrind developers, but I'd like to help in any possible way.
Comment 11 Ed Maste 2011-11-08 21:22:20 UTC
What you can do to help:

- Test the FreeBSD port as each new version comes out and report any problems you see on your apps
- Demonstrate to the Valgrind developers that there is a broad base of users who want to use Valgrind on FreeBSD
- Vote this bug up (it's currently the highest-voted Valgrind issue on bugs.kde.org I believe)

Thanks
Ed
Comment 12 Florian Krohm 2011-11-08 22:42:36 UTC
(In reply to comment #11)
> What you can do to help:
> 

I worked on the s390x port which was added earlier this year. In my experience the following helped (no promises though):

(1) Post the patch here. 
(2) Keep changes to the common code to a minimum. It's OK to have #ifdef's in places where the other OSes have them. #ifdef's elsewhere are a different story.
(3) Add testcases.
Comment 13 Tom Hughes 2011-11-09 00:20:15 UTC
I would add that I doubt adding votes to the bug will achieve anything. As far as I know nobody pays any attention to the vote count. In fact I've never found any open source project which supports "votes" on bugs where the votes are paid attention to.
Comment 14 Ed Maste 2011-11-09 01:11:42 UTC
The reason I suggested marking it with a vote is just to demonstrate the level of interest in Valgrind on FreeBSD.  I've heard the comment in the past that there's a belief that there is not much interest in running Valgrind on FreeBSD, and that is definitely not the case.

> (1) Post the patch here. 

Patches have been posted at various points over the last two years, and referenced in the mailing lists.  There are some 30 new files and about 130 files with changes.  Shall we start posting the diffs themselves to the devel mailing list?

> (2) Keep changes to the common code to a minimum. It's OK to have #ifdef's in
places where the other OSes have them. #ifdef's elsewhere are a different
story.

Of course, that is in general what's been done with this port.  If there are any cases where this isn't true we will clean them up.

> (3) Add testcases.

With your experience with the s390x port can you comment on the types of testcases that needed to be added (were not covered by the existing valgrind test suite)?
Comment 15 Christian Borntraeger 2011-11-09 08:45:32 UTC
On 09/11/11 02:11, Ed Maste wrote:
>> (3) Add testcases.
> 
> With your experience with the s390x port can you comment on the types of
> testcases that needed to be added (were not covered by the existing valgrind
> test suite)?

Being NOT a maintainer, I add my 2 cents as well_
The "covered by" is a good indicator.
I would start with testcases for any supported system call that is not 
available on Linux or system calls with different behaviours:
- calling conventions
- return parameters
- different behaviour (I know there are some differences between bsd and sysV)

In addition, you should be able to use most instruction tests, but
please inspect all testcase failures and start fixing testcases or the port
(You might also want to post the testsuite results here).

Christian
Comment 16 Bart Van Assche 2011-11-09 18:53:32 UTC
Does stuff like this mean that the FreeBSD port is incomplete ?

--- //depot/vendor/valgrind/callgrind/tests/Makefile.am.orig
+++ //depot/vendor/valgrind/callgrind/tests/Makefile.am
@@ -17,7 +17,11 @@
 	notpower2-use.vgtest notpower2-use.stderr.exp \
 	threads.vgtest threads.stderr.exp
 
-check_PROGRAMS = clreq simwork threads
+check_PROGRAMS = clreq simwork
+
+if !VGCONF_PLATFORMS_INCLUDE_X86_FREEBSD
+check_PROGRAMS += threads
+endif
 
 AM_CFLAGS   += $(AM_FLAG_M3264_PRI)
 AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)


And why has the change below been made ? As far as I can see $(EGREP) doesn't occur anywhere.

--- //depot/vendor/valgrind/configure.in.orig
+++ //depot/vendor/valgrind/configure.in
@@ -39,6 +39,7 @@
 #         AC_SUBST([OBJCFLAGS])
 #        ])
 AC_PROG_RANLIB
+AC_PROG_EGREP
 
 # If no AR variable was specified, look up the name of the archiver. Otherwise
 # do not touch the AR variable.


And why has AC_PATH_PROG(SED, sed) been added ? AC_PROG_SED is already present in configure.in.

+# find sed
+AC_PATH_PROG(SED, sed)
+
Comment 17 Bart Van Assche 2011-11-09 18:56:55 UTC
Another note:(In reply to comment #0)
> It's now against version 3.5.0, but I can update it to HEAD at any
> moment.

Maybe you should better do that - 3.5.0 is so old that it isn't worth to spend time reviewing a patch that is based on 3.5.0. Many of the configure.in changes fail to apply on the trunk by the way.
Comment 18 Ed Maste 2011-11-09 19:47:26 UTC
> Maybe you should better do that - 3.5.0 is so old that it isn't worth to spend
> time reviewing a patch that is based on 3.5.0. Many of the configure.in changes
> fail to apply on the trunk by the way.

The port was done against 3.5.0 two years ago; the current port is against 3.7.0.  Stanislav's maintaining the FreeBSD port in Mercurial on bitbucket, at:

https://bitbucket.org/stass/valgrind-freebsd/changesets

We'll regenerate diffs for review.
Comment 19 Stanislav Sedov 2011-11-09 20:57:24 UTC
Hi, Bart!

Thanks a lot for you comments.
We'we working on finishing the 3.7.0 port right now, where some of this
stuff will be gone.  The FreeBSD port is not complete in the sense that
some of valgrind parts are not working yet (exp-ptrcheck being one example,
but it seems it's gone now).

We're ready to address all this limitations and do the diff cleanup (there're
still some places where our diff touches the common code, which probably should
be ifdef'ed at least initially) if there's any interest in merging our code.

I will post the new diff as soon as it's fully tested.

Thanks!
Comment 20 Ed Maste 2011-11-12 20:40:12 UTC
Current state of the test suite:

== 497 tests, 169 stderr failures, 11 stdout failures, 0 stderrB failures, 0 stdoutB failures, 3 post failures ==

The reported failures break down as follows:

  19 memcheck
   2 massif
  16 none
  44 helgrind
  98 drd
   2 exp-sgcheck
   1 exp-bbv
Comment 21 Bart Van Assche 2011-11-14 18:44:00 UTC
(In reply to comment #20)
> Current state of the test suite:
> 
> == 497 tests, 169 stderr failures, 11 stdout failures, 0 stderrB failures, 0
> stdoutB failures, 3 post failures ==
> 
> The reported failures break down as follows:
> 
>   19 memcheck
>    2 massif
>   16 none
>   44 helgrind
>   98 drd
>    2 exp-sgcheck
>    1 exp-bbv

All DRD tests pass on the currently supported systems, so there must be something wrong with the FreeBSD port.
Comment 22 Ed Maste 2011-11-14 19:07:35 UTC
On Mon, Nov 14, 2011 at 06:44:00PM +0000, Bart Van Assche wrote:

> All DRD tests pass on the currently supported systems, so there must be
> something wrong with the FreeBSD port.

I haven't looked at the drd ones yet, but the first 30 or so results
I have investigated are false positive failures - i.e., the output
when run on FreeBSD doesn't match what's expected, but the functionality
itself works.
Comment 23 Bart Van Assche 2011-11-16 17:05:23 UTC
(In reply to comment #22)
> On Mon, Nov 14, 2011 at 06:44:00PM +0000, Bart Van Assche wrote:
> 
> > All DRD tests pass on the currently supported systems, so there must be
> > something wrong with the FreeBSD port.
> 
> I haven't looked at the drd ones yet, but the first 30 or so results
> I have investigated are false positive failures - i.e., the output
> when run on FreeBSD doesn't match what's expected, but the functionality
> itself works.

Adding support for FreeBSD on the trunk means setting up a nightly build server for FreeBSD too such that developers who write and test patches on Linux have a way to verify that nothing breaks on FreeBSD. The output of the nightly build script for FreeBSD will be worthless unfortunately with so many known failures.
Comment 24 Ed Maste 2011-11-17 01:24:18 UTC
On Wed, Nov 16, 2011 at 05:05:24PM +0000, Bart Van Assche wrote:

> Adding support for FreeBSD on the trunk means setting up a nightly build
> server for FreeBSD too such that developers who write and test patches on
> Linux have a way to verify that nothing breaks on FreeBSD. The output of
> the nightly build script for FreeBSD will be worthless unfortunately with
> so many known failures.

Thanks for the comment Bart.  We're committed to getting the test suite
into good shape in order to have a candidate ready for committing to
SVN trunk.  The goal in trying to engage now to flesh out the roadmap on
getting the patches ready for a smooth integration.

On this specific topic of the nightly build server, I've had a look at
bin/nightly and I'm thinking of getting it to run against our downstream
repo for now as we clean up the test failures.  (Extending the script to
check out from a Hg repo on bitbucket.org instead.)  I also want to start
running the regression suite with a checkout of our tree on Linux to
ensure we're not breaking anything.

Do you have additional suggestions for the process?

Thanks,
Ed
Comment 25 Bart Van Assche 2011-11-17 20:05:12 UTC
(In reply to comment #24)
> Do you have additional suggestions for the process?

There are some changes that affect the Linux build. These should be explained (e.g. increasing the number of reserved FDs and the VKI_SIGSYS changes).

Also, I think you should address the remaining to-do items in your patch, e.g.

+#  elif defined(VGO_freebsd)
+#     warning "Needs love"
Comment 26 Ivo Raisr 2017-09-10 10:49:29 UTC
Stanislav, Ed et al,
Has there been any progress recently on fixing the remaining issues on FreeBSD port [1]? I see the last commit dates 2016-01-13, more than 1,5 years ago.
Perhaps the port has moved somewhere else?

[1] https://bitbucket.org/stass/valgrind-freebsd/
Comment 27 Ed Maste 2019-01-02 19:23:51 UTC
*** Bug 368873 has been marked as a duplicate of this bug. ***
Comment 28 Ed Maste 2019-01-02 19:26:18 UTC
Current work is in progress at https://github.com/freebsdfoundation/valgrind. The most up-to-date branch is freebsd.rebase, https://github.com/freebsdfoundation/valgrind/tree/freebsd.rebase.
Comment 29 Ed Maste 2019-01-02 19:58:53 UTC
(In reply to Bart Van Assche from comment #16)
> -check_PROGRAMS = clreq simwork threads
> +check_PROGRAMS = clreq simwork
> +
> +if !VGCONF_PLATFORMS_INCLUDE_X86_FREEBSD
> +check_PROGRAMS += threads
> +endif

This is no longer in the patchset. tsan_unittest is disabled on FreeBSD in the patch though:

+if !VGCONF_OS_IS_FREEBSD
+check_PROGRAMS += tsan_unittest
 endif

> And why has the change below been made ? As far as I can see $(EGREP)
> doesn't occur anywhere.
> 
> --- //depot/vendor/valgrind/configure.in.orig
> +++ //depot/vendor/valgrind/configure.in
> @@ -39,6 +39,7 @@
>  #         AC_SUBST([OBJCFLAGS])
>  #        ])
>  AC_PROG_RANLIB
> +AC_PROG_EGREP

Does it get used implicitly by AC_EGREP_CPP perhaps? I also see a ${EGREP} use in setting xpg_present.

> And why has AC_PATH_PROG(SED, sed) been added ? AC_PROG_SED is already
> present in configure.in.

This one has been removed.
Comment 30 Ed Maste 2019-01-02 20:03:17 UTC
I believe the specific points raised in previous comments have been addressed. On the mailing list Philippe Waroquiers reported that many files based on a Linux version still have the old filename in header comments etc., will address those soon.

Regtest results as of today:
 == 599 tests, 203 stderr failures, 68 stdout failures, 0 stderrB
failures, 0 stdoutB failures, 0 post failures ==
Comment 31 Ed Maste 2019-01-03 15:52:39 UTC
I've fixed up a few more issues, and started working on curating the changes into more reasonably reviewable pieces.

Current WIP is in the "freebsd.20190103" branch - I'll try to keep the patch set rebased on upstream and will start a new branch when rebasing.

https://github.com/FreeBSDFoundation/valgrind/tree/freebsd.20190103

Two questions:

- link_tool_exe_freebsd.in is a copy of older link_tool_exe_linux.in. Our toolchain is GNU-compatible and link_tool_exe_linux.in will probably work out of the box on FreeBSD. For cases like this should we share the script (perhaps renaming it)?

- tests/filter_libc starts with
#! /usr/bin/perl -w
which does not work on FreeBSD (perl is /usr/local/bin/perl).

Should this be renamed to tests/filter_libc.in and start with #! @PERL@ ?
Comment 32 Ed Maste 2019-03-07 18:08:21 UTC
Rebased patch set in https://github.com/FreeBSDFoundation/valgrind/tree/freebsd.20190307
Comment 33 Paul Floyd 2020-05-04 20:39:33 UTC
Over 10 years since this item was opened and it's my turn to take a stab at getting it done.

Here a couple of sample results (best and worst)

GCC on amd64 configured with -O0
== 714 tests, 19 stderr failures, 5 stdout failures, 1 stderrB failure, 3 stdoutB failures, 0 post failures ==

clang on x86
== 648 tests, 69 stderr failures, 4 stdout failures, 4 stderrB failures, 4 stdoutB failures, 1 post failure ==


Stuff that's been fixed
~~~~~~~~~~~~~~~~~~~~~~~
FreeBSD 11.1 added a ~64MB MAP_GUARD region below the user stack which was breaking the address space manager on x86.
For x86 on amd64 there was a failure arising from Valgrind not fully synthesizing auxv for the guest combined with a bug in rtld. That took a long time to hunt down.
x86 sigreturn was broken.
Debug output never worked on x86 and caused crashes on amd64.
There were several redir errors in drd and helgrind.
Added ~ 20 syscalls.


Remaining problems
~~~~~~~~~~~~~~~~~~
The number one remaining issue is with signal delivery, and it's worse on x86.

Some of the clang failures that I've looked at are due to the codegen. In a couple of cases I saw that clang used cmov opcodes rather then test/jmp used by GCC. I need to look ore at things like varinfo differences.

The default suppression file is pretty noisy with plain old libc functions. If I run 'ps' under memcheck then I get a bunch of 'Conditional jumps' in strlen and strvis. Qt apps could also do with some attention.


Not enough regtests yet. I've only added 7 I think. I definitely need to add a 'scalar' test.

Other stuff
~~~~~~~~~~~
There are a few other issues, but I might be able to live with them as known limitations.

I've tried to clean out the diffs in common source files as much as possible, but there's still some work to do. I have been fairly heavy handed in modifying test scripts that use sed, and should probably make .in files and a configure time AC_CONF_SED.

Next steps
~~~~~~~~~~
Before any talk of patches or code reviews:

I'd like to deal with the signal issues on x86, but that does not look easy.

The issues with clang need to be all analyzed, since this is the system compiler.

Test, test, test.

My github repo is here
https://github.com/paulfloyd/freebsd_valgrind
Comment 34 Paul Floyd 2020-07-02 09:01:19 UTC
Some gory details, part 1. In the FreeBSD world, normally there are 2 active release streams (currently 11 and 12) and one development stream (currently 13). The system compiler is clang, with GCC as an optional install. Whilst other architectures are supported by FreeBSD, amd64 and x86 are the only two that work with Valgrind. x86 (i386 in the FreeBSD world) is still fairly widely used.

My primary build/test work is all on FreeBSD 12.1. I started with amd64/GCC but  now I'm concentrating on amd64/clang. I also build and test on x86/clang and x86/gcc. I occasionally do builds on FreeBSD 11.3.

Here are some regtest results that I'm currently getting, and some analysis of the failures.

More analysis here https://github.com/paulfloyd/freebsd_valgrind/issues

amd64/clang
== 725 tests, 22 stderr failures, 1 stdout failure, 1 stderrB failure, 0 stdoutB failures, 0 post failures ==


memcheck/tests/leak* (4 fails)
There's a discrepancy with clang between the client request report and the final report. WIP.

drd/tests/omp (3 fails)
Many errors, not fully analysed. clang support for OpenMP seems fairly weak.

memcheck/tests/varinfo6 (+1 similar)
drd/tests/tc04_free_lock
Issue with getting varinfo, error line number printed as 0

drd/tests/dlopen
Hits an assert setting pthreadid, possibly related to the special handling that was required for dlopen on Solaris.

memcheck/tests/descr_belowsp
Error message doesn't mention guard page. Needs different guard page detection heuristics?

memcheck/tests/gone_abrt_xml
helgrind/tests/tc22_exit_w_lock 
There's a hack for stacktraces without function call prologs that doesn't work in these 2 cases.

gdbserver_tests/mcinfcallWSRU
Line number diffs in stderrB. Looks harmless.

memcheck/tests/amd64/insn-pmovmskb
Looks like clang optimization won the day with this testcase. Missing error messages and changes in order.

memcheck/tests/clientperm
Looks like clang optimization of branches.

helgrind/tests/tls_threads (+ drd)
Hard problem. On Linux this relies on spying on libc variables for tls. That doesn't work with non-GCC FreeBSD libc.

helgrind/tests/pth_cond_destroy_busy
One missing error message

helgrind/tests/tc22_exit_w_lock 

drd/tests/std_list
A load of locale errors.

drd/tests/atomic_var
Missing varinfo details

none/tests/amd64/ssse3_misaligned
SIGSEGV in host :-(

none/tests/rlimit_nofile
Only fails when I'm on KDE because of an extra krunner socket.
Comment 35 Paul Floyd 2020-07-02 09:12:51 UTC
Gory details part 2.

x86/clang, this is the worst case.

== 668 tests, 32 stderr failures, 2 stdout failures, 3 stderrB failures, 1 stdoutB failure, 0 post failures ==

Mostly the same as amd64/clang

none/tests/sigsusp
Testcase hangs :-( We try to clear the VGKILL bit in the syswrap, but for some reason that is failing (perhaps because the mask is const).

none/tests/manythreads
Fails after 8192 threads have run. Don't know why yet.

gdbserver_tests/nlpasssigalrm
SIGSEGV in host. Problem with correct construction of sigframe.

none/tests/pth_self_kill_15_other
drd/tests/sigalrm
More SIGSEGVs in host.

drd/tests/concurrent_close (4 cases in total)
drd/tests/annotate*
Extra conflicting loads
Comment 36 Paul Floyd 2020-07-02 20:13:52 UTC
Gory details, part 3. Last for the moment.

Good news for any FreeBSD users compiling with GCC on amd64:

== 735 tests, 7 stderr failures, 1 stdout failure, 0 stderrB failures, 0 stdoutB failures, 0 post failures ==

I won't dwell on that since clang is the priority.

The full git diff --stat output is too scary to copy in its entirety. Here is the last line

 498 files changed, 107880 insertions(+), 1377 deletions(-)

I will work on removing as many gratuitous differences as possible, but at the same time I'm adding regression tests, so I'm afraid this is just going to get bigger.

Finally, syscall and test coverage. I reckon that FreeBSD 12.1 has 363 syscalls
(not counting obsolete ones). 75 of these are covered by generic syscalls, 287 specific to FreeBSD. 43 of these are unimplemented. There are tests for at least 77 of these syscalls, plus a full scalar test.
Comment 37 Paul Floyd 2020-07-06 08:38:30 UTC
clang/x86 none/tests/sigsusp no longer hangs :-)

That 'only' leaves a couple of segfaults and client requests with clang as serious problems on FreeBSD 12.1.
Comment 38 Paul Floyd 2021-10-09 13:10:22 UTC
That's it. The Beastie has landed. Champagne tonight.

FreeBSD is now part of the official Valgrind code. When 3.18 is out I'll update the FreeBSD port (devel/valgrind) to point to the offical tarball.