转载:asan 使用

十二月 10, 2025 [C/C++] #obsidian #调试 #编译链接 #安全

转载:asan 使用

原文:https://www.cnblogs.com/fellow1988/p/17263427.html

参考:

1. make cflags

# 静态链接 libasan
static: gcc test.c -o test -fsanitize=address -static-libasan -g

# 动态链接 libasan
dynamic: gcc test.c -o test -fsanitize=address -lasan -g

2. asan env

export ASAN_OPTIONS=halt_on_error=false:print_scariness=true:fast_unwind_on_malloc=true:detect_leak=1

ASAN_OPTIONS 是 Address-Sanitizer 的运行选项环境变量。常用选项:

除了上述常用选项,以下还有一些选项可根据实际需要添加:

3. asan runtime does not come first in initial library list

export LD_PRELOAD=/usr/lib/basan.so