【发布时间】:2017-08-11 03:42:26
【问题描述】:
我正在尝试通过这样的构建来使用未定义的行为清理器
gcc -fsanitize=undefined add.c -o add
还有
clang -fsanitize=undefined -O add.c -o add
在这两种情况下,我都会收到文件未找到错误:
ld: file not found: /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ubsan_osx_dynamic.dylib
这是我在运行gcc -v 和clang -v 时得到的输出
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
根据this news release,它在GCC 和original homepage 中都可用,因为它表示它已被合并到LLVM。链接到文章说 GCC 4.9 有它,我想我有(至少 -- 版本编号似乎不同,但这篇文章是几年前写的,我已经多次更新我的系统)。
问题:如何构建可执行文件以使用 UBSan?
【问题讨论】:
-
你没有gcc,你有clang伪装成gcc。它应该仍然有效。你确定你有完整的 XCode 安装吗?
-
@MarcGlisse 我安装了命令行工具,而不是 xcode
-
在 llvm 博客 (blog.llvm.org/2013/04/testing-libc-with-fsanitizeundefined.html) 上有一篇关于它的文章,但它似乎需要构建几个库 (libc++ libc++abi) 冒着覆盖关键系统库的风险,所以我没有没试过(因此不会回答我自己的问题)
-
-fsanitize=undefined标志遇到了同样的问题。升级到Xcode 10.0解决了这个问题。