gpt4 book ai didi

c++ - 使用 Clang 的 "undefined" sanitizer 时 undefined symbol

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:45:06 27 4
gpt4 key购买 nike

此代码在启用 clang 的“未定义行为” sanitizer 程序的情况下编译良好:

➜  ~ cat test.cc 
#include <iostream>

int main(int argc, char **argv) {
// Won't compile if next line will be uncommented!
// std::cout << "Hello, World!" << std::endl;
int k = 0x7fffffff;
k += argc;
return 0;
}
➜ ~ clang++ -fsanitize=address -fsanitize=undefined test.cc

然而,当我取消注释提到的行时,它会爆炸:

  ~ clang++ -fsanitize=address -fsanitize=undefined test.cc   
Undefined symbols for architecture x86_64:
"___ubsan_handle_dynamic_type_cache_miss", referenced from:
_main in test-5f28d3.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-5f28d3.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in test-5f28d3.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in test-5f28d3.o
"___ubsan_vptr_type_cache", referenced from:
_main in test-5f28d3.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in test-5f28d3.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in test-5f28d3.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in test-5f28d3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

clang 版本:

➜  ~ clang --version
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

详细的编译器输出是 here .

我做错了什么?

最佳答案

通过使用来自 llvm 站点的 clang/llvm 二进制文件而不是 Apple 的 clang 解决了问题。

关于c++ - 使用 Clang 的 "undefined" sanitizer 时 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40284307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com