5

在clang中,如果程序使用128位整数时未定义的行为清理器( ) ,我会遇到链接错误。-fsanitize=undefined链接错误抱怨__muloti4

$ cat example.c
__int128_t a;
int main (void) {
  a = a * a;
  return 0;
}

$ clang -fsanitize=undefined example.c 
/tmp/example-df4873.o: In function `main':
example.c:(.text+0x4c): undefined reference to `__muloti4'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(在带有 clang 4.0.1 的 Ubuntu 17.10 上测试。)

使用 gcc,它可以开箱即用 ( gcc -fsanitize=undefined example.c)。

与 clang 一起使用的是以下调用,但我既不完全理解它(--rtlib=compiler-rt),也不像我这样:

clang -lgcc_s -lubsan --rtlib=compiler-rt -fsanitize=undefined /tmp/example.c

我通过反复试验找到了它,但是使用 clang 和链接一些 gcc 库感觉不对。还明确链接到ubsan根据文档,也不需要。

这是摆脱错误的正确方法,还是有更强大的解决方案?

4

1 回答 1

4

这是一个已知问题(另见此。Libgcc(默认情况下与 clang 链接)不提供必要的符号来清理 128 位类型,因此您需要让 clang 使用 compiler-rt 运行时库。

于 2018-04-12T11:32:15.910 回答