在叮当声中,如果
Undefined Behavior Sanitizer
(
-fsanitize=undefined
)当程序使用128位整数时。链接错误抱怨
__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)
(在Ubuntu 17.10和clang 4.0.1上测试。)
使用gcc,它可以开箱即用(
gcc -fsanitize=undefined example.c
)。
下面的调用对clang起作用,但我都不完全理解(
--rtlib=compiler-rt
),在我看来也不像:
clang -lgcc_s -lubsan --rtlib=compiler-rt -fsanitize=undefined /tmp/example.c
我通过反复试验找到了它,但对某些gcc库使用clang和link感觉是错误的。还显式链接到
ubsan
根据
documentation
。
这是消除错误的正确方法,还是有更可靠的解决方案?