我用g++
和cmake
编译了AddressSanitizer(asan)的C++库:
SET( AXULIARY_COMPILE_FLAGS "-g -Og -fsanitize=address -fno-omit-frame-pointer")
当运行独立的C/C++可执行程序时,这工作得很好。但是当用ctypes
将其作为共享/动态库(.so
)加载到python中时,我无法使其工作:
run.sh:
#!/bin/bash
#LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so
LD_PRELOAD=$(g++ -print-file-name=libasan.so)
echo $LD_PRELOAD
export $LD_PRELOAD
python3 run_asan.py
run_asan.py:
import ctypes ;print("DEBUG 1 ")
asan = ctypes.CDLL( "/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so", mode=ctypes.RTLD_LOCAL ) ;print("DEBUG 2 ")
lib = ctypes.CDLL( "../../cpp/Build/libs/Molecular/libMMFFsp3_lib.so", mode=ctypes.RTLD_LOCAL ) ;print("DEBUG 3 ")
不断收到此错误:
prokop@DesktopGTX3060:~/git/FireCore/tests/tMMFFsp3$ ./run.sh
/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so
./run.sh-: line 7: export: `/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so': not a valid identifier
DEBUG 1
==20016==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
我还尝试将asan与cmake静态链接,但这也不起作用:
run_asan.py
import ctypes; print("DEBUG 1 ")
lib = ctypes.CDLL( "../../cpp/Build/libs/Molecular/libMMFFsp3_lib.so", mode=ctypes.RTLD_LOCAL )
prokop@DesktopGTX3060:~/git/FireCore/tests/tMMFFsp3$ python3 run_asan.py
/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so
./run.sh-: line 7: export: `/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so': not a valid identifier
DEBUG 1
Traceback (most recent call last):
File "/home/prokop/git/FireCore/tests/tMMFFsp3/run_asan.py", line 3, in <module>
lib = ctypes.CDLL( "../../cpp/Build/libs/Molecular/libMMFFsp3_lib.so", mode=ctypes.RTLD_LOCAL ) ;print("DEBUG 3 ")
File "/usr/lib/python3.10/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ../../cpp/Build/libs/Molecular/libMMFFsp3_lib.so: undefined symbol: __asan_option_detect_stack_use_after_return
1条答案
按热度按时间j7dteeu81#
您应该使用
而不是