Search code examples
qtvisual-c++llvm-clangaddress-sanitizerclang-cl

How to build clang compiler-rt on Windows linked against dynamic Visual C++ runtimes?


I want to use clang-cl with address sanitizers on Windows. When trying with the prebuilt llvm/clang packages from the official installers, I get linker errors because my application needs linking to the dynamic CRT (/MD) instead of the static CRT (/MT, the packages in the llvm/clang installers have compiler-rt built with this).

I want to use this with Qt, because I did not manage to build Qt itself with /MT .

According to these slides from a google engineer, building compiler-rt/asan with /MT is possible.

What do I have to change compared to these instructions when building llvm/clang in order to build compiler-rt with /MT ?


Solution

  • It turns out that my linker errors had another reason.

    To find the required libraries, build a small hello-world app with the following command, inspect the resulting linker command and link to the required libraries explicitly:

    clang-cl -v -fsanitize=address /MD test.cpp
    

    PR35343 (currently unresolved) is about supporting automatic linking of sanitizer libs in lld-link, like it is done on other platforms.