ASAN - 抑制外部库中的报告(LLVM 13,Windows)

ASAN - Suppressing Reports in External Libraries (LLVM 13, Windows)

我试图抑制外部库中的 ASAN 问题,因此我正在关注 llvm-asan-suppressing-reports-in-external-libraries,文档说:

If you run into an issue in external libraries, we recommend immediately reporting it to the library maintainer so that it gets addressed Blockquote

更新:这里是link问题,Issue 45842: AddressSanitizer: bad-free - hello world c extension - Python tracker

ASAN 踪迹

==6968==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x01e7aceb3be0 in thread T0
    #0 0x7ffec9a97f31  (D:\a\min_reprex_python_c_extension_asan\min_reprex_python_c_extension_asan\llvm\lib\clang.0.0\lib\windows\clang_rt.asan_dynamic-x86_64.dll+0x180037f31)
    #1 0x7ffeca696030  (C:\hostedtoolcache\windows\Python.10.0\x64\python310.dll+0x180026030)
    #2 0x7ffeca67aaaf  (C:\hostedtoolcache\windows\Python.10.0\x64\python310.dll+0x18000aaaf)

...

    #114 0x7ff72208122f  (C:\hostedtoolcache\windows\Python.10.0\x64\python.exe+0x14000122f)
    #115 0x7ffefee17973  (C:\Windows\System32\KERNEL32.DLL+0x180017973)
    #116 0x7fff0071a2f0  (C:\Windows\SYSTEM32\ntdll.dll+0x18005a2f0)

Address 0x01e7aceb3be0 is a wild pointer inside of access range of size 0x000000000001.
SUMMARY: AddressSanitizer: bad-free (D:\a\min_reprex_python_c_extension_asan\min_reprex_python_c_extension_asan\llvm\lib\clang.0.0\lib\windows\clang_rt.asan_dynamic-x86_64.dll+0x180037f31) 
==6968==ABORTING

Here link 到完整的 ASAN 跟踪。

到目前为止我做了什么

我创建了一个 my_asan.supp 并按照文档中的建议用 ASAN_OPTIONS=suppressions=my_asan.supp 加载了它,内容如下:

interceptor_via_fun:_PyObject_Realloc
interceptor_via_fun:realloc
interceptor_via_lib:C:/Python39/python3.dll
interceptor_via_lib:C:/s/eklang/DevOps/clang/bin/LLVM-13.0.0-win64/lib/clang/13.0.0/lib/windows/clang_rt.asan_dynamic-x86_64.dll
interceptor_via_lib:C:/Windows/System32/KERNEL32.DLL
interceptor_via_lib:C:/Windows/SYSTEM32/ntdll.dll
interceptor_via_lib:C:\Python39\python3.dll
interceptor_via_lib:C:\s\eklang\DevOps\clang\bin\LLVM-13.0.0-win64\lib\clang.0.0\lib\windows\clang_rt.asan_dynamic-x86_64.dll
interceptor_via_lib:C:\Windows\System32\KERNEL32.DLL
interceptor_via_lib:C:\Windows\SYSTEM32\ntdll.dll
interceptor_via_lib:clang_rt.asan_dynamic-x86_64.dll
interceptor_via_lib:ntdll
interceptor_via_lib:ntdll.dll
interceptor_via_lib:python3
interceptor_via_lib:python3.dll
interceptor_via_lib:KERNEL32
interceptor_via_lib:KERNEL32.dll

None 这些似乎都有效,我做错了什么?我尝试了完整路径、正斜杠、反斜杠、dll 名称...

信息

LLVM 13,Windows10

当未使用 asan 编译的可执行文件(在本例中为 python.exe)加载使用 i.

编译的 dll 时

需要确保首先加载 asan runtime 才能发挥它的魔力并正确拦截 mallocfree,在 [=32] 下=] 这很简单,可以使用 LD_PRELOAD(互联网上有很多关于如何做到这一点的示例)。

虽然在 windows 中,这似乎是不可能的,因此解决方法似乎是使用 clang_rt.asan-preinit-x86_64.libclang_rt.asan-x86_64.lib 链接并调用 python 来制作可执行包装器在那里,稍后将加载需要用 clang_rt.asan_dll_thunk-x86_64.lib.

编译的 dll

整个事情听起来很复杂,但到目前为止似乎可行。 This article 帮助了我。