8

Valgrind is not compatible with macOS 12 now, and I tried to add compile flag -fsanitize=address, but got link error:

Undefined symbols for architecture x86_64:
  "___asan_init", referenced from:
      _asan.module_ctor in main.cpp.o
  "___asan_version_mismatch_check_apple_clang_1300", referenced from:
      _asan.module_ctor in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there any way to make Valgrind compatible with macOS 12?

2 Answers 2

13

Are there any patches via macports or brew that allow you to install Valgrind on macOS 12?

It's all a question of resources. I think that I'm the only active Valgrind dev that uses macOS, but my focus is on FreeBSD. It's a bit of a pity that Apple (market cap of $2.4 trillion at the time of writing) can't commit some relatively small amount of effort to achieve this. There are several IBM engineers contributing (directly for s390 and PPC and indirectly via RedHat).

The changes required to the Valgrind configure scripts are fairly minor.

Try this

AC_DEFINE([XCODE_12_0], 110000, [XCODE_VERS value for Xcode 12.0])

and after line 555

12.*)
            AC_DEFINE([XCODE_VERS], XCODE_12_0, [Xcode version])
            ;;
  • duplicate the case block for kernel version 21.0 (line 526), something like
       # comes after the 20.0) case
       21.*)
      AC_MSG_RESULT([Darwin 21.x (${kernel}) / macOS 12 Monterey])
      AC_DEFINE([DARWIN_VERS], DARWIN_12_00, [Darwin / Mac OS X version])
      DEFAULT_SUPP="darwin20.supp ${DEFAULT_SUPP}"
      DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
                  ;;
  • (ignore the suppression version for now)
  • run ./autogen.sh
  • run ./configure
  • run make
  • if that all works run ./vg-in-place yes

Doing the above plus a few more changes for DARWIN_12, I get

paulf> ./vg-in-place yes
==12358== Memcheck, a memory error detector
==12358== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==12358== Using Valgrind-3.18.0.GIT-lbmacos and LibVEX; rerun with -h for copyright info
==12358== Command: yes
==12358== 

valgrind: m_mach/dyld_cache.c:244 (int try_to_init(void)): Assertion 'dyld_cache.header->mappingCount == 3' failed.
Sign up to request clarification or add additional context in comments.

5 Comments

Is the source of that git repo the same as the one you're commenting on? The line numbers dont really match up with what I see...Also, when you reference line numbers (e.g. "add new versions for XCode 12: after line 435" is the line number referenced correct after having completed previous instructions? or before any insertions were done at all?) Thanks!
I tried building that branch with no changes and I get a compile error: m_debuginfo/debuginfo.c:1564:12: error: no member named 'have_rw_map' in 'struct _DebugInfoFSM'
This commit from upstream fixes that commit 0ea3746e978420963760051e6f821f9b5c3d872d Author: Paul Floyd <snip> Date: Thu Oct 20 23:11:42 2022 +0200 Fix build on macOS A while back when I added support for split RW PT_LOAD sections one instance in the macho code didn't get updated. Also update the comment that refers to the old struct member that got renamed.
I figured out the error: the function di_notify_mmap_in_memory was removed in base but not the branch. It appears to be a near copy of di_notify_mmap but it isnt getting the updates, so members which were changed like have_rw_map werent changed in the di_notify_mmap_in_memory version which is causing a compile error.
Welp, now link is failing: ld: warning: building for macOS 10.6 is deprecated ld: warning: ignoring file ../coregrind/libcoregrind-amd64-darwin.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64 ld: warning: ignoring file ../VEX/libvex-amd64-darwin.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 ) Undefined symbols for architecture x86_64: "_IRConst_U1", referenced from:
2

I don't have enough reputation to comment on Paul's post. After I made the changes he stated, I got the following error. I am currently on Monterey 12.1 Beta (21C5021h) with Intel i7.

./vg-in-place yes
==30798== Memcheck, a memory error detector
==30798== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==30798== Using Valgrind-3.18.0.GIT-lbmacos and LibVEX; rerun with -h for copyright info
==30798== Command: yes
==30798== 
==30798== Invalid read of size 8
==30798==    at 0x100017126: cerror_nocancel (in /usr/lib/dyld)
==30798==    by 0x1000156E8: kdebug_is_enabled (in /usr/lib/dyld)
==30798==    by 0x10004215B: dyld3::kdebug_trace_dyld_marker(unsigned int, dyld3::kt_arg, dyld3::kt_arg, dyld3::kt_arg, dyld3::kt_arg) (in /usr/lib/dyld)
==30798==    by 0x100019375: (below main) (in /usr/lib/dyld)
==30798==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==30798== 
==30798== 
==30798== Process terminating with default action of signal 11 (SIGSEGV)
==30798==  Access not within mapped region at address 0x8
==30798==    at 0x100017126: cerror_nocancel (in /usr/lib/dyld)
==30798==    by 0x1000156E8: kdebug_is_enabled (in /usr/lib/dyld)
==30798==    by 0x10004215B: dyld3::kdebug_trace_dyld_marker(unsigned int, dyld3::kt_arg, dyld3::kt_arg, dyld3::kt_arg, dyld3::kt_arg) (in /usr/lib/dyld)
==30798==    by 0x100019375: (below main) (in /usr/lib/dyld)
==30798==  If you believe this happened as a result of a stack
==30798==  overflow in your program's main thread (unlikely but
==30798==  possible), you can try to increase the size of the
==30798==  main thread stack using the --main-stacksize= flag.
==30798==  The main thread stack size used in this run was 8388608.
==30798== 
==30798== HEAP SUMMARY:
==30798==     in use at exit: 0 bytes in 0 blocks
==30798==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==30798== 
==30798== All heap blocks were freed -- no leaks are possible
==30798== 
==30798== For lists of detected and suppressed errors, rerun with: -s
==30798== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
./vg-in-place: line 31: 30798 Segmentation fault: 11  VALGRIND_LIB="$vgbasedir/.in_place" VALGRIND_LIB_INNER="$vgbasedir/.in_place" "$vgbasedir/coregrind/valgrind" "$@"

1 Comment

I expect that a fair amount more work will need to be done to get it to work reliably.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.