|
From: Paul F. <pa...@so...> - 2026-03-09 07:28:52
|
https://sourceware.org/cgit/valgrind/commit/?id=8338e4a11c695b8b24ccb06bae4ed9d611de4d88 commit 8338e4a11c695b8b24ccb06bae4ed9d611de4d88 Author: Paul Floyd <pj...@wa...> Date: Mon Mar 9 08:05:39 2026 +0100 Darwin stack size Darwin wasn't using --main-stacksize. Instead the stack was being set based on rlimit (in my tests I saw that it could also be set from macho, but it appears to specify a size of 0, at least on regtest files compiled on macOS 12. Also unlike other OSes there was no lower/upper limit of 1MB and 16MB. It looks like all four platforms now have duplicated code for setting the main client stack size, so I should probably factor it out into something like VG_(get_default_stack_size)(). With this change I tried to get the lsframe1 and lsframe2 tests to work. With some twiddling of the stack and frame size they seem to work. One issue is that Darwin has a function that probes below the stack. I think that is related to stack growth. We don't implement a grow down stack on Darwin. The whole stack gets mapped in one go. So this probing does not serve much purpose under Valgrind but it does generate a lot of memcheck noise. ~t seems as though the name of this probe function changed with macOS 12. Previously it was __chkstk_darwin_probe. With macOS 12 it is ___chkstk_darwin. So I added a couple of wildcards to the suppressions so that they match both versions. Diff: --- coregrind/m_ume/macho.c | 21 +++++++++++++++++---- darwin.supp | 6 ++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/coregrind/m_ume/macho.c b/coregrind/m_ume/macho.c index 22f2d7a0d6..536eef261e 100644 --- a/coregrind/m_ume/macho.c +++ b/coregrind/m_ume/macho.c @@ -42,6 +42,7 @@ #include "pub_core_mallocfree.h" // VG_(malloc), VG_(free) #include "pub_core_syscall.h" // VG_(strerror) #include "pub_core_clientstate.h" +#include "pub_core_options.h" #include "pub_core_ume.h" // self #include "priv_ume.h" @@ -349,10 +350,22 @@ load_genericthread(struct thread_command *threadcmd, int type, GrP fixme 64-bit? */ static vki_size_t default_stack_size(void) { - struct vki_rlimit lim; - int err = VG_(getrlimit)(VKI_RLIMIT_STACK, &lim); - if (err) return 8*1024*1024; // 8 MB - else return lim.rlim_cur; + SizeT m1 = 1024 * 1024; + SizeT m16 = 16 * m1; + SizeT szB = (SizeT)VG_(client_rlimit_stack).rlim_cur; + if (szB < m1) { + szB = m1; + } + if (szB > m16) { + szB = m16; + } + if (VG_(clo_main_stacksize) > 0) { + szB = VG_(clo_main_stacksize); + } + if (szB < m1) { + szB = m1; + } + return szB; } diff --git a/darwin.supp b/darwin.supp index b53ea93596..9d6506492c 100644 --- a/darwin.supp +++ b/darwin.supp @@ -782,10 +782,12 @@ # I suppose that this is deliberate # and that Apple know what they are doing? +# On macOS 12 at least this seems to have changed name to ___chkstk_darwin +# this matches both { macOS1015:__chkstk_darwin_probe Memcheck:Addr8 - fun:__chkstk_darwin_probe + fun:__*chkstk_darwin* } { @@ -815,7 +817,7 @@ { macOS1100:__chkstk_darwin_probe Memcheck:Addr1 - fun:__chkstk_darwin_probe + fun:__*chkstk_darwin* } { |