2

当我在使用编译器清理程序时,当仅在clang++.

请注意,当我删除-fsanitize=leak或添加这些标志时,链接问题消失了:-fsanitize=leak -fsanitize-trap=undefined.

另请注意,这种奇怪的链接错误似乎只在使用clang++. g++在下面显示的所有情况下都工作得很好。

$ clang++-11 -fsanitize=undefined ../main.cpp && ./a.out
../main.cpp:17:5: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../main.cpp:17:5 in

$ clang++-11 -fsanitize=undefined -fsanitize=leak ../main.cpp && ./a.out
/usr/bin/ld: /tmp/main-920ee1.o: in function `main':
main.cpp:(.text+0x6a): undefined reference to `__ubsan_handle_add_overflow'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ clang++-11 -fsanitize=undefined -fsanitize=leak -fsanitize-trap=undefined ../main.cpp && ./a.out
Illegal instruction

$ clang++-11 -v
Debian clang version 11.0.0-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64

任何线索都可能有所帮助。谢谢。

main.cpp如果您需要(您可能永远不会这样做)的源代码:

int main(int argc, char **argv) {
  int k = 0x7fffffff;
  k += argc;
  return 0;
}
4

0 回答 0