macOS 12 Monterey 上的内存检查?

Memory check on macOS 12 Monterey?

Valgrind 现在与 macOS 12 不兼容,我尝试添加编译标志 -fsanitize=address,但出现 link 错误:

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)

有没有办法让 Valgrind 兼容 macOS 12?

是否有任何通过 macports 或 brew 的补丁允许您在 macOS 12 上安装 Valgrind?

都是资源的问题。我认为我是唯一使用 macOS 的活跃 Valgrind 开发人员,但我的重点是 FreeBSD。遗憾的是,Apple(撰写本文时市值 2.4 万亿美元)无法通过相对较小的努力来实现这一目标。有几位 IBM 工程师做出了贡献(直接为 s390 和 PPC 做出贡献,并通过 RedHat 间接做出贡献)。

Valgrind 配置脚本所需的更改相当小。

试试这个

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

第 555 行之后

12.*)
            AC_DEFINE([XCODE_VERS], XCODE_12_0, [Xcode version])
            ;;
  • 复制内核版本 21.0 的 case 块(第 526 行),类似于
       # 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}"
                  ;;
  • (暂时忽略打压版)
  • 运行 ./autogen.sh
  • 运行 ./configure
  • 运行 make
  • 如果一切正常运行./vg-in-place yes

执行上述操作并针对 DARWIN_12 进行一些更改,我得到

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.

我没有足够的声誉来评论 Paul 的 post。 在我按照他所说的进行更改后,出现以下错误。 我目前在使用 Intel i7 的 Monterey 12.1 Beta (21C5021h)。

./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" "$@"