我运行的是 OS X,10.8.5;我已经通过 homebrew 安装了 llvm 3.4 (clang version 3.4 (tags/RELEASE_34/final) ),并且我正在使用 -fsanitize=address 进行构建。我可以让 asan 使用简单的演示程序,但是在针对我们的代码库进行构建时,我遇到了几个问题(尽管我真的只想回答 #1):
-
3rd 方库正在生成 asan 错误,并且 asan 第一次出现时就会终止我的应用程序。我认为会有某种(运行时/编译时)选项来告诉 asan 在发现错误后继续前进。具体来说,我看到的是这样的:
bash-3.2$ ASAN_SYMBOLIZER_PATH=/usr/local/Cellar/llvm34/3.4/lib/llvm-3.4/bin/llvm-symbolizer ./unit_test
Start testing of PathTrieTest
Config: Using QTest library 4.8.2, Qt 4.8.2
PASS : PathTrieTest::initTestCase()
PASS : PathTrieTest::pathTrieNodeTest()
=================================================================
==76647==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61600019e588 at pc 0x10891ddd3 bp 0x11312ba90 sp 0x11312ba58
WRITE of size 48830 at 0x61600019e588 thread T3
#0 0x10891ddd2 in wrap_readdir_r (/usr/local/lib/llvm-3.4/lib/clang/3.4/lib/darwin/libclang_rt.asan_osx_dynamic.dylib+0x11dd2)
#1 0x10ac23571 in QFileSystemIterator::advance(QFileSystemEntry&, QFileSystemMetaData&) (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xef571)
#2 0x10abd86d3 in QDirIteratorPrivate::advance() (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xa46d3)
#3 0x10abd7a7f in QDirIteratorPrivate::QDirIteratorPrivate(QFileSystemEntry const&, QStringList const&, QFlags<QDir::Filter>, QFlags<QDirIterator::IteratorFlag>, bool) (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xa3a7f)
#4 0x10abd8b68 in QDirIterator::QDirIterator(QDir const&, QFlags<QDirIterator::IteratorFlag>) (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xa4b68)
#5 0x10abd7609 in QDirPrivate::initFileLists(QDir const&) const (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xa3609)
#6 0x10abd5394 in QDir::count() const (/Volumes/ToolChain/qt-4.8/lib/QtCore.framework/Versions/4/QtCore+0xa1394)
#7 0x1084c205d in get_count(QFileInfo&) /Users/stebro/dev_vm/ui/ui/fsinfoprovider.cpp:36
...
当应用程序未经清理运行时,此错误不会导致应用程序终止。
-
使用 -fsanitize=undefined (或 -fsanitize=address,undefined)选项时,我无法获取要链接的代码。我在编译和链接命令中都包含 -fsanitize=undefined 行,但出现链接错误,例如:
Undefined symbols for architecture x86_64:
"typeinfo for __cxxabiv1::__class_type_info", referenced from:
__ubsan::checkDynamicType(void*, void*, unsigned long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
"typeinfo for __cxxabiv1::__si_class_type_info", referenced from:
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
"typeinfo for __cxxabiv1::__vmi_class_type_info", referenced from:
isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
findBaseAtOffset(__cxxabiv1::__class_type_info const*, long) in libclang_rt.ubsan_osx.a(ubsan_type_hash.o)
-
我无法让黑名单工作,并且 -mllvm -asan-globals=0 或 -mllvm -asan-stack=0 似乎没有像我预期的那样工作。例如,后者不会抑制上面 #1 中列出的错误的生成,并且创建如下所示的黑名单也不会抑制错误:
fun:QDirPrivate::initFileLists
fun:get_count
fun:*opendir2*
-
最后,使用这些 asan 选项生成的可执行文件会导致 lldb 崩溃。我正在使用 XCode 5 工具附带的 lldb;没有使用 homebew llvm 包部署 lldb,我不知道如何构建它。构建说明在此输入链接描述 http://lldb.llvm.org/download.html有一个指向您应该使用的源的无效链接;直接从 svn 存储库中提取源代码,使用:
svn co http://llvm.org/svn/llvm-project/lldb/tags/RELEASE_34/final lldb
导致代码无法编译(根据请求提供错误)。
您可以使用以下方式构建您的项目-fsanitize=address -fsanitize-recover=address
标志,并使用环境变量运行ASAN_OPTIONS=halt_on_error=0
。
来源:https://github.com/google/sanitizers/wiki/AddressSanitizer https://github.com/google/sanitizers/wiki/AddressSanitizer
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)