Bug 508638

Summary: Self-hosting not working on FreeBSD
Product: [Developer tools] valgrind Reporter: Paul Floyd <pjfloyd>
Component: generalAssignee: Paul Floyd <pjfloyd>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: FreeBSD   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Paul Floyd 2025-08-23 10:42:38 UTC
The inner fails very early on. VG_(am_create_reservation) can't get a single segment (why?) in setup_client_stack.

I need to check that this is still working on Linux.
Comment 1 Paul Floyd 2025-08-25 19:22:18 UTC
No problem on Linux.

${HOME}/tools/valgrind/bin/valgrind --sim-hints=enable-outer --trace-children=yes  \
       --smc-check=all-non-file \
       --run-libc-freeres=no --tool=none -q \
       ./vg-in-place --vgdb-prefix=./inner --tool=none -q true

^^^ runs without a squeak

A while back I did increase the FreeBSD memory space from 32Gb to 128Gb 
35bb01dd450bfe3ba658ec5b58bc9f47dfc4c2aa
    FreeBSD: make amd64 aspace max mem 128Gbytes

Also this diff

78a7f9244163bd6dba3b556f3708269a49a59243

    FreeBSD: clean up guest stack creation code

-
-   suggested_clstack_end = aspacem_maxAddr - (kern_maxssiz - kern_sgrowsiz) + VKI_PAGE_SIZE;
+   VG_(printf)("maxssiz %lx\n", kern_maxssiz);
+   //suggested_clstack_end = aspacem_maxAddr - (kern_maxssiz - kern_sgrowsiz) + VKI_PAGE_SIZE;
 #endif
 
+   // on amd64 we have oodles of space and just shove the new stack somewhere out of the way
+   // x86 is far more constrained, and we put the new stack just below the stack passed in to V
+   // except that it has stack space and the growth stack guard below it as decribed above
+   // so we need to skip over the existing stack/growth area on x86
+
+# if VG_WORDSIZE == 4
    suggested_clstack_end = aspacem_maxAddr - 64*1024*1024UL
                                            + VKI_PAGE_SIZE;
-
 #else
-   suggested_clstack_end = aspacem_maxAddr - 16*1024*1024UL
-                                           + VKI_PAGE_SIZE;
-
+   suggested_clstack_end = aspacem_maxAddr;
 #endif
Comment 2 Paul Floyd 2025-08-25 19:59:07 UTC
Looks like it was the second change.  I've fixed that (at least for amd64) and I now get two errors

>--2573-- Reading syms from /home/paulf/z400/paulf/scratch/valgrind_inner/none/none-amd64-freebsd
>--2573--    object doesn't have a dynamic symbol table
>--2573-- Reading syms from /home/paulf/tools/valgrind/libexec/valgrind/none-amd64-freebsd
>--2573-- ELF section outside all mapped regions

Not too serious for getting things running, need to sort it out in order to be able to get callstacks. Then

>==2573== error 9 Bad file descriptor
>==2573== mknod ./inner-to-vgdb-from-2573-by-paulf-on-green
>==2573== valgrind: fatal error: vgdb FIFOs cannot be created.
Comment 3 Paul Floyd 2025-08-26 08:29:34 UTC
OK this is my fault. In 52dddd460b0778f862c062c82d8d2819f740c268 I messed up the handling of AT_FDCWD in mknodat

f6f7cae623 (Paul Floyd 2023-02-25 16:09:41 +0100)    PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
52dddd460b (Paul Floyd 2025-08-23 14:19:33 +0200)    if (!ML_(fd_allowed)(ARG1, "mknodat", tid, False))
52dddd460b (Paul Floyd 2025-08-23 14:19:33 +0200)       SET_STATUS_Failure(VKI_EBADF);
f6f7cae623 (Paul Floyd 2023-02-25 16:09:41 +0100) }

The FreeBSD generic wrappers for bindat, connectat, chflagsat and utimesat all have the same problem.

Whilst I'm at it, Linux openat2 has a message referring to openat (copy and paste)
Comment 4 Paul Floyd 2025-08-26 11:38:11 UTC
Seems to work now.

For this message

>--86152-- Reading syms from /home/paulf/tools/valgrind/libexec/valgrind/memcheck-amd64-freebsd
>--86152-- ELF section outside all mapped regions

that's the outer as seen by the inner. so not really an issue that it can't read symbols.

Also there is

==86152== Warning: ignored attempt to set SIG128 handler in sigaction();
==86152==          the SIG128 signal is used internally by Valgrind

for another day.
Comment 5 Paul Floyd 2025-08-26 11:38:25 UTC
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Tue Aug 26 13:32:07 2025 +0200

    Bug 508638 - Self-hosting not working on FreeBSD