在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
根据文档,也不需要。
这是摆脱错误的正确方法,还是有更强大的解决方案?