【问题标题】:Xcode Address Sanitizer with ccacheXcode Address Sanitizer 与 ccache
【发布时间】:2017-10-09 15:40:08
【问题描述】:

我正在尝试在 Xcode 中使用 Address Sanitizer,但我也在使用 ccache 来加速我的构建。为此,我在 Xcode 项目级别设置了 CC 标志,以指向我存储在 ~/projects/support/cmake/ccache-clang 的脚本。脚本读取

#!/bin/sh
if type -p /usr/local/bin/ccache >/dev/null 2>&1; then
  export CCACHE_CPP2=true
  exec /usr/local/bin/ccache "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
else
  exec "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
fi

这样就达到了预期的效果(如果安装在开发者的系统上,则使用ccache)。这很好用。

现在,当我们为给定方案打开 Address Sanitizer 时,问题就来了。构建成功完成,但是当我们尝试运行时,我们终于看到了这个错误:

Error: Check dependencies

Could not determine version of clang to find its Address Sanitizer library: ~/projects/support/cmake/ccache-clang

也许这是由于 Xcode 中的一些 hacky 实现,它试图解析编译器的路径以确定版本?

想知道如何修改我的脚本以允许 Address Sanitizer 工作。当前的解决方法是在我们需要进行消毒工作时删除覆盖的 CC 标志。

使用 Xcode 8.3.1

【问题讨论】:

    标签: xcode xcode8 address-sanitizer ccache


    【解决方案1】:

    直接链接 Asan 库,而不是选中方案中的复选框。

    链接器编译器标志应该包含以下内容。

    -fsanitize=address -fno-omit-frame-pointer
    

    如果找不到库,则找到通常在的asan动态库的路径

    ${CMAKE_LINKER}/../../lib/clang/version/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
    

    并将其添加到链接器标志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-16
      • 2016-12-25
      • 2022-01-23
      • 2020-12-18
      • 2020-07-01
      • 2021-12-02
      • 2015-09-17
      • 2018-10-28
      相关资源
      最近更新 更多