【问题标题】:ld: file not found: /Library/Developer/.../libclang_rt.ubsan_osx_dynamic.dylibld:找不到文件:/Library/Developer/.../libclang_rt.ubsan_osx_dynamic.dylib
【发布时间】: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 -vclang -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 解决了这个问题。

标签: xcode macos clang ubsan


【解决方案1】:

据博客Friday Q&A 2015-07-03: Address Sanitizer by Mike Ash

知道为什么 Apple clang 不支持 -fsanitize=undefined

当我尝试得到:

clang -fsanitize=undefined ub.c
...
ld: file not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ubsan_osx_dynamic.dylib

斯宾塞在 2016-12-21 01:23:59:

如果您使用-fsanitize=address,undefined,它可以工作。希望这 帮助找到此帖子的其他人像我一样搜索该错误。

这对我们来说不是一个理想的解决方案,因为它们是独立的组件,而且我们对环境和工具的控制有限。我们不得不暂停一些 Address Sanitizer 测试,因为 Asan 使用 GCC 内联汇编和使用 ebp/rbp 作为通用寄存器会产生不正确的结果。而这里的环境和工具由Travis CI提供。


向 LLVM 提交了一份错误报告,地址为 Issue 33201, Apple Clang bundled with Xcode 8 does not reject -fsanitize=undefined when it should。由于它是一个 Apple Clang 错误(我们没有 iTunes 帐户向 Apple 提交该错误),因此它可能会因为离题而关闭。

【讨论】:

    【解决方案2】:

    为了使用未定义的行为清理程序,我必须使用 clang 以及 libcxx 和 libcxxabi 安装和构建 LLVM,即使我的 MacOS 已经附带了一个 clang 版本。 (结果我现在在我的电脑上安装了两个版本的 clang)。来自llvm getting started page

    cd where-you-want-llvm-to-live
    svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
    
    cd where-you-want-llvm-to-live
    cd llvm/tools
    svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
    
    cd where-you-want-llvm-to-live
    svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
    svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
    

    现在,我可以通过运行来使用未定义的行为清理程序

    /usr/local/bin/clang -fsanitize=undefined -O add.c -o add
    

    【讨论】:

      猜你喜欢
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 2021-05-07
      • 1970-01-01
      • 2018-10-20
      相关资源
      最近更新 更多