【问题标题】:Memory check on macOS 12 Monterey?macOS 12 Monterey 上的内存检查?
【发布时间】:2021-12-15 22:06:30
【问题描述】:

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

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 兼容?

【问题讨论】:

    标签: c++ memory-leaks clang llvm valgrind


    【解决方案1】:

    我没有足够的声誉来评论 Paul 的帖子。 在我进行他所说的更改后,我收到以下错误。 我目前正在使用 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" "$@"
    

    【讨论】:

    • 我预计需要做更多的工作才能使其可靠地工作。
    【解决方案2】:

    是否有任何通过 macports 或 brew 提供的补丁可以让您在 macOS 12 上安装 Valgrind?

    这都是资源问题。我认为我是唯一使用 macOS 的活跃 Valgrind 开发人员,但我的重点是 FreeBSD。有点遗憾的是,苹果(撰写本文时市值为 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(第 526 行)的 case 块,类似于
           # 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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-14
      • 2021-12-19
      • 2021-12-19
      • 2022-01-24
      • 2022-09-25
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多