How to use ubsan for llvm .bc file

42 views Asked by At

Suppose I have a file called put.bc. It doesn't have strings "asan_report" and "ubsan_handles" in it. If I use command clang -fsanitize=address -emit-llvm -o put-asan.bc -c put.bc directly, "asan_report" will not appear in put-asan.bc. So,I write a pass1.cpp:

for (Function &F : M)
    {
        F.addFnAttr(Attribute::SanitizeAddress);
    }

compile it to pass1.so. I use command clang -Xclang -load -Xclang pass1.so -emit-llvm -o put-tem.bc -c put.bc. And the comand clang -fsanitize=address -emit-llvm -o put-asan.bc -c put-tem.bc. So, put-asan.bc has strings "asan_report" or something else. This means that asan instrumentation was successfully used on it. I don't know how to use ubsan to instrument put.bc. Because there's no F.addFnAttr(Attribute::SanitizeUndefined); like asan.

Is there a way to get the put-ubsan.bc from put.bc? What should I do?

Im using llvm 12.0.1.

1

There are 1 answers

0
Nick Lewycky On

Unlike ASan TSan and MSan which are LLVM passes that can run over any LLVM IR, UBSan is a feature of clang which changes the LLVM IR that is produced from the original C++ source code. This is an essential part of how UBSan works as UBSan detects things that are undefined behaviour in terms of the C++ language standard, even when the equivalent LLVM IR has well defined behaviour.