Phi*_*ßen 6 c clang linker-errors sanitizer ubsan
在 clang 中,当程序使用 128 位整数时,如果未定义行为 Sanitizer ( ) ,我会遇到链接错误。-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)
Run Code Online (Sandbox Code Playgroud)
(在 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
Run Code Online (Sandbox Code Playgroud)
我通过反复试验找到了它,但使用 clang 并链接到某些 gcc 库感觉是错误的。根据文档ubsan
,也不需要明确链接。
这是消除错误的正确方法,还是有更可靠的解决方案?