代码之家  ›  专栏  ›  技术社区  ›  Philipp Claßen

clang:-fsanitize=未定义128个整数运算(未定义对“\uu muloti4”的引用)

  •  6
  • Philipp Claßen  · 技术社区  · 7 年前

    在叮当声中,如果 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

    这是消除错误的正确方法,还是有更可靠的解决方案?

    1 回复  |  直到 7 年前
        1
  •  5
  •   yugr    7 年前

    这是一个 known problem (另请参见 this ).Libgcc(默认情况下,clang链接的对象)没有提供必要的符号来清理128位类型,因此您需要要求clang使用编译器rt运行时库。