gpt4 book ai didi

python - python 扩展上的地址 sanitizer

转载 作者:行者123 更新时间:2023-11-28 16:58:53 25 4
gpt4 key购买 nike

我正在尝试使用 Address Sanitizer 编译 python 扩展。当我加载扩展时,我得到

Traceback (most recent call last):
File "test.py", line 2, in <module>
from extension import package
File "/tmp/python_test/extension/package.py", line 28, in <module>
from extension._ext import *
ImportError: /tmp/python_test/extension/_ext.so: undefined symbol: __asan_version_mismatch_check_v8

编译器调用是

clang -g -o _ext.so code.ll -fsanitize=address -lrt -lpthread -ldl -lstdc++ -lm -fPIC -shared

因此,它无法正确加载来自 asan 的符号。我试过使用 -static-libsan ,但结果是一样的。

我看到有些人使用 LD_PRELOAD然而,为了让 Asan 进入共享对象,似乎 libasan.so在我的系统上来自不同版本的 Address Sanitizer(从 Debian 的 libasan3 软件包安装,而我从 deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-8 main 得到 clang)。

那么,如何让 Address Sanitizer 与共享对象库一起工作?或者,我需要正确版本的 libasan.so (它似乎不在 deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-8 main 中,或者我需要一种静态链接的方法)。

我的 clang 版本:

$ clang -v
clang version 8.0.0-svn356034-1~exp1~20190313094216.53 (branches/release_80)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

最佳答案

要使用 Clang 清理单个库(而不清理主 python 可执行文件),您应该

  • -shared-libasan 添加到 LDFLAGS(Clang 默认为 -static-libasan,与 GCC 不同)
  • 使用 LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) 运行(它应该在标准 Clang 库中)

(参见 AddressSanitizerAsDso wiki)。

另一种选择是使用 GCC,在这种情况下,不需要 -shared-libasan 并且 LD_PRELOAD 值变为 libasan.so.N( N 取决于 GCC 版本,使用 $(gcc -print-file-name=libasan.so) 来定位它。

有关 GCC 和 Clang 在清理 shlib 方面的差异的更多详细信息,请参阅 this answer .

关于python - python 扩展上的地址 sanitizer ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55692357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com